From 12c0798127e8d7478385d0a3eabcce25b23bf0da Mon Sep 17 00:00:00 2001 From: Zoltan Fridrich Date: Tue, 12 Mar 2024 16:37:01 +0100 Subject: [PATCH] Use monotonic clock for sequence numbering Signed-off-by: Zoltan Fridrich --- lib/kcapi-kernel-if.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/kcapi-kernel-if.c b/lib/kcapi-kernel-if.c index 835e45a..a534da0 100644 --- a/lib/kcapi-kernel-if.c +++ b/lib/kcapi-kernel-if.c @@ -663,6 +663,7 @@ static int __kcapi_common_getinfo(struct kcapi_handle *handle, int drivername) { struct kcapi_handle_tfm *tfm = handle->tfm; + struct timespec tp; int ret = -EFAULT; /* NETLINK_CRYPTO specific */ @@ -691,7 +692,13 @@ static int __kcapi_common_getinfo(struct kcapi_handle *handle, req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.cru)); req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_type = CRYPTO_MSG_GETALG; - req.n.nlmsg_seq = (__u32)time(NULL); + + if (clock_gettime(CLOCK_MONOTONIC, &tp) < 0) { + kcapi_dolog(KCAPI_LOG_ERR, + "Netlink error: cannot retrieve monotonic time"); + return -errno; + } + req.n.nlmsg_seq = (__u32)tp.tv_sec; if (drivername) strncpy(req.cru.cru_driver_name, ciphername,