From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Wang Haoran <haoranwangsec@gmail.com>,
ziiiro <yuanmingbuaa@gmail.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 6.12 03/10] scsi: target: target_core_configfs: Add length check to avoid buffer overflow
Date: Fri, 3 Oct 2025 18:05:50 +0200 [thread overview]
Message-ID: <20251003160338.560421570@linuxfoundation.org> (raw)
In-Reply-To: <20251003160338.463688162@linuxfoundation.org>
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Haoran <haoranwangsec@gmail.com>
commit 27e06650a5eafe832a90fd2604f0c5e920857fae upstream.
A buffer overflow arises from the usage of snprintf to write into the
buffer "buf" in target_lu_gp_members_show function located in
/drivers/target/target_core_configfs.c. This buffer is allocated with
size LU_GROUP_NAME_BUF (256 bytes).
snprintf(...) formats multiple strings into buf with the HBA name
(hba->hba_group.cg_item), a slash character, a devicename (dev->
dev_group.cg_item) and a newline character, the total formatted string
length may exceed the buffer size of 256 bytes.
Since snprintf() returns the total number of bytes that would have been
written (the length of %s/%sn ), this value may exceed the buffer length
(256 bytes) passed to memcpy(), this will ultimately cause function
memcpy reporting a buffer overflow error.
An additional check of the return value of snprintf() can avoid this
buffer overflow.
Reported-by: Wang Haoran <haoranwangsec@gmail.com>
Reported-by: ziiiro <yuanmingbuaa@gmail.com>
Signed-off-by: Wang Haoran <haoranwangsec@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/target/target_core_configfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -2776,7 +2776,7 @@ static ssize_t target_lu_gp_members_show
config_item_name(&dev->dev_group.cg_item));
cur_len++; /* Extra byte for NULL terminator */
- if ((cur_len + len) > PAGE_SIZE) {
+ if ((cur_len + len) > PAGE_SIZE || cur_len > LU_GROUP_NAME_BUF) {
pr_warn("Ran out of lu_gp_show_attr"
"_members buffer\n");
break;
next prev parent reply other threads:[~2025-10-03 16:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-03 16:05 [PATCH 6.12 00/10] 6.12.51-rc1 review Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 01/10] crypto: sha256 - fix crash at kexec Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 02/10] gcc-plugins: Remove TODO_verify_il for GCC >= 16 Greg Kroah-Hartman
2025-10-03 16:05 ` Greg Kroah-Hartman [this message]
2025-10-03 16:05 ` [PATCH 6.12 04/10] media: b2c2: Fix use-after-free causing by irq_check_work in flexcop_pci_remove Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 05/10] media: tuner: xc5000: Fix use-after-free in xc5000_release Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 06/10] media: rc: fix races with imon_disconnect() Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 07/10] media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 08/10] mm: swap: check for stable address space before operating on the VMA Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 09/10] wifi: ath11k: fix NULL dereference in ath11k_qmi_m3_load() Greg Kroah-Hartman
2025-10-03 16:05 ` [PATCH 6.12 10/10] ASoC: qcom: audioreach: fix potential null pointer dereference Greg Kroah-Hartman
2025-10-03 17:24 ` [PATCH 6.12 00/10] 6.12.51-rc1 review Florian Fainelli
2025-10-03 20:51 ` Brett Mastbergen
2025-10-04 11:36 ` Brett A C Sheffield
2025-10-04 12:13 ` [PATCH 6.12 00/10] " Naresh Kamboju
2025-10-04 13:18 ` Jon Hunter
2025-10-04 16:57 ` Shuah Khan
2025-10-04 21:19 ` Peter Schneider
2025-10-04 21:20 ` Ron Economos
2025-10-05 16:26 ` Mark Brown
2025-10-09 14:23 ` Pavel Machek
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=20251003160338.560421570@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=haoranwangsec@gmail.com \
--cc=martin.petersen@oracle.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=yuanmingbuaa@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;
as well as URLs for NNTP newsgroup(s).