From nobody Wed Feb 14 03:53:48 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 4TZPSX703Fz59qSJ; Wed, 14 Feb 2024 03:53:48 +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 4TZPSX4HJrz4695; Wed, 14 Feb 2024 03:53:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707882828; 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=dPF5lyQ1XSvUfOfWTLvYBYXscHhpyKAo+wm/VwHK5EA=; b=VW6JZpHDE2mM5JUTYP1vn4YGSUq4V+lPlLZVthj5CuMfYjmDXzX4ztbVuXLkbC6IjKjky5 BGAQvE9xCTNZWHcZHfsZg8EzwiSLt5BhaENtaKW7BLx4I7G5eT5E6570KYiUzJeRpwQy89 A7h0nbrxGkw8CMh8q9fRNshW5NGtvKSsOAXAR4BcjjRBxroclxy51SA7nMcUXIgpRX6LhX w8vsrr7NXd2I8HeHZgXz8JbXJKe7BlZPOCNxUbfoovtCPTDZNaSNBijZUDMo5Wgd+AB9lF iLQwBRqg02WmM5gNxn0owDK3miX5uhujFGKXPmnI3CABFo8E7oOz/fyPTn3fsQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707882828; a=rsa-sha256; cv=none; b=ymz+UYF6fzmwrD/kUYBl0HRfrB/OzwBVUz8lkooOnWHtpznWcT6w1PQXftAmlgv2nhusNy 3DfriTK//bK2k2Vo5Urw2xMMnCSn5FAchjb36KQIt3hB+dZqcEsJ+uqhkPRsAJX34GnwUy UQVjsaLa77WO+6C7bO6aeNfTe8LE2fwaeXBrvosHFCKT4M8Fr9PEsgr8CKcQ3CoHIUrOMg X5pXWlpqaZ9Ed8cXqURrSssAAjHjzS7laek7ebhjyRtddi1xdOqT+XdniCFe/9QbYF8eL3 hNXWkh1tcpVPhruF2kzAb/zo54g8M6zj8g+/+Q6CsoPobzo2YQNwQ1qyx+4bOw== 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=1707882828; 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=dPF5lyQ1XSvUfOfWTLvYBYXscHhpyKAo+wm/VwHK5EA=; b=PyZ/s/zMJegu48TSSTWEKEyAxBk4ZxGLsKtePKvHDNu9aqtQ+ryYrJyfgMqVkbyC5Afvva LQ0c8v1XdyB4KtOOvrVchBzO4S4scom2bcO+ZeTAQyup5pepHDNB9JIbbR+sM1Nl/7Z/8Y EkxA10D/ZZv0wr7hKpHRtQW3w6pbNuB+hnpc5HER8Z/cujBZ81/vse55cXAu1RjlK7uB4j Xb/64A8cG6WgPdyDYNECOv58YZM2nQuytRCGFCHfgRqePPHc4JC7Oj1WlRumzWIczDVch2 I2bK+Zt6Ywr1ua5dSWKWmhy87CI3Iwfm22y9QudqeNV097+cla3oTyaEBG6vuA== 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 4TZPSX3KTCzjVZ; Wed, 14 Feb 2024 03:53:48 +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 41E3rmuA064595; Wed, 14 Feb 2024 03:53:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41E3rmhb064592; Wed, 14 Feb 2024 03:53:48 GMT (envelope-from git) Date: Wed, 14 Feb 2024 03:53:48 GMT Message-Id: <202402140353.41E3rmhb064592@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: bcd7b196c83b - stable/14 - ELF note parser: provide more info on failure 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: 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/14 X-Git-Reftype: branch X-Git-Commit: bcd7b196c83b9a1ed5f2e2215c15542088d88aef Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=bcd7b196c83b9a1ed5f2e2215c15542088d88aef commit bcd7b196c83b9a1ed5f2e2215c15542088d88aef Author: Konstantin Belousov AuthorDate: 2024-02-10 01:36:58 +0000 Commit: Konstantin Belousov CommitDate: 2024-02-14 03:42:40 +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 f22f9addb45c..85f0602fe584 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2704,6 +2704,7 @@ __elfN(note_procstat_auxv)(void *arg, struct sbuf *sb, size_t *sizep) } } +#define MAX_NOTES_LOOP 4096 static bool __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, const char *note_vendor, const Elf_Phdr *pnote, @@ -2743,9 +2744,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 || @@ -2765,6 +2772,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: