From: Mark Wielaard Date: Fri, 11 Jul 2025 17:58:53 +0000 (+0200) Subject: linux mseal PRE wrapper should First check for overflow X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;p=thirdparty%2Fvalgrind.git linux mseal PRE wrapper should First check for overflow 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). --- diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 51a47a16f..306c3a2f8 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -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); }