From: Greg KH <gregkh@linuxfoundation.org>
To: Kees Bakker <kees@ijzerbout.nl>
Cc: Dave Penkler <dpenkler@gmail.com>,
Linux Staging <linux-staging@lists.linux.dev>
Subject: Re: [PATCH] staging: gpib: avoid buffer overflow
Date: Thu, 17 Oct 2024 20:23:25 +0200 [thread overview]
Message-ID: <2024101759-petticoat-prone-52ad@gregkh> (raw)
In-Reply-To: <20241017181435.70D2B18DAF2@bout3.ijzerbout.nl>
On Tue, Oct 15, 2024 at 08:38:13PM +0200, Kees Bakker wrote:
> The remaining buffer size for snprintf also depends on `pos`.
>
> Signed-off-by: Kees Bakker <kees@ijzerbout.nl>
> ---
> drivers/staging/gpib/ni_usb/ni_usb_gpib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> index 1da263676f2a..4df1ceaa138f 100644
> --- a/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> +++ b/drivers/staging/gpib/ni_usb/ni_usb_gpib.c
> @@ -364,7 +364,7 @@ static void ni_usb_dump_raw_block(const u8 *raw_data, int length)
> pr_info("%s\n", print_buf);
> pos = 0;
> }
> - pos += snprintf(&print_buf[pos], RAW_BUF_SIZE, " %02x", raw_data[i]);
> + pos += snprintf(&print_buf[pos], RAW_BUF_SIZE - pos, " %02x", raw_data[i]);
> }
> if (pos)
> pr_info("%s\n", print_buf);
The better thing to do would be to delete this whole function and just
use the in-kernel hex_dump_to_buffer() function instead, which handles
all of this logic properly.
Can you do that instead?
thanks,
greg k-h
next prev parent reply other threads:[~2024-10-17 18:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 18:38 [PATCH] staging: gpib: avoid buffer overflow Kees Bakker
2024-10-17 18:23 ` Greg KH [this message]
2024-10-17 18:24 ` Greg KH
[not found] <20241015201629.4B97918DA87@bout3.ijzerbout.nl>
2024-10-17 9:44 ` Dave Penkler
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=2024101759-petticoat-prone-52ad@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dpenkler@gmail.com \
--cc=kees@ijzerbout.nl \
--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