From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796181392; b=lhQ0GFB++7GPxsN5VwomQNLAPQw2Oqu02u6R+Z9PyRc6d0f0OZGg1aXhSH73vs0i6Wtc TFSb7qU7WaEr1VfYcIWAxtx1HEE1286jVvZaqLAIsb8yUSh7wvdbWC2lvgvRQP+/+I/oV 6OxmLusvuotD4zOb3u6sn3Sf411Ps+clAw2OlEsm3x9d6swQbcj6b6xz0Q1ekAMveXWwK 9S6EVM20TavQDp5Zc7f6QQV/ZDRnp6K3xuxKOBAZM/q48WFjdxXPW45fuyQR57CzPuoBH 0JME5fLrQj0sh0l+uafYgjImmN1jlvqlTTzYRiWyY/pktBnoEPo98G3fB6/1T6vRsWw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181392; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=yQTv4YplOwmRz+IxibAY+G5tcSEe/syBhfYDQtDX5kA=; b=y5zMFCdc+U98m+KLhQf3WiftwtBYOFwtgZl6oxxx0PczAcWB3EXIeRBp3gb9pNKnLo7k z9cFsxcNxnXWaY0xy9Mky3zABr+4GalJXZ+IHaQ6iz3Hw2RoPZIUhCZEt43LlYwhAVf2d 7nU989VZZNbxILI3OFs+G+cxhwwOQEgy/NHzceiGGkkqQUJgEatfN/R5pgyuQfAAOw6F4 VGFlWz2G+hXiLPnK328gNSRRZEqQI7B4vY85vYNJJ+aHi8ozga5MIhf7ntrWiluWNAch3 jqu4RdRWJufQpCPxvgxiS9dZ1utcthS/MTLrWh6LKo+VPE09daMCIytHpSc24sW1DJA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ikgdKybG; arc=pass header.oldest-pass=0 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 5654D606A6A6; Wed, 2 Dec 2026 03:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ikgdKybG Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796181391; b=Fa7nUVzsnYjDogAMH98g62RD38CCzCySpgS0esDdSIOyk/ul08h3sR3yW/9ugoMXWVwd dWIpeiY5+SfM6FOXdSUh++MhF9WPVjLaVzTasSDlzFaEMZagRrAE3yEFa2OF1SmugaD3b zYP16rC1iIz5lgQLtr06V5vH5dWVACQQ87I8YXxAr4NygUHQyY4JsxgWjHdGBPNsqSBPI gpiRoTr2AR7cbRq4H0yGddzIqOTVt5F8wGoFz8nrr+Gx8y6S2zDrTr7eBLn9gGp3RdA6m JbshWiCSpxvP3V85vneLCxpEtTf2L1TqDVmSkjQQLcqrbnGZe9DoF0yNYqAZNiuPa6Q== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796181391; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=yQTv4YplOwmRz+IxibAY+G5tcSEe/syBhfYDQtDX5kA=; b=3C19bTsGwG3Mdizvroa75+7B/c/LLKqQrgqi0badd9odaWV9zD15Jl3+3KLzTts+1E08 URni8MX/HL7EkCVSgRW/6KsQ+C/mf/8uwObjF0BQc7eI9gEkMXKf617mmMbwRV8CCkslU ZO+bxrVDOOPfgkf8qUHdGlDJ66leE55SdwNNn1XoqaT/VL15eKD3vQmAiD1UwrmXeQDhC AHsuyqP5JDnakRNvqAajlzKsiUolTASsVTou+pdfsiR6fOsev9TSPydGjne7S0/ZqA58t raDMhyhVGABCeC4ibB70HirHbRcRbP66NrcCGWkFA4WEb16rA3GOnK8nlYzHtPExpGg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 400311F00926; Wed, 2 Dec 2026 03:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181391; bh=yQTv4YplOwmRz+IxibAY+G5tcSEe/syBhfYDQtDX5kA=; h=From:Date:Subject:To:Cc:Reply-To; b=ikgdKybGz4efW2md9sdwlq/wzo5ZhEHJ0qggRvDYrxuY1iT1fTWbmZOjFzrmp4apg vMPJDtJUhgUG2i8zwA82mkSVt4aAam1JtB7ILi7Q2O3DFzRRwXa5pNymAW5kcdkIcv 5zAaJIVMtAAVP7aWbTr9cawCp6mBFIFT9WrH6t1ALj20TLhFjzIQTwDWXNBNqchVGg 0RwiE1Q7iLoNu+vOdVa7HBZtDxRl4EJJ+5TgOXtPaalTgsaPv03oMgWmFdw+F8qa9H tuv/VgEslmdMs+JYGInUVwYs9Jj9Dg/BZeEWqJCOPzkQgji4XqgzxR7/BajFhhHKWA LwBwzi2LsYmPg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id C46A24F1F4; Wed, 2 Dec 2026 03:16:26 +0000 (UTC) From: Zijie Zhao via B4 Relay Date: Tue, 01 Dec 2026 21:16:27 -0600 Subject: [PATCH] libnvdimm/security: Reject security commands with missing key ids X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-kbug-l936-v1-1-a2e78263625c@gmail.com> X-B4-Tracking: v=1; b=H4sIAIqND2sC/yXM0QpAMBSA4VfRubbaGS28ilzYHByENqTk3Q2XX /39F3hyTB6K6AJHB3te5gCMI7B9PXckuAkGJZVGJVGMZu/ElCdaSKNSSzWi1hmEfnXU8vm9yuq 3381AdnsHcN8PQbAXum0AAAA= X-Change-ID: 20261201-kbug-l936-0b24cea11668 To: Dan Williams , Vishal Verma , Dave Jiang , Alison Schofield Cc: Ira Weiny , nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, Zijie Zhao X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796181386; l=2063; i=zzjas98@gmail.com; s=20261126; h=from:subject:message-id; bh=xkD5xIiz5QSp3+QZl7UDp389VTZ9n+yJRnxi3RpCh5Y=; b=NGgziqb/Lejz5AxUKU65q++Oe8ZiSzPZ8SajZCphywDU0vPQ5rwb/Mum6ZbFQbvuGpmX+VyZj 8glxDTjE4xWDfxVfjOzLi/SImmUnM/5RbqsvkftRtwF7xn8PVnalM7J X-Developer-Key: i=zzjas98@gmail.com; a=ed25519; pk=JH1SXIjc6vLfCjl6NzH9q8FTNJnOj4FyHWYhz1uELOE= X-Endpoint-Received: by B4 Relay for zzjas98@gmail.com/20261126 with auth_id=1645 X-Original-From: Zijie Zhao Reply-To: zzjas98@gmail.com Content-Transfer-Encoding: 7bit From: Zijie Zhao nvdimm_security_store() parses the 'security' attribute with sscanf() into the uninitialized stack arrays cmd, keystr and nkeystr, but only rejects a return value below 1. Commands that take key ids are then parsed with kstrtouint() on keystr and nkeystr according to ops[i].args, regardless of how many fields sscanf() actually filled. Writing e.g. "disable" without a key id, or "update 1" without the new key id, makes kstrtouint() parse uninitialized stack memory that is not guaranteed to be NUL terminated within the array. If that memory parses as a number, a key id taken from stale stack contents is passed to the security operation handler instead of the write failing with -EINVAL, and the handler proceeds if its state and key checks succeed. Return -EINVAL when sscanf() converted fewer fields than the matched command requires. Found by a static analysis tool. The fix and this changelog were drafted with AI assistance (Claude Code, with a second review by OpenAI Codex), then reviewed by the submitter. Fixes: 03b65b22ada8 ("acpi/nfit, libnvdimm: Add disable passphrase support to Intel nvdimm.") Signed-off-by: Zijie Zhao --- Testing: - Compile-tested on x86_64 (allmodconfig, W=1): drivers/nvdimm/security.o; no new warnings. - checkpatch.pl --strict: no errors or warnings. --- drivers/nvdimm/security.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c index e41f6951ca0f..1fc6c0ad1460 100644 --- a/drivers/nvdimm/security.c +++ b/drivers/nvdimm/security.c @@ -534,6 +534,8 @@ ssize_t nvdimm_security_store(struct device *dev, const char *buf, size_t len) break; if (i >= ARRAY_SIZE(ops)) return -EINVAL; + if (rc < ops[i].args) + return -EINVAL; if (ops[i].args > 1) rc = kstrtouint(keystr, 0, &key); if (rc >= 0 && ops[i].args > 2) --- base-commit: 5a277aa7eb4d4f1f05534d6c3dcb1a9fa4f6b8f2 change-id: 20261201-kbug-l936-0b24cea11668 Best regards, -- Zijie Zhao