]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
linux mseal PRE wrapper should First check for overflow
authorMark Wielaard <mark@klomp.org>
Fri, 11 Jul 2025 17:58:53 +0000 (19:58 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 11 Jul 2025 18:00:34 +0000 (20:00 +0200)
According to https://docs.kernel.org/next/userspace-api/mseal.html
mseal returns -EINVAL when Address range (addr + len) overflow. The
LTP test mseal02 checks this. So do this check first before checking
for valid_client_addr (which returns -ENOMEM).

coregrind/m_syswrap/syswrap-linux.c

index 51a47a16fbc5a3667ff9a436e81895f0ea6b0d06..306c3a2f8b41f7d90c3d87f56f88d4a0cd1e8731 100644 (file)
@@ -4315,7 +4315,10 @@ PRE(sys_mseal)
     /* int mseal(void *addr, size_t len, unsigned long flags) */
     PRINT("sys_mseal ( %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, )", ARG1, ARG2, ARG3);
     PRE_REG_READ3(int, "mseal", void *, addr,  vki_size_t, len, int, flags);
-    if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "mseal"))
+    /* First check for overflow which produces EINVAL.  */
+    if ((Addr)ARG1 > ((SizeT)(-1) - (SizeT)ARG2)) {
+       SET_STATUS_Failure(VKI_EINVAL);
+    } else if (!ML_(valid_client_addr)(ARG1, ARG2, tid, "mseal"))
        SET_STATUS_Failure(VKI_ENOMEM);
 }