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=1796381534; b=tOV1diRcJnPYoeEkCcgF5Ys9LS1Nta6CSJ3ERhvfZ2mtc9MRqmcml8UHAhi1A0ZA+SZA 6TBh/wXpAtyseNIaxsAC+biZnTcr46I6hEi8W7CPD0Uk6qlpQMjwaBsctn+s24JSikoKs GbMzmvMXDuV7rUkwCaAQv2N2+BotIWHsIduAv+ulDX47jDkpGpyFk+DizgdVvQKMsaww/ lbTVxr4f+JuxEO8y98C8SE08b6ChsvAsWA/GAwrXY76LgGjb/YjJatvxkIcnL4W5r7ETG EYbJS7dfVH360qWiiXpMWcy3lEE+QTD+Px65J+uCE9E4dyvBXGS/jmp3aSKRami8S5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381534; 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=v4CWue5eLYhO8tWIBPEtkNCsVeXcOihTsCDacv4McrY=; b=waT7prSyrZRtnreF975s4L3DvWY8T1soQR9CENqNtveF2PsMIpd7KpoeyvHJ+oSJwOx9 4Emo8OnkaK4d7c/aWJqQhJah/RgUY8E5P1kiDUy4wvnI2x1BhBVemQYM4UxgrSYNxa1xC aszwXgWOYGK1MYDTAcbwn1v4R4w38qAxytvqdL4btFjCggSV5VobFCqiTrML/qgQTAv1T eSANcbHE0KFaZ0HyTU2FHQYHuarB9ilfhl6SPPokkTIo94zxj8oxIC9dssCKR8lyiy0pu yVV/hj+McMFxhpxKWZ/V3ruNCwN0wJbZ+N6FyMAkJGHQd9/b1JsV5sEO3yRuYD8NZcw== 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=e0IC0LOX; 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 5A2AE606A683; Fri, 4 Dec 2026 10:52:14 +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=e0IC0LOX Received: by smtp.kernel.org (Postfix) with ESMTPSA id C97081F000C2; Fri, 4 Dec 2026 10:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381534; bh=v4CWue5eLYhO8tWIBPEtkNCsVeXcOihTsCDacv4McrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e0IC0LOXOYUNZ69fF5AD92uzYjs2ii5m4NFUQ1IO4MBvzHwqpmZJ6aMJnCB0k6yzS LqMdcvCo5eX0tiXM7Vmy5PTi6FgYS1XaqnUEwUPU5zRAtkQXlvE/mqLWDESfQlrtOn SNbF8fcAoEsvKFyQPJpjwFubVb5SZwjbDJU80pLg= 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 7.3 706/742] KEYS: Fix crash on big_key read Date: Fri, 4 Dec 2026 19:09:30 +0900 Message-ID: <20261204100653.811332859@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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; } /*