mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ваторопин Андрей" <a.vatoropin@crpt.ru>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "Ваторопин Андрей" <a.vatoropin@crpt.ru>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"David Disseldorp" <ddiss@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"target-devel@vger.kernel.org" <target-devel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>
Subject: [PATCH] scsi: target: Add a check to prevent the use of a NULL pointer
Date: Wed, 8 Apr 2026 10:14:20 +0000	[thread overview]
Message-ID: <20260408101400.8373-1-a.vatoropin@crpt.ru> (raw)

From: Andrey Vatoropin <a.vatoropin@crpt.ru>

Some functions accept a string input parameter, which is then passed to
strscpy(). If strscpy() returns zero the (len > 0) branch is not taken and
`stripped` remains NULL. The subsequent check (len < 0 || len >
INQUIRY_VENDOR_LEN) does not catch this case, allowing a NULL `stripped`
pointer to be passed to target_check_inquiry_data().

Therefore, the existing checks are insufficient to prevent the use of a
NULL pointer when an empty string is passed.

Add exclusion of zero-length strings to avoid dereferencing a NULL
`stripped` pointer.

Found by Linux Verification Center (linuxtesting.org) with SVACE.
       
Fixes: 54a6f3f6a43c ("scsi: target: add device vendor_id configfs attribute")
Signed-off-by: Andrey Vatoropin <a.vatoropin@crpt.ru>
---
 drivers/target/target_core_configfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index a1c91d4515bc..3aaa2b931009 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -1455,6 +1455,10 @@ static ssize_t target_wwn_vendor_id_store(struct config_item *item,
 			"\n");
 		return -EOVERFLOW;
 	}
+	if (len == 0) {
+		pr_err("Emulated T10 Vendor Identification equals zero.\n");
+		return -EINVAL;
+	}
 
 	ret = target_check_inquiry_data(stripped);
 
@@ -1511,6 +1515,10 @@ static ssize_t target_wwn_product_id_store(struct config_item *item,
 			"\n");
 		return -EOVERFLOW;
 	}
+	if (len == 0) {
+		pr_err("Emulated T10 Vendor equals zero.\n");
+		return -EINVAL;
+	}
 
 	ret = target_check_inquiry_data(stripped);
 
@@ -1567,6 +1575,10 @@ static ssize_t target_wwn_revision_store(struct config_item *item,
 			"\n");
 		return -EOVERFLOW;
 	}
+	if (len == 0) {
+		pr_err("Emulated T10 Revision equals zero.\n");
+		return -EINVAL;
+	}
 
 	ret = target_check_inquiry_data(stripped);
 
-- 
2.43.0

             reply	other threads:[~2026-04-08 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08 10:14 Ваторопин Андрей [this message]
2026-04-09 13:32 ` James Bottomley

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=20260408101400.8373-1-a.vatoropin@crpt.ru \
    --to=a.vatoropin@crpt.ru \
    --cc=ddiss@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=martin.petersen@oracle.com \
    --cc=r.bolshakov@yadro.com \
    --cc=target-devel@vger.kernel.org \
    /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®