From: Dan Carpenter <error27@gmail.com>
To: Christian Lamparter <chunkeey@gmail.com>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH 3/3] wifi: carl9170: NUL terminate string in debugfs
Date: Thu, 1 Oct 2026 21:31:32 +0300 [thread overview]
Message-ID: <ar6nBMGUaqRPnRv_@stanley.mountain> (raw)
In-Reply-To: <e550f231-87cd-4220-a17e-d0288516ef9e@gmail.com>
On Thu, Oct 01, 2026 at 07:58:13PM +0200, Christian Lamparter wrote:
> On 10/1/26 9:37 AM, Dan Carpenter wrote:
> > The "buf" buffer comes from the user. We use it to store a number or
> > two so it doesn't need to be large. It gets passed to sscanf() in the
> > write functions such as carl9170_debugfs_erp_write(). Ensure that
> > buffer is NUL terminated.
> >
> > This is debugfs so it's root only.
>
> Sure.
> >
> > Fixes: 00c4da27a421 ("carl9170: firmware parser and debugfs code")
> > Signed-off-by: Dan Carpenter <error27@gmail.com>
> Acked-by: Christian Lamparter <chunkeey@gmail.com>
>
> > ---
> > drivers/net/wireless/ath/carl9170/debug.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/wireless/ath/carl9170/debug.c b/drivers/net/wireless/ath/carl9170/debug.c
> > index 0498df2a2160..bc6c8e0b1d16 100644
> > --- a/drivers/net/wireless/ath/carl9170/debug.c
> > +++ b/drivers/net/wireless/ath/carl9170/debug.c
> > @@ -119,7 +119,7 @@ static ssize_t carl9170_debugfs_write(struct file *file,
> > if (!count)
> > return 0;
> > - if (count > PAGE_SIZE)
> > + if (count >= PAGE_SIZE)
> heh. It's unnecessary to change this for the max. two numbers we get.
> But I'm curious if this is a change that an AI tool added?
No. The other two patches used kzalloc() to allocate their buffers so
changing "> PAGE_SIZE" to ">= PAGE_SIZE" fixed the bug. But as I was
writing this, I decided that there was no way I was going to let people
allocat PAGE_SIZE + 1 bytes... :P Plus, since I was adding a byte
later it kind of maintained the status quo to subtract one here.
I did use AI to write the Smatch check. ;)
>
> But yeah, it's still fine.
>
> > return -E2BIG;
> > ar = file->private_data;
> > @@ -131,7 +131,7 @@ static ssize_t carl9170_debugfs_write(struct file *file,
> > if (!dfops->write)
> > return -ENOSYS;
> > - buf = vmalloc(count);
> > + buf = vmalloc(count + 1);
>
> I think there's also a vzalloc...
>
I was more considering changing this to kzalloc() but I decided that
was too much change.
> > if (!buf)
> > return -ENOMEM;
> > @@ -139,6 +139,7 @@ static ssize_t carl9170_debugfs_write(struct file *file,
> > err = -EFAULT;
> > goto out_free;
> > }
> > + buf[count] = '\0';
> which would eliminate that. But yeah, this is fine as well.
Thanks!
regards,
dan carpenter
next prev parent reply other threads:[~2026-10-01 18:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 7:37 [PATCH 0/3] wifi: NULL terminate some user strings Dan Carpenter
2026-10-01 7:37 ` [PATCH 1/3] wifi: b43: don't pass unterminated string to sscanf() Dan Carpenter
2026-10-01 7:37 ` [PATCH 2/3] wifi: b43legacy: debugfs: NUL terminate string in debugfs Dan Carpenter
2026-10-01 7:37 ` [PATCH 3/3] wifi: carl9170: " Dan Carpenter
2026-10-01 17:58 ` Christian Lamparter
2026-10-01 18:31 ` Dan Carpenter [this message]
2026-10-03 22:49 ` Jeff Johnson
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=ar6nBMGUaqRPnRv_@stanley.mountain \
--to=error27@gmail.com \
--cc=chunkeey@gmail.com \
--cc=linux-wireless@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