From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795023059; b=qZmRza/qORoUuqphf52Utjizwi4hV5PdGS2Wtf0egTwGaWtifX89+ICMA62u3/pwnot4 +ARST5cglYH6AP+JvXWeCASSfO48Qu9xWpVg33OzHcqpQygGcHiRvY4jU8Gb2MGv/1Z0T pn2ZODmS9KQ530/dBP+ZCz0tf+Ol0lqa7vBFjTmdlIaxOZsN9/fUTZK+i1fI/eiuc1nqD s41PMSrJNgeWiYz1wt4aInbKyC68hoQm864LVd0XAVeWMSnWuiswvx201z+GjAWWH6W9R JeP6ZdoUekmXJLHmUDON77axLIHt4mJS5yun4Ggpgxho01CwJRCtlLEEG5YMnBqQq6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795023059; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=GC4rZANE76B15/GQlbq0zBvNS6AyuwuBTsEdPjGzKGk=; b=KqJdXWOL6CImJnYg5mSuhngnr1HgyH7bW1CYhZZwviHc/qqchjFS2NWSQw3BnLh39Vqk tIu3E4SD1Ki4B6sQe9PaKL7qXIzZ22CWxPonQyOVbXQ2E7fGsUQcn022/5AjFpfqIG9bw HWqrcPcpwPBrFsljSez75v4A4cHSGYVYcovN9yhrEYkrlpOX78xQAcTowjwxzhl9sApEi BFy8MhtgSwnWCsRgsjACq4tq/VzT92UY1uFtPg5WfucForEkRa6DL/mX/S6lIZO5eWWKs P3QSRgZjuCRd1Nm/ex6VuMXc669aSVFiVh9loQDKm/3DXgLRlVGdCliKOn8xNnk/uZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ebqTAtqR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66355606A32A; Wed, 18 Nov 2026 17:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ebqTAtqR Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBF8B1F000C5; Wed, 18 Nov 2026 17:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795023059; bh=GC4rZANE76B15/GQlbq0zBvNS6AyuwuBTsEdPjGzKGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ebqTAtqRo5lCmYPCrpmXpF3BTe9b3eWSA0+opiWwF5h6fnKGWpCqnCM1JBh2wgiPD DC40eLKLhmQzHNTLn+N1ewEvoJU1SYIrrC56l4ZoTgFwOKRQhh8Sd6v4YX3S7Om+mz EE8NBM/hnk5IW4gAx7oyUn9vV1lX51KbFFolcc6s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fabrice Derepas , Herbert Xu , Sasha Levin Subject: [PATCH 6.18 0232/2151] crypto: asymmetric_keys - fix OOB read in pefile_parse_binary Date: Wed, 18 Nov 2026 15:32:47 +0100 Message-ID: <20261118150130.229820360@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fabrice Derepas [ Upstream commit 37d550172c2d3cdb3a5ace3e6cb0625967d86349 ] pefile_parse_binary() reads the size field of the certificate table's data-directory entry, which sits at fixed index 4 of the PE optional header's data directory: ctx->certs_size = ddir->certs.size; but nothing ensures index 4 is present. n_data_dirents (the untrusted NumberOfRvaAndSizes) is only upper-bounded against header_size and may be 0, and header_size need only satisfy cursor < header_size < datalen. A crafted PE with n_data_dirents = 0 and a tiny header_size therefore causes the ddir->certs.size read to land past the end of the image (CWE-125). The chkaddr() that bounds the certificate blob runs only after this read. verify_pefile_signature() is reached from kexec_file_load() (the lockdown/secure-boot enforced PE-image signature path), and the image is parsed before its signature is checked. The trigger needs CAP_SYS_BOOT and the access is out-of-bounds read only (no write). Require the certificate table's data-directory entry (index 4) to be present; the existing upper-bound check then keeps ddir->certs within [cursor, header_size). Fixes: 26d1164be37f ("pefile: Parse a PE binary to find a key and a signature contained therein") Assisted-by: copilot-cli:claude-opus-4-6 frama-c Signed-off-by: Fabrice Derepas Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- crypto/asymmetric_keys/verify_pefile.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/asymmetric_keys/verify_pefile.c b/crypto/asymmetric_keys/verify_pefile.c index cec99db14129a..1efd5c0d0e9ce 100644 --- a/crypto/asymmetric_keys/verify_pefile.c +++ b/crypto/asymmetric_keys/verify_pefile.c @@ -87,6 +87,11 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen, if (ctx->n_data_dirents > (ctx->header_size - cursor) / sizeof(*dde)) return -ELIBBAD; + /* the certificate table entry must be present in the data directory */ + if (ctx->n_data_dirents <= + offsetof(struct data_directory, certs) / sizeof(*dde)) + return -ELIBBAD; + ddir = pebuf + cursor; cursor += sizeof(*dde) * ctx->n_data_dirents; -- 2.53.0