mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zijie Zhao via B4 Relay <devnull+zzjas98.gmail.com@kernel.org>
To: Dan Williams <djbw@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	 Dave Jiang <dave.jiang@intel.com>,
	 Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <iweiny@kernel.org>,
	nvdimm@lists.linux.dev,  linux-kernel@vger.kernel.org,
	Zijie Zhao <zzjas98@gmail.com>
Subject: [PATCH] libnvdimm/security: Reject security commands with missing key ids
Date: Tue, 01 Dec 2026 21:16:27 -0600	[thread overview]
Message-ID: <20261201-kbug-l936-v1-1-a2e78263625c@gmail.com> (raw)

From: Zijie Zhao <zzjas98@gmail.com>

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 <zzjas98@gmail.com>
---
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 <zzjas98@gmail.com>



                 reply	other threads:[~2026-12-02  3:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-kbug-l936-v1-1-a2e78263625c@gmail.com \
    --to=devnull+zzjas98.gmail.com@kernel.org \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=iweiny@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    --cc=zzjas98@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®