From nobody Mon Dec 15 18:19:07 2025 X-Original-To: dev-commits-src-all@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 4dVSxm2yplz6L7VN for ; Mon, 15 Dec 2025 18:19:08 +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 4dVSxl1Wxvz4LrR for ; Mon, 15 Dec 2025 18:19:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822747; 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=zhf8cvjV0ZAIS7aEPZGXB/SDecFXzXWSTI2sZ6dLmWY=; b=fC7gA43ow1de/YGZLzfPV8X6wVcnWSka6zq1CouTXE81EYiSbIbt8IQg7+6Fxkr32bdypA FKzQaAb4x1JPiRWrWaBpU65bPbLtFk4AJX1spr6zm6Eetz3eWRfgY5YA8Y1YH7XdQn0RTD puTMbiPLtKTknnmFZ9o9TDr8BeBY4Tr1Bw7wxl114aVyzdFeER20zq7sxHM0A+5KS07YJl hPvlpm6JBT+Mo+cC90PhgKWzkcpaOTztE8dZfzrWez86gsO5GwfmFE7nurlh/q3d9AQvoe OC3JgbaKSi01bOcUuNpR4POQnKK95KK5gYl7JnAXuHDUqu5xE4ERw0dsVzOU+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822747; 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=zhf8cvjV0ZAIS7aEPZGXB/SDecFXzXWSTI2sZ6dLmWY=; b=jqR8QHaYn4CAxIynXLEYIAGaUZEnzQDwFiXgYaEeeJKnqMO1XK2ZbnUW1KxRvTkTyvbHA0 nwxOGmS4u2EVESCgpbx+2Z8Al/NRg9lqahfFMS3b6Ng80l5yzIVbGZ/Pq0ecRS+24hSfpK bjKGjhY+N/aRznFIQy3RJhaB/CGBQbrRJCcX86NU97xvuXSTXh8WOpKl9JCNm8iNwkIGZI J1btheifoqBU7GKoz8RWzQhGJ9blUIj+aCAQ73D+XlTxayAdhcRgOZVZDkMQP/jgRWB/8z 9H9SasyHdR4dCtJJGwJ85uIHJ3apcZ6saRwl+q1OoW5/aJJTlzmJuKNFKemKrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765822747; a=rsa-sha256; cv=none; b=jDuij8wICbLNX2UZ0auD2KjhKb296PVed/0hKkszotLPwFbEhnUs2Zgvhf7LitLpzoHsSU 5PdUroEkxostymlArgdiQZavmgFxy8Zbjtl+jLdTq4notJVCWuSnk5nJ3Y/expA2bL4anX t/hsFm7ePgEr4/hYe0Sgn/7OGsJQvKSOhfUOJQ2sS1//3Ju35ByMkKtu7T8QAVf/71wP4V BCrk00kOTeIe39fdvLjvEKliVkzDxwvNK1kY7RPqj7rezFJut6515GKrybhpMbhk5bRtmT m01rUbokMx/Tw6Wxdr0lUXJLrLL8USvg0ADAw241Nfhg6QuqDH0avzM3aVKSDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dVSxl0qxfzVhj for ; Mon, 15 Dec 2025 18:19:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 261aa by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 18:19:07 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 3e264f4d3586 - stable/13 - imgact_elf: Fix off-by-one in note size check List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3e264f4d35863f9888f3779c64bf027e52fc9bc0 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 18:19:07 +0000 Message-Id: <6940511b.261aa.183285ee@gitrepo.freebsd.org> The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=3e264f4d35863f9888f3779c64bf027e52fc9bc0 commit 3e264f4d35863f9888f3779c64bf027e52fc9bc0 Author: Jessica Clarke AuthorDate: 2025-12-08 13:01:57 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 17:56:37 +0000 imgact_elf: Fix off-by-one in note size check Prior to c86af2cc4cd1 ("imgact_elf: Check note body sizes"), this was note_name + n_namesz >= note_end, which checks that there is at least one byte after the unpadded name (which could be either padding or data), and given our notes always have data with them this was fine. However, once we started checking the padded name (note that "FreeBSD\0" is already a multiple of 4 bytes, so has no padding) and data, this turned into checking that there is at least one byte after the unpadded data, and since our ELF notes already have a multiple of 4 bytes for their data and therefore have no padding, this means that we are now checking that there is at least one byte after the ELF note, which is not going to be the case for the last ELF note. Instead, switch this to a strict greater than, as should be used when comparing one-past-the-end pointers, which both sides of the inequality are. For executables, this was generally not a problem in reality, since the last of our ELF notes is NT_FREEBSD_NOINIT_TAG, which isn't read by the kernel. However, ld-elf.so.1 (and libcompat variants), like shared libraries, only has NT_FREEBSD_ABI_TAG, which meant the kernel did not see this ELF note when directly executing it (e.g. as done by ldd), and on RISC-V this is the only branding present, so doing so would fail with ENOEXEC. This does also mean on non-RISC-V direct exec ld-elf.so.1 runs with the wrong p_osrel, but given it sets kern.proc.osrel.PID to the executable's NT_FREEBSD_ABI_TAG that it loads, this probably doesn't matter in practice. PR: 291446 Reported by: bdragon Tested by: bdragon Fixes: c86af2cc4cd1 ("imgact_elf: Check note body sizes") MFC after: 3 days (cherry picked from commit 5d58198ccc2b562098ee5fc4898013622b32b065) --- sys/kern/imgact_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index cda86cf48001..eaaebfbb0e08 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2759,7 +2759,7 @@ __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, goto nextnote; note_name = (const char *)(note + 1); if (note_name + roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + - note->n_descsz >= (const char *)note_end || + note->n_descsz > (const char *)note_end || strncmp(note_vendor, note_name, checknote->n_namesz) != 0) goto nextnote;