From nobody Sat Nov 15 15:02:50 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4d7y171TPqz6GRXc; Sat, 15 Nov 2025 15:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d7y170mvtz3G9q; Sat, 15 Nov 2025 15:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763218971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Oq2R5D8njH1fkBey7DW/DjHho5uMLxxj0hlG2XJRXIk=; b=GF3mhTPkKzxX+Nwy5NFCPl6RlMr6rQmGKT3qAGs9r7Shdeh0ikuhfdzuPUlhYA9NsX+c/i U42lcD1Pnc3wtDoRpzH7Wcjv7V4AJaCVqrfMeMbug/UiZ9Eeruk5u7QDk63okMDJq9xgW+ WVCjTvPmumWAkvN9VdSoNhrcjEl5CZrZagtHs6gIxpc0Fecb2NIey89il95WG3CFWTZKMU mWyDVRAuO4BLZK0jUVnlUVAQzxAuPtAHkd8nRwTO440oBBlMWz7G/jADtoAGr7w53UpaCt bFBneCb60ONTUskVF6YtaRGwwzOc2uRMAbyUu+byJw+Y2s9cMw1Cs0XLw9W4Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763218971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Oq2R5D8njH1fkBey7DW/DjHho5uMLxxj0hlG2XJRXIk=; b=CSYPcFLbcyNz63MCgYnk8CP5JWxBxc4C4iA27NBwIKfImfuB79ckf5HKgpiqIq3diPNa14 A0Dugy523AGYUiUvfebnjXJnYpElmc4cZsyCcRyz+oXcI504w39AXS3gbBQg+OMDaljNkY Qiowzj87ixG+jp5x488ZWWB/8CsiAKHlUIi+nQnUiIR4BEqZMhUbRalCTGoMA/W99F9O1k SKpjzHSov6ViO5UrCPsqqpCDdZH661FPozAva4aekY6+a3RyXjMY0NXzpy9mgrcF0jNvgf 6A0+bIRsBrtVXCfLHoPMoBe46iESbDc+JkgNL77Q6uxR2pyYJFUj7CtXti/iDQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763218971; a=rsa-sha256; cv=none; b=sgDCKuljpmYvOPF9jEIRk2WhYzbKkhBA0NL9q78fo1czqvci09kZNI53NzqA5rrQt0tQ+q 06/N9fBX6tPW+aWzJfV+bqBaiYu/k7ow6fpq3dkGlx1vCfswQYz9e34UbwBJU0daOK9g9p u/MDmDtJBMzhmOrGczMdG9W76E/kVW78kbf7QHrQxB7PSZIGC0ORGkxgpueu/EYl4TkK8K wG9La5Wcz9PGFgFzLoyIQYlsq6+YyQA8Nh6y+gqFe9zIj2FRzimQfNEdNKRz8jm6AE0nTR W6dvGfAfcwWpT8CCGLkTwe59rCZSiM/kIIbf0bZaO4JkFGBrtoiaZZciM0eXSA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4d7y170FW9zxrD; Sat, 15 Nov 2025 15:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5AFF2ocO020681; Sat, 15 Nov 2025 15:02:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AFF2ofL020678; Sat, 15 Nov 2025 15:02:50 GMT (envelope-from git) Date: Sat, 15 Nov 2025 15:02:50 GMT Message-Id: <202511151502.5AFF2ofL020678@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 190e6d67953c - stable/15 - setcred(): Fix 32-bit compatibility copy-in List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 190e6d67953c3fb2064823d27998c54defff1925 Auto-Submitted: auto-generated The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=190e6d67953c3fb2064823d27998c54defff1925 commit 190e6d67953c3fb2064823d27998c54defff1925 Author: Olivier Certner AuthorDate: 2025-11-14 20:20:12 +0000 Commit: Olivier Certner CommitDate: 2025-11-15 15:02:12 +0000 setcred(): Fix 32-bit compatibility copy-in For 32-bit processes on 64-bit architectures, a difference of 'int' pointers was wrongly used as a number of bytes to copy in a memcpy() used to internally construct a 64-bit 'struct setcred' from the 32-bit variant, leading to copying only part of the 32-bit structure, and thus to requesting credentials with garbage IDs except for the real and effective user IDs. This bug was spotted by jhb@, who produced a slightly more invasive fix in D53757 (a switch to using CP() on all fields). In the interest of minimizing the diff for possible inclusion in 15.0, the commit here just limits itself to fixing the number of bytes to copy. Tested successfully on a VM with 32-bit mdo(1) (and in passing also tested that the same executable on a kernel without this change exhibits the bug in practice, in the form of setcred() failing with EINVAL). Reported by: jhb Reviewed by: jhb Fixes: ddb3eb4efe55 ("New setcred() system call and associated MAC hooks") MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53767 (cherry picked from commit 4872b48b175cc637ee38f645d68b8207d9335474) For the insta-MFC to stable/15: Approved by: re (cperciva) --- sys/kern/kern_prot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 3c145851b683..0b7dc2169335 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -603,8 +603,8 @@ user_setcred(struct thread *td, const u_int flags, if (error != 0) return (error); /* These fields have exactly the same sizes and positions. */ - memcpy(&wcred, &wcred32, &wcred32.setcred32_copy_end - - &wcred32.setcred32_copy_start); + memcpy(&wcred, &wcred32, __rangeof(struct setcred32, + setcred32_copy_start, setcred32_copy_end)); /* Remaining fields are pointers and need PTRIN*(). */ PTRIN_CP(wcred32, wcred, sc_supp_groups); PTRIN_CP(wcred32, wcred, sc_label);