From: "Arnd Bergmann" <arnd@arndb.de>
To: "Dan Carpenter" <dan.carpenter@linaro.org>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
linux-kernel@vger.kernel.org,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Kees Cook" <keescook@chromium.org>,
"Daniel Micay" <danielmicay@gmail.com>,
linux-staging@lists.linux.dev
Subject: Re: [PATCH 03/11] staging: replace weird strncpy() with memcpy()
Date: Mon, 08 Apr 2024 21:20:25 +0200 [thread overview]
Message-ID: <88009872-377b-4155-aceb-88d36f4a44e4@app.fastmail.com> (raw)
In-Reply-To: <948ab982-cb4d-46d4-a3c4-cc1c6369eb92@moroto.mountain>
On Mon, Apr 8, 2024, at 17:59, Dan Carpenter wrote:
> On Mon, Apr 08, 2024 at 04:45:55PM +0200, Arnd Bergmann wrote:
>> On Thu, Mar 28, 2024, at 17:35, Dan Carpenter wrote:
>> >> if (sendbytes > 8) {
>> >> memcpy(buf, inquiry_buf, 8);
>> >> - strncpy(buf + 8, inquiry_string, sendbytes - 8);
>> >> + memcpy(buf + 8, inquiry_string, min(sendbytes, 36) - 8);
>> >
>> > I think your math is off. The string is 29 characters + NUL. So it
>> > should be "min(sendbytes, 38) - 8". You're chopping off the space and
>> > the NUL terminator.
>> >
>> > This only affects pro_formatter_flag code...
>>
>> The extra two bytes were clearly a mistake in the original version
>> at the time it got added to drivers/staging. Note how the code
>> immediately below it would overwrite the space and NUL byte again:
>>
>> if (pro_formatter_flag) {
>> if (sendbytes > 36)
>> memcpy(buf + 36, formatter_inquiry_str, sendbytes - 36);
>> }
>>
>
> Ah. Okay. Fair enough.
>
> I do think this code is really suspect... What is the point of allowing
> sendbytes < 36? But that's not related to your patch.
As far as I can tell, the driver tries to emulate the behavior
or normal scsi commands that could be issued from userspace through
SGIO with a short length. drivers/ata/libata-scsi.c has code to
handle INQUIRY as well that is somewhat similar but also different
enough that I don't trust the rts5208 version of it.
On a separate note, I just noticed that I forgot to put
the driver name into the subject line, which I've fixed
up for v2 as well now.
Arnd
next prev parent reply other threads:[~2024-04-08 19:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 14:04 [PATCH 00/11] address remaining stringop-truncation warnings Arnd Bergmann
2024-03-28 14:04 ` [PATCH 01/11] staging: vc04_services: changen strncpy() to strscpy_pad() Arnd Bergmann
2024-03-28 14:42 ` Dan Carpenter
2024-03-28 16:15 ` Arnd Bergmann
2024-03-28 23:10 ` Justin Stitt
2024-03-28 14:04 ` [PATCH 03/11] staging: replace weird strncpy() with memcpy() Arnd Bergmann
2024-03-28 16:35 ` Dan Carpenter
2024-04-08 14:45 ` Arnd Bergmann
2024-04-08 15:59 ` Dan Carpenter
2024-04-08 19:20 ` Arnd Bergmann [this message]
2024-03-28 14:04 ` [PATCH 09/11] staging: rtl8723bs: convert strncpy to strscpy Arnd Bergmann
2024-03-28 23:01 ` Justin Stitt
2024-04-08 18:15 ` Arnd Bergmann
2024-03-28 14:04 ` [PATCH 10/11] staging: greybus: change strncpy() to strscpy() Arnd Bergmann
2024-03-28 15:00 ` Dan Carpenter
2024-04-08 18:26 ` Arnd Bergmann
2024-04-09 7:09 ` Dan Carpenter
2024-03-28 23:28 ` Justin Stitt
2024-04-08 18:30 ` Arnd Bergmann
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=88009872-377b-4155-aceb-88d36f4a44e4@app.fastmail.com \
--to=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=danielmicay@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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