From: Laurence Oberman <loberman@redhat.com>
To: xujiahao <xujiahao@cmss.chinamobile.com>,
John Meneghini <jmeneghi@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: st: Avoid truncating the tape name for large tape numbers
Date: Fri, 06 Nov 2026 08:44:11 -0500 [thread overview]
Message-ID: <51dba0cd5655a635be2980267d51c4cb3dfa0314.camel@redhat.com> (raw)
In-Reply-To: <20261106021730.3409119-1-xujiahao@cmss.chinamobile.com>
On Fri, 2026-11-06 at 10:17 +0800, xujiahao wrote:
> create_one_cdev() builds the class device name in a 10-byte buffer as
> "n" (no-rewind devices) + tape->name + a one-character mode suffix.
> tape->name is a DISK_NAME_LEN (32) byte array holding "st%d", and the
> tape index comes from an idr with an upper bound of ST_MAX_TAPES - 1
> (131071, six digits), so "n" + "st131071" + suffix + terminator needs
> 11 bytes. Names of tapes with large index numbers are truncated
> today
> and lose the mode suffix, which leaves the rewind modes of such a
> tape
> with the same name.
>
> Size the buffer after the actual requirement, DISK_NAME_LEN + 2, and
> pass sizeof(name) to snprintf() so the two cannot drift apart again.
>
> GCC reports with -Wformat-truncation=2:
>
> drivers/scsi/st.c:4393:31: warning: '%s' directive output may be
> truncated writing up to 31 bytes into a region of size between 9 and
> 10 [-Wformat-truncation=]
>
> Signed-off-by: xujiahao <xujiahao@cmss.chinamobile.com>
> ---
> drivers/scsi/st.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index e9d41e3cc..311781987 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -4366,7 +4366,7 @@ static int create_one_cdev(struct scsi_tape
> *tape, int mode, int rew)
> struct cdev *cdev;
> struct device *dev;
> struct st_modedef *STm = &(tape->modes[mode]);
> - char name[10];
> + char name[DISK_NAME_LEN + 2];
> int dev_num = tape->index;
>
> cdev_devno = MKDEV(SCSI_TAPE_MAJOR, TAPE_MINOR(dev_num,
> mode, rew));
> @@ -4390,7 +4390,7 @@ static int create_one_cdev(struct scsi_tape
> *tape, int mode, int rew)
> }
>
> i = mode << (4 - ST_NBR_MODE_BITS);
> - snprintf(name, 10, "%s%s%s", rew ? "n" : "",
> + snprintf(name, sizeof(name), "%s%s%s", rew ? "n" : "",
> tape->name, st_formats[i]);
>
> dev = device_create(&st_sysfs_class, &tape->device-
> >sdev_gendev,
Hi,
Thanks for the patch.
The arithmetic is correct, but the truncation only occurs with tape
indices >= 100000, which is not a configuration anyone will
realistically
have. So this addresses a W=2 format-truncation warning rather than a
real-world problem, and I'd prefer not to churn st.c for that.
NAK for now.
Regards,
Laurence
prev parent reply other threads:[~2026-11-06 13:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 2:17 xujiahao
2026-11-06 13:44 ` Laurence Oberman [this message]
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=51dba0cd5655a635be2980267d51c4cb3dfa0314.camel@redhat.com \
--to=loberman@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=jmeneghi@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=xujiahao@cmss.chinamobile.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®