From nobody Sun Feb 11 03:39:20 2024 X-Original-To: dev-commits-src-main@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 4TXYHD55m7z59Hf6; Sun, 11 Feb 2024 03:39:20 +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 4TXYHD3chFz4LcP; Sun, 11 Feb 2024 03:39:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707622760; 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=erm0njCYmV616crsOYGyT6PfSl2gAf5atBpLcAR8Q8g=; b=qDYK/U4WvTN2YIUAp78ZGTLvrA9u4ROqR5pDsR8C4iW38fP6KESXkkXgnrBe0YOc8LN85N 3ZpBiAT+DShpc3MSKZXsximzwOo2kGBccCMOSxP6NbEtfmExJjrnVv0wSRH9Uq6Gnp5Uv8 PUF9VSrpw4UDUK/l5QM0pWicW9wKGIEKlFIEI9ewn7VT3ZCSE4voN6WGV+wRG9XyLzL7DL LZDRwgoEIULxL6P+ooVt5QwJgIa0ZRInFJObR+XEDDBJ4jycd+N9Ker+ip4JmN/b6Bwuw4 WPyveGPMROM9bHmxpSquDnxmpK9VoBtW6wA6ZBNTM5eVdMgfzxmucu9VQJgs0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707622760; a=rsa-sha256; cv=none; b=CMrwlWEctiG77u1rNNcXWcAekABcVmxvS2qRP65DKnlhdXGTgCVBNPIuuw7kRLM/Kl2tUp yoIoShep4GsFcQ8R6kMjoQ3mln/NtMhAcIOOwSuBZtJ9raThyejl1IF8R1mx3vaYTcVE+J YriM5M1HZXKNqQDvHEfMyczNEQKLKISGvRDGQ1BPpVJDVaDlU1TBrJNG+NpK28+6My0nDi /lot/bDhkvJBV03sxRUtqlvWERs0nBXxsle3w295ervwNNIa2EpTnhhF759QTU+pZzYMus Z0e8cAWeQEQRJnDqvLCcmetql87L+fPSE3IvSgYgf05w86F9Vew48by6y9DeDw== 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=1707622760; 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=erm0njCYmV616crsOYGyT6PfSl2gAf5atBpLcAR8Q8g=; b=JULHKdoacfzxdznwswbrzuY8BHyjtSBQQI2gbrot6WKrGxGrqmtPnKY8PZYHrtABcmeJax 6+R+5zl7q9izsVyoApqlKicDbYpN1fVBZVTeVpoiwdhqul5Jf8qGCXpEuP3o/nWJW3/evV /Bp9RaiHE4qtEKFY68HrN1oy1KZaDKBTrxfW9P0BgeDYmAB1k9TLfzy8rdehtP5ijNVIGa kZDAOwreJIQ6/Elao9+8Hbd39pxVNJmg6+ohTaFypH2CM9EqqwLZ09XN7RtspOQVOa10ok C+vngW2/8EU8Ix73UdrDIOX6VESPS+KQdkN2SOLe1DPDcz847SbDb9ojeLK6UA== 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 4TXYHD2gPszkLx; Sun, 11 Feb 2024 03:39:20 +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 41B3dKup060176; Sun, 11 Feb 2024 03:39:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41B3dKCj060173; Sun, 11 Feb 2024 03:39:20 GMT (envelope-from git) Date: Sun, 11 Feb 2024 03:39:20 GMT Message-Id: <202402110339.41B3dKCj060173@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 29d4f8bfc642 - main - ELF note parser: provide more info on failure List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 29d4f8bfc642f0196c27eb469ea7eb326ff529d1 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=29d4f8bfc642f0196c27eb469ea7eb326ff529d1 commit 29d4f8bfc642f0196c27eb469ea7eb326ff529d1 Author: Konstantin Belousov AuthorDate: 2024-02-10 01:36:58 +0000 Commit: Konstantin Belousov CommitDate: 2024-02-11 03:37:12 +0000 ELF note parser: provide more info on failure Print reasons when parser declined to parse notes, due to mis-alignment, invalid length, or too many notes (the later typically means that there is a loop). Also increase the loop limit to 4096, which gives enough iterations for notes to fill whole notes' page. Sponsored by: The FreeBSD Foundation MFC after: 3 days --- 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 49dcae050d76..8f85a4f5e18a 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2709,6 +2709,7 @@ __elfN(note_procstat_auxv)(void *arg, struct sbuf *sb, size_t *sizep) } } +#define MAX_NOTES_LOOP 4096 bool __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, const char *note_vendor, const Elf_Phdr *pnote, @@ -2748,9 +2749,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 || @@ -2770,6 +2777,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: