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=1796382972; b=38dKTN25KkuGjcWFKKategWKvH3snfnpVKG+X6VOFaARLZwnRQncs1nCFw80jOxasPL4 Z5IsEpbmzAJimp1+QWWikRShEk3GQt+2aMY15lFCcZoLmMCt+u8XIvDL1IKGKQU+omeVO xXxW57hk8L+hooukzaNkKZfLTK2UIVxZ5mDyNp1gmjx/3dM04pkjuhIDSvj/MBC7sH6jg ISmSCb/i5hAIYyzFzNoG7c+bsUnEP7uhk/LwOLT9qNBOH05OtBfjO+K/QBSZOONvWGSe9 5TexzqQMu3L/Fx5ofdRa4MYdKWEoB8sJ7qFL5U18an0a7Rf+xPNJ5wVHmFnQ4XsWMUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382972; 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=RGNDjUJl0D0OdbGYWjWCysyEc4VaGrL5jYqb0BNmHGQ=; b=WXf3lIfcv3NKnAL/zli6zPg2lYA2Z+wu1auRkQjm8WItVfIHhri7sx3+HsvLm06muXuX aJd3QoyeqwllfRZTFyW41QgK75PVM9v4vvIhNOJzcRtL8QVSKzSsPEGqiI1Bxn++i2r42 Qx14HyjZhHisZaIBrzwU2drdlIK2fWYlFkTcPowyGjpkOXkwtQycCT9cSCrZUo0+Xa5F0 2UeSQvpFUYk3iaWbNany3E1uVkXAVvc2YTQAqgCx/Pz4Qkjq7QFDAsUwSUXmdQK6j7Nkg sOwTH3Qw6onX0c/reiO1uk3p7N9bK4HDgv8IIcE1ykN5NkUbAi/VsiXXEiPrwtzjTag== 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=eBFU+9UR; 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 5BD64606A32F; Fri, 4 Dec 2026 11:16:12 +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=eBFU+9UR Received: by smtp.kernel.org (Postfix) with ESMTPSA id B75421F00897; Fri, 4 Dec 2026 11:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382972; bh=RGNDjUJl0D0OdbGYWjWCysyEc4VaGrL5jYqb0BNmHGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eBFU+9UR3HIrCmX3TgLHrA8j3XKS3dLj5ibQqUO0c/NK4obsAJmamyWqnV15MpZ/d cnEzWHK32Lu4FbIrj3qcn5YvM7HwpsNe5a2AO9QDbdKQo2N65zklw58vyHH+Ypdm8h qx8QkNQGTdy4Uyz6OJ1FREoIOPQLgzc7tpB3M23E= 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.18 631/703] KEYS: Fix crash on big_key read Date: Fri, 4 Dec 2026 19:08:50 +0900 Message-ID: <20261204100644.572626125@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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: 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; } /*