From: Kees Cook <keescook@chromium.org>
To: Justin Stitt <justinstitt@google.com>
Cc: Karsten Keil <isdn@linux-pingi.de>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] isdn: kcapi: replace deprecated strncpy with strscpy_pad
Date: Sat, 23 Sep 2023 20:36:19 -0700 [thread overview]
Message-ID: <202309232034.38BC5E1C3@keescook> (raw)
In-Reply-To: <20230922-strncpy-drivers-isdn-capi-kcapi-c-v1-1-55fcf8b075fb@google.com>
On Fri, Sep 22, 2023 at 11:49:14AM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings
> [1] and as such we should prefer more robust and less ambiguous string
> interfaces.
>
> `buf` is used in this context as a data buffer with 64 bytes of memory
> to be occupied by capi_manufakturer.
>
> We see the caller capi20_get_manufacturer() passes data.manufacturer as
> its `buf` argument which is then later passed over to user space. Due to
> this, let's keep the NUL-padding that strncpy provided by using
> strscpy_pad so as to not leak any stack data.
> | cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer);
> | if (cdev->errcode)
> | return -EIO;
> |
> | if (copy_to_user(argp, data.manufacturer,
> | sizeof(data.manufacturer)))
> | return -EFAULT;
Yup, strongly agreed: this needs the padding. I actually wonder if a
follow-up patch might be a good idea here, just for robustness:
capi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct capidev *cdev = file->private_data;
- capi_ioctl_struct data;
+ capi_ioctl_struct data = { };
>
> Perhaps this would also be a good instance to use `strtomem_pad` for but
> in my testing the compiler was not able to determine the size of `buf`
> -- even with all the hints.
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
next prev parent reply other threads:[~2023-09-24 3:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 11:49 [PATCH] isdn: kcapi: replace deprecated strncpy with strscpy_pad Justin Stitt
2023-09-24 3:36 ` Kees Cook [this message]
2023-09-29 19:37 ` Kees Cook
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=202309232034.38BC5E1C3@keescook \
--to=keescook@chromium.org \
--cc=isdn@linux-pingi.de \
--cc=justinstitt@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@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