From nobody Wed Feb 14 04:05:35 2024
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 4TZPk75fMCz59rKJ;
	Wed, 14 Feb 2024 04:05:35 +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 "R3" (verified OK))
	by mx1.freebsd.org (Postfix) with ESMTPS id 4TZPk74Zy8z49qY;
	Wed, 14 Feb 2024 04:05:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1707883535;
	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=PNR0YV7igwlLIY+M2nLQGMrK4BDmNDCu7jLNJ6DCBjU=;
	b=nqeb+IBSjxJCqH1nkpa/6Z4w5yVngxWSaVhk+jML5BV1urwX8XFzv1x6Bpmcra7vr8ehUe
	G5ZaaC/mFoEABWUlJP0n+kHYT/Nsx3Yy8wIe4xR38xTWQy9l+Q1fPio291mc6XyjU8NS/n
	Xc67FyXNCxAS6jcThZslq8CqfyTWw7ARznEiPDEbDujyr3ijr4bALvc5R537WYMDvjUxmu
	yMTVA2mcrxtsIxVVbxqmzkk59a3curMQINgOwdFwVr7hwArVWbcp60Q+idAZq8fQ/NrFfR
	GJhsvXVV6hWJquUrQGxDmz+PtVyjNoTp6RwoZj29z0bqedhEkSBwZOmwMkBjAA==
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707883535; a=rsa-sha256; cv=none;
	b=pshwdaYSnknGm8CknJ9XkDGTRLvnjgkRs2eQUyJxWHEyh+Cz5A/pF75dwOXLLfUpKoPNAq
	KRAEPYvsVU0bnJN/09WANq/7cbNoOI1dLkdIcTnW8Dtnfcq13szSe5uUuM5o62PWqZi8wW
	KRle/xsFp569QcorPSHvHAJ+YfGhOs+NYGrMEY+tQRfCks83kTmtYU2VZ3Ts+GcMAMJ8YQ
	XtK+SGV3/eDows3A3OK+XDd0kxM8eEU38yfxvICnhnVLt0DfdfAOPynwaz55YlOA2Z6G9V
	yvhaMD44aVKmPl0laQnVoujR6Q2WJ2YBnLbrpUYgFt9J4N+eSQqq5ZyK76xHUg==
ARC-Authentication-Results: i=1;
	mx1.freebsd.org;
	none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
	s=dkim; t=1707883535;
	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=PNR0YV7igwlLIY+M2nLQGMrK4BDmNDCu7jLNJ6DCBjU=;
	b=B0GgOO0+zxn1qQFR5lLRf/kI3GSi/H1Rckq60PwK0Ja+NZgXaMkOMMmVA4fm/0sX+yBr9p
	Vj/U2r3bVGb82458iB2pUX8KSf4gBeRJjEFxq+OW2/2LQUdMbPOfCZ5ww0B1+gKF2Fj+aM
	dw7FmnPBVWDNFTiADIgBbMr1aoYTCGeEtX4hEQGotIo76tTJcRee5n2of3djyWpv8P0zKC
	2AV4/rZ5SyebgSt2e4eikMcC4MljhZUMhEvzGuPseKeHcVkDUCkcfJmfXW1BhnH2kDhY6t
	ZfRkjBcrgoHVGUqjlwBklElWawT2JIKFBJ+c/7IBHU2DBtS3zYwWDUituyVG6w==
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 4TZPk73g1Jzk1w;
	Wed, 14 Feb 2024 04:05:35 +0000 (UTC)
	(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
	by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41E45ZPO082422;
	Wed, 14 Feb 2024 04:05:35 GMT
	(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
	by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41E45Z2c082419;
	Wed, 14 Feb 2024 04:05:35 GMT
	(envelope-from git)
Date: Wed, 14 Feb 2024 04:05:35 GMT
Message-Id: <202402140405.41E45Z2c082419@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
        dev-commits-src-branches@FreeBSD.org
From: Konstantin Belousov <kib@FreeBSD.org>
Subject: git: 72616ae38093 - stable/13 - ELF note parser: provide
  more info on failure
List-Id: Commit messages for all branches of the src repository <dev-commits-src-all.freebsd.org>
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all
List-Help: <mailto:dev-commits-src-all+help@freebsd.org>
List-Post: <mailto:dev-commits-src-all@freebsd.org>
List-Subscribe: <mailto:dev-commits-src-all+subscribe@freebsd.org>
List-Unsubscribe: <mailto:dev-commits-src-all+unsubscribe@freebsd.org>
Sender: owner-dev-commits-src-all@freebsd.org
X-BeenThere: dev-commits-src-all@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kib
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/13
X-Git-Reftype: branch
X-Git-Commit: 72616ae38093f627821e119c7470537aaf254a10
Auto-Submitted: auto-generated

The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=72616ae38093f627821e119c7470537aaf254a10

commit 72616ae38093f627821e119c7470537aaf254a10
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-02-10 01:36:58 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-02-14 03:54:00 +0000

    ELF note parser: provide more info on failure
    
    (cherry picked from commit 29d4f8bfc642f0196c27eb469ea7eb326ff529d1)
---
 sys/kern/imgact_elf.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 0a6ef1242d77..cae1889bc4c5 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -2703,6 +2703,7 @@ __elfN(note_procstat_auxv)(void *arg, struct sbuf *sb, size_t *sizep)
 	}
 }
 
+#define	MAX_NOTES_LOOP	4096
 static boolean_t
 __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote,
     const char *note_vendor, const Elf_Phdr *pnote,
@@ -2742,9 +2743,15 @@ __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote,
 		    pnote->p_offset + pnote->p_filesz);
 		buf = NULL;
 	}
-	for (i = 0; i < 100 && note >= note0 && note < note_end; i++) {
-		if (!aligned(note, Elf32_Addr) || (const char *)note_end -
-		    (const char *)note < sizeof(Elf_Note)) {
+	for (i = 0; i < MAX_NOTES_LOOP && note >= note0 && note < note_end;
+	    i++) {
+		if (!aligned(note, Elf32_Addr)) {
+			uprintf("Unaligned ELF note\n");
+			goto retf;
+		}
+		if ((const char *)note_end - (const char *)note <
+		    sizeof(Elf_Note)) {
+			uprintf("ELF note to short\n");
 			goto retf;
 		}
 		if (note->n_namesz != checknote->n_namesz ||
@@ -2764,6 +2771,8 @@ nextnote:
 		    roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) +
 		    roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE));
 	}
+	if (i >= MAX_NOTES_LOOP)
+		uprintf("ELF note parser reached %d notes\n", i);
 retf:
 	res = FALSE;
 ret: