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=1796384191; b=KuATLiK8mBS21n622FEUwg1xTFV1gJZ4tFzA07dEQ31tvYNVxxQ2y5NqqgDJ/e8vulTI b2sGt6Qa5i0TdJaOzyH8Qfsj3cx7tvofaDUcsDPcvuVYfuvmEMTKQKVO9CEvSogjD2yQL nF6AN6kVs1D+3FrpUaai17lpv9x09eAu7Z/tpH/CWtioXokaETl5BcxcOJ/PtGZL+dnI8 jsFV/ut1MuuZ3UahxEurBWVcap4sofK/xUEJfbUNPZ0sPdsm1m6cxYXHshcKaA9mxAUzH dHAxk2eIlXdaER6x3xyZa/QsJej23xg5H7GikR+T+Gora8DZAaAEucZ+VT13DtYxCWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384191; 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=+jZVkBX7UZDTtoGmrvQkrQ87LoB5N9Z1J7bWhuae/sY=; b=PGZvZxc1YsPSJG6K79hU1tx1LpUxVIM4KFn2Ohk2d+gdqSjmi3EJLtTVL608c/Bh8pO7 x9HGhlo7/T4tNA/szse2/taX6vQ1Bum1rcFN3v8s61nko3a9krec/BW6h/jTxrkfRbUzl 7wL2hvzKoGY8Dct8h1RyptILZ+E7WPSwijmpqQKYfjSMgaM9ytB1kKe2AWISOk34VPjhF KiaNmDEQxZTeoa4/PCvUsbTGCGYIv5o1s9P+sqvMOj6KOanim449TeL0k+VoYiwqyGAhl eD/WpEjAb2stq//US8EnQ8ftW7Lya1vmfNlHiwFQYN461UiRvMn3B38o8RXXd+fxU/g== 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=ykXe3IM4; 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 1654F606A322; Fri, 4 Dec 2026 11:36:31 +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=ykXe3IM4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81DA61F000C2; Fri, 4 Dec 2026 11:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384190; bh=+jZVkBX7UZDTtoGmrvQkrQ87LoB5N9Z1J7bWhuae/sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ykXe3IM4KlknpmOH77gv+r/xqOcc4vhLJNHbkbu2mRywHBTWA9jqFY6miqheu4Z53 +oiMYF76nPRAILHFJcHUmAdtGxzN0wNXo+EaCVEuV8HtSdKrzyKfiAQJWOPqrfeAfU Vo8JjJt9peqKciOtzUmEt01GdyYQNcvrrxcCDC1k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Henry Martin , Jarkko Sakkinen , Guicai Ma Subject: [PATCH 6.12 534/555] KEYS: Fix crash on big_key read Date: Fri, 4 Dec 2026 19:09:37 +0900 Message-ID: <20261204100629.010890788@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Henry Martin commit 1bcff832c48d83c5132662bec83bda37f566d8a2 upstream. big_key_update() reserves quota with the raw payload length and then destroys the old payload before instantiating the new one. For a payload of N < 16 bytes that reserve releases 16-N bytes, so the reserve of 16 done by generic_key_instantiate() charges them again and can fail with -EDQUOT once the payload is already destroyed. big_key_destroy() keeps payload->length but clears path and data, so the key stays positive with a stale length that KEYCTL_READ and KEYCTL_REVOKE then follow: kernel BUG at fs/open.c:1145! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:dentry_open+0x7b/0x90 big_key_read+0x141/0x280 Instantiate the new payload first and destroy the old one only on success; a positive key's reservation is already 16 bytes, so it cannot fail. This issue was discovered by Tencent CodeBuddy Security. Cc: stable@vger.kernel.org Fixes: b6f61c314649 ("keys: Implement update for the big_key type") Signed-off-by: Henry Martin Reviewed-by: Jarkko Sakkinen Reviewed-by: Guicai Ma Tested-by: Guicai Ma Link: https://lore.kernel.org/r/20261124025759.39344-1-bsdhenrymartin@gmail.com Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- security/keys/big_key.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- a/security/keys/big_key.c +++ b/security/keys/big_key.c @@ -193,16 +193,24 @@ void big_key_destroy(struct key *key) */ int big_key_update(struct key *key, struct key_preparsed_payload *prep) { + struct big_key_payload old = { }; + bool positive = key_is_positive(key); int ret; - ret = key_payload_reserve(key, prep->datalen); + if (positive) + old = *to_big_key_payload(key->payload); + + ret = generic_key_instantiate(key, prep); if (ret < 0) return ret; - if (key_is_positive(key)) - big_key_destroy(key); + if (positive) { + if (old.length > BIG_KEY_FILE_THRESHOLD) + path_put(&old.path); + kfree_sensitive(old.data); + } - return generic_key_instantiate(key, prep); + return 0; } /*