From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 99BBE3B47CD; Tue, 13 Oct 2026 12:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791893092; cv=none; b=giSukGjG5vKHu/q9Vmow7UFLvzlaTPCizYh/biBp9XACFGkPmapinE+bVRZSW6YLefffpCkCqx81VUKHA76l499geQkMLdNxO7uDNV/RoAZLAAlRj+0MZXVDAuUWCI7S7FIqEOFDF1s+bT2OrKsxnZ16sseClqDNxy5e7UNEt+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791893092; c=relaxed/simple; bh=9Nk6LGGA36sLRKYDF0dwnHXVqxvKmVWhEYgmEQ0tO/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oK5YYXwluXqMqX4KAQkYWl3GE5PXAKL1EQaUu6q9jzC8FqwYab86+BhKNBwGln4OUCQZHKp8dAsIPE2Ck55EbE24Lg5xnpvfKhJVp4Qm8KysIRDsYmZ61+DdPhL1aJ1aerSiL92iaY6oZjnqhRMEStZwsuwEvy6hQp6RCDVraLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=V/rkopX1; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="V/rkopX1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D853A1F000FF; Tue, 13 Oct 2026 12:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791893091; bh=NQmXuFJLSJmfaJpE2IYS9BgozwR23OBsz7WGNb+vJEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V/rkopX1NiWdPi2aw16OWiqzgyA1f5Yvah2SZ3xB6Wv9uLOyVokLmRv5cLVquLo0v lGaYpW+sM4+zUS3gbzKPVoIwO6bW9ltoomEp9LBBpsJXoJyBR0pB1MMuGvcZXOMxLw ztgiz/39K4VcAp61t4/eKQp65sZJTEP9tzXW/1ts= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?=EC=84=B1=EB=B3=91=EC=B0=AC?= , Jarkko Sakkinen Subject: [PATCH 6.18 065/621] KEYS: Fix add_key() race with keyring restriction Date: Tue, 13 Oct 2026 13:31:00 +0200 Message-ID: <20261013112922.403368039@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261013112920.855194808@linuxfoundation.org> References: <20261013112920.855194808@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: 성병찬 commit dd3ea3fcba7c75493760cdbccd35f029597e8d5e upstream. __key_create_or_update() snapshots keyring->restrict_link before taking the destination keyring's semaphore. keyring_restrict() installs a restriction while holding that semaphore. This allows a writer to observe no restriction, wait for the keyring owner to install a reject-all restriction and return successfully, and then link a key using the stale NULL snapshot. The writer only needs write permission on the destination keyring. Move the restrict_link read after __key_link_lock() and __key_link_begin(). The read and the subsequent restriction check are then serialized with restriction installation by keyring->sem. The race was reproduced on v7.2.8 in 19 executions where restriction installation returned before the link completed. All 19 linked the key despite the reject-all restriction. With this change, 312 executions reached the same ordering and every add_key() call failed with -EPERM. The issue was found by manual concurrency analysis assisted by AI-based analysis and independently verified with a QEMU reproducer and kernel instrumentation. Fixes: 5ac7eace2d00 ("KEYS: Add a facility to restrict new links into a keyring") Cc: stable@vger.kernel.org Signed-off-by: 성병찬 Reviewed-by: Jarkko Sakkinen Link: https://lore.kernel.org/r/20260930041802.6114-1-tjdqudcks0424@naver.com Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- security/keys/key.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/security/keys/key.c +++ b/security/keys/key.c @@ -840,9 +840,6 @@ static key_ref_t __key_create_or_update( key_check(keyring); - if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION)) - restrict_link = keyring->restrict_link; - key_ref = ERR_PTR(-ENOTDIR); if (keyring->type != &key_type_keyring) goto error_put_type; @@ -880,6 +877,9 @@ static key_ref_t __key_create_or_update( goto error_link_end; } + if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION)) + restrict_link = keyring->restrict_link; + if (restrict_link && restrict_link->check) { ret = restrict_link->check(keyring, index_key.type, &prep.payload, restrict_link->key);