From: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
To: Kees Cook <keescook@chromium.org>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: Re: [PATCH 2/3] media: replace strcpy() by strscpy()
Date: Mon, 10 Sep 2018 17:14:15 -0300 [thread overview]
Message-ID: <20180910171415.7eac2732@coco.lan> (raw)
In-Reply-To: <20180910164847.3f015458@coco.lan>
Em Mon, 10 Sep 2018 16:48:47 -0300
Mauro Carvalho Chehab <mchehab+samsung@kernel.org> escreveu:
> Em Mon, 10 Sep 2018 09:16:35 -0700
> Kees Cook <keescook@chromium.org> escreveu:
>
> > On Mon, Sep 10, 2018 at 5:19 AM, Mauro Carvalho Chehab
> > <mchehab+samsung@kernel.org> wrote:
> > > The strcpy() function is being deprecated upstream. Replace
> > > it by the safer strscpy().
> >
> > Did you verify that all the destination buffers here are arrays and
> > not pointers? For example:
> >
> > struct thing {
> > char buffer[64];
> > char *ptr;
> > }
> >
> > strscpy(instance->buffer, source, sizeof(instance->buffer));
> >
> > is correct.
> >
> > But:
> >
> > strscpy(instance->ptr, source, sizeof(instance->ptr));
> >
> > will not be and will truncate strings to sizeof(char *).
> >
> > If you _did_ verify this, I'd love to know more about your tooling. :)
>
> I ended by implementing a simple tooling to test... it found just
> one place where it was wrong. I'll send the correct patch.
Btw, at the only case it was trying to fill a pointer was for
some sysfs fill. AFAIKT, the buffer size there is PAGE_SIZE,
so, I guess the enclosed patch would be the right way to use
strscpy().
Yet, IMHO, a better fix would be if the parameters for
DEVICE_ATTR store field would have a count.
Thanks,
Mauro
diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index 1041c056854d..989d2554ec72 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -772,9 +772,9 @@ static ssize_t show_associate_remote(struct device *d,
mutex_lock(&ictx->lock);
if (ictx->rf_isassociating)
- strcpy(buf, "associating\n");
+ strscpy(buf, "associating\n", PAGE_SIZE);
else
- strcpy(buf, "closed\n");
+ strscpy(buf, "closed\n", PAGE_SIZE);
dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for instructions on how to associate your iMON 2.4G DT/LT remote\n");
mutex_unlock(&ictx->lock);
next prev parent reply other threads:[~2018-09-11 1:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 12:19 [PATCH 0/3] Use only strscpy() for string copy Mauro Carvalho Chehab
2018-09-10 12:19 ` [PATCH 1/3] media: use strscpy() instead of strlcpy() Mauro Carvalho Chehab
2018-09-10 16:13 ` Kees Cook
2018-09-11 15:55 ` Hans Verkuil
2018-09-10 12:19 ` [PATCH 2/3] media: replace strcpy() by strscpy() Mauro Carvalho Chehab
2018-09-10 16:16 ` Kees Cook
2018-09-10 19:48 ` Mauro Carvalho Chehab
2018-09-10 20:14 ` Mauro Carvalho Chehab [this message]
2018-09-10 20:20 ` [PATCH 2/3 v2] " Mauro Carvalho Chehab
2018-09-11 15:54 ` Hans Verkuil
2018-09-10 12:19 ` [PATCH 3/3] media: replace strncpy() " Mauro Carvalho Chehab
2018-09-10 16:18 ` Kees Cook
2018-09-10 18:34 ` Mauro Carvalho Chehab
2018-09-10 20:38 ` Kees Cook
2018-09-12 7:04 ` Hans Verkuil
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=20180910171415.7eac2732@coco.lan \
--to=mchehab+samsung@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@infradead.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