From d7743540064c58d3dcb850804fb29f742757d853 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 11 Jul 2025 19:58:53 +0200 Subject: [PATCH] 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). --- coregrind/m_syswrap/syswrap-linux.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); } -- 2.39.5