Linux IIO development
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: David Lechner <dlechner@baylibre.com>,
	nuno.sa@analog.com,  linux-iio@vger.kernel.org
Cc: Olivier Moysan <olivier.moysan@foss.st.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH 1/2] iio: backend: make sure to NULL terminate stack buffer
Date: Tue, 18 Feb 2025 16:36:00 +0000	[thread overview]
Message-ID: <3ead92b71ccf8b2d4e1762ca369911d637619883.camel@gmail.com> (raw)
In-Reply-To: <553ed40f-f0dc-4902-9d2a-9b690fce6ff9@baylibre.com>

On Tue, 2025-02-18 at 09:52 -0600, David Lechner wrote:
> On 2/18/25 4:31 AM, Nuno Sá via B4 Relay wrote:
> > From: Nuno Sá <nuno.sa@analog.com>
> > 
> > Make sure to NULL terminate the buffer in
> > iio_backend_debugfs_write_reg() before passing it to sscanf(). It is a
> > stack variable so we should not assume it will 0 initialized.
> > 
> > Fixes: cdf01e0809a4 ("iio: backend: add debugFs interface")
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > ---
> >  drivers/iio/industrialio-backend.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-
> > backend.c
> > index
> > d4ad36f54090204bf3bef08457d4aa55aa7c11fc..a43c8d1bb3d0f4dda4277cac94b0ea9232
> > c071e4 100644
> > --- a/drivers/iio/industrialio-backend.c
> > +++ b/drivers/iio/industrialio-backend.c
> > @@ -155,10 +155,12 @@ static ssize_t iio_backend_debugfs_write_reg(struct
> > file *file,
> >  	ssize_t rc;
> >  	int ret;
> >  
> > -	rc = simple_write_to_buffer(buf, sizeof(buf), ppos, userbuf,
> > count);
> > +	rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
> > count);
> >  	if (rc < 0)
> >  		return rc;
> >  
> > +	buf[count] = '\0';
> 
> Does this need to be count++? Later we return count.
> 

Don't think so... count comes down from userspace. The termination is local so
we do not want to return count + 1 when userspace only requested to write count.
Same deal as in iio_debugfs_write_reg()

Also note that we pass sizeof(buf) - 1 into simple_write_to_buffer()

- Nuno Sá
> 

  reply	other threads:[~2025-02-18 16:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 10:31 [PATCH 0/2] iio: small fixes and improvements Nuno Sá via B4 Relay
2025-02-18 10:31 ` [PATCH 1/2] iio: backend: make sure to NULL terminate stack buffer Nuno Sá via B4 Relay
2025-02-18 15:52   ` David Lechner
2025-02-18 16:36     ` Nuno Sá [this message]
2025-02-18 16:57       ` David Lechner
2025-02-18 10:31 ` [PATCH 2/2] iio: core: make use of simple_write_to_buffer() Nuno Sá via B4 Relay
2025-02-18 17:29 ` [PATCH 0/2] iio: small fixes and improvements David Lechner
2025-02-22 14:23   ` Jonathan Cameron

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=3ead92b71ccf8b2d4e1762ca369911d637619883.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=olivier.moysan@foss.st.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