From: Kees Cook <keescook@chromium.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Justin Stitt <justinstitt@google.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH v3] null_blk: replace strncpy with strscpy
Date: Tue, 3 Oct 2023 17:00:17 -0700 [thread overview]
Message-ID: <202310031658.9F0DB21C@keescook> (raw)
In-Reply-To: <20230919-strncpy-drivers-block-null_blk-main-c-v3-1-10cf0a87a2c3@google.com>
On Tue, Sep 19, 2023 at 05:30:35AM +0000, Justin Stitt wrote:
> `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>
> We should favor a more robust and less ambiguous interface.
>
> We expect that both `nullb->disk_name` and `disk->disk_name` be
> NUL-terminated:
> | snprintf(nullb->disk_name, sizeof(nullb->disk_name),
> | "%s", config_item_name(&dev->group.cg_item));
> ...
> | pr_info("disk %s created\n", nullb->disk_name);
>
> It seems like NUL-padding may be required due to __assign_disk_name()
> utilizing a memcpy as opposed to a `str*cpy` api.
> | static inline void __assign_disk_name(char *name, struct gendisk *disk)
> | {
> | if (disk)
> | memcpy(name, disk->disk_name, DISK_NAME_LEN);
> | else
> | memset(name, 0, DISK_NAME_LEN);
> | }
>
> Then we go and print it with `__print_disk_name` which wraps `nullb_trace_disk_name()`.
> | #define __print_disk_name(name) nullb_trace_disk_name(p, name)
>
> This function obviously expects a NUL-terminated string.
> | const char *nullb_trace_disk_name(struct trace_seq *p, char *name)
> | {
> | const char *ret = trace_seq_buffer_ptr(p);
> |
> | if (name && *name)
> | trace_seq_printf(p, "disk=%s, ", name);
> | trace_seq_putc(p, 0);
> |
> | return ret;
> | }
>
> >From the above, we need both 1) a NUL-terminated string and 2) a
> NUL-padded string. So, let's use strscpy_pad() as per Kees' suggestion
> from v1.
>
> 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
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Ping on this one too. Jens, can you pick this up?
Thanks!
-Kees
--
Kees Cook
next prev parent reply other threads:[~2023-10-04 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 5:30 [PATCH v3] null_blk: replace strncpy with strscpy Justin Stitt
2023-09-20 15:38 ` Kees Cook
2023-10-04 0:00 ` Kees Cook [this message]
2023-10-04 0:23 ` Jens Axboe
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=202310031658.9F0DB21C@keescook \
--to=keescook@chromium.org \
--cc=axboe@kernel.dk \
--cc=justinstitt@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.