Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 081672E5B1D for ; Wed, 1 Oct 2025 11:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759319760; cv=none; b=njfGmDWRFcirV6Gz2o/MMZmUcBspCtZjQ3nFVrchC/4SmXr4815eBsSEuBCQffDCSdUJ4c1Rn3GuKUGbwQzA09GCkN7jS9onNQDlzqsd+vA+M0rm4CwAQVPnOo9g/8jAMnsXwQvQ00ulpfn/7833Kkb3MSAHVk3AwKYqWyM0KWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759319760; c=relaxed/simple; bh=Zt94GpwBJhod59es99bo824Abmk/MFAJObdw6IHpHrg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qxz/GX9BzT1gdSpXs7boZLF8yFNhLTxHDER5NTP+MeBK4ZHbIuwt6HLZp8p1Xqa2sluNt04/Ylt91iJAdCqQnHYuAitkUCBstOb+ae2s5EcHZexzLk+YPYVBBFA/ma2Cu2f4G2HHzCpTtuwwYL9n9KXjag37RQJRLWK4b3hVYOc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1QCR2nZh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1QCR2nZh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E3DCC116C6; Wed, 1 Oct 2025 11:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759319759; bh=Zt94GpwBJhod59es99bo824Abmk/MFAJObdw6IHpHrg=; h=From:To:Cc:Subject:Date:Reply-to:From; b=1QCR2nZh0k7TZ5j7fFoEgr3GhQdef/oCZCw85J9tF6qPPOvBK2FwcnPxOChVXMtLB xQ5omdcDVglDqebsiqI1QB8+etXHOGoIN0yNE16N+dqOvY9yZz4T+VdA/EU6Ko7UAH U2axk/nK+dUqG+c7hX+MxSR4aikIUoSHgcB1zuwQ= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50450: libbpf: Use elf_getshdrnum() instead of e_shnum Date: Wed, 1 Oct 2025 13:45:20 +0200 Message-ID: <2025100116-CVE-2022-50450-7ef7@gregkh> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3709; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=6i8QIDXwTYI9/HoAa58KDmDC0CbmQ29LVghbmONf8NA=; b=owGbwMvMwCRo6H6F97bub03G02pJDBl3RXx2zjI+w+LcxcLK+ovl1mzhJYK7lslckBLYoH5AU 8PQYvbxjlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZhIMDfD/LDuUw3vdASWHmlk vu5jxf72lce2+QzzCxm+7RfOt1xxLGg6g1Db1TR1+XsrAQ== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: libbpf: Use elf_getshdrnum() instead of e_shnum This commit replace e_shnum with the elf_getshdrnum() helper to fix two oss-fuzz-reported heap-buffer overflow in __bpf_object__open. Both reports are incorrectly marked as fixed and while still being reproducible in the latest libbpf. # clusterfuzz-testcase-minimized-bpf-object-fuzzer-5747922482888704 libbpf: loading object 'fuzz-object' from buffer libbpf: sec_cnt is 0 libbpf: elf: section(1) .data, size 0, link 538976288, flags 2020202020202020, type=2 libbpf: elf: section(2) .data, size 32, link 538976288, flags 202020202020ff20, type=1 ================================================================= ==13==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000c0 at pc 0x0000005a7b46 bp 0x7ffd12214af0 sp 0x7ffd12214ae8 WRITE of size 4 at 0x6020000000c0 thread T0 SCARINESS: 46 (4-byte-write-heap-buffer-overflow-far-from-bounds) #0 0x5a7b45 in bpf_object__elf_collect /src/libbpf/src/libbpf.c:3414:24 #1 0x5733c0 in bpf_object_open /src/libbpf/src/libbpf.c:7223:16 #2 0x5739fd in bpf_object__open_mem /src/libbpf/src/libbpf.c:7263:20 ... The issue lie in libbpf's direct use of e_shnum field in ELF header as the section header count. Where as libelf implemented an extra logic that, when e_shnum == 0 && e_shoff != 0, will use sh_size member of the initial section header as the real section header count (part of ELF spec to accommodate situation where section header counter is larger than SHN_LORESERVE). The above inconsistency lead to libbpf writing into a zero-entry calloc area. So intead of using e_shnum directly, use the elf_getshdrnum() helper provided by libelf to retrieve the section header counter into sec_cnt. The Linux kernel CVE team has assigned CVE-2022-50450 to this issue. Affected and fixed versions =========================== Issue introduced in 5.16 with commit 25bbbd7a444b1624000389830d46ffdc5b809ee8 and fixed in 6.0.16 with commit 854f8c61422053f71e3cf0c4abf757c8aa5c748d Issue introduced in 5.16 with commit 25bbbd7a444b1624000389830d46ffdc5b809ee8 and fixed in 6.1.2 with commit 622ff59742fe7bf53c06a57332040fa0e08b8242 Issue introduced in 5.16 with commit 25bbbd7a444b1624000389830d46ffdc5b809ee8 and fixed in 6.2 with commit 51deedc9b8680953437dfe359e5268120de10e30 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-50450 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: tools/lib/bpf/libbpf.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/854f8c61422053f71e3cf0c4abf757c8aa5c748d https://git.kernel.org/stable/c/622ff59742fe7bf53c06a57332040fa0e08b8242 https://git.kernel.org/stable/c/51deedc9b8680953437dfe359e5268120de10e30