From: Vasily Gorbik <gor@linux.ibm.com>
To: Justin Stitt <justinstitt@google.com>
Cc: Vineeth Vijayan <vneethv@linux.ibm.com>,
Peter Oberparleiter <oberpar@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] s390/cio: replace deprecated strncpy with strscpy
Date: Wed, 25 Oct 2023 12:25:04 +0200 [thread overview]
Message-ID: <your-ad-here.call-01698229504-ext-3663@work.hours> (raw)
In-Reply-To: <20231023-strncpy-drivers-s390-cio-chsc-c-v1-1-8b76a7b83260@google.com>
On Mon, Oct 23, 2023 at 07:24:38PM +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.
>
> We expect both `params` and `id` to be NUL-terminated based on their
> usage with format strings:
>
> format_node_data(iuparams, iunodeid, &lir->incident_node);
> format_node_data(auparams, aunodeid, &lir->attached_node);
>
> switch (lir->iq.class) {
> case LIR_IQ_CLASS_DEGRADED:
> pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x "
> "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n",
> sei_area->rs, sei_area->rsid, lir->ic, iuparams,
> iunodeid, auparams, aunodeid);
>
> NUL-padding is not required as both `params` and `id` have been memset
> to 0:
>
> memset(params, 0, PARAMS_LEN);
> memset(id, 0, NODEID_LEN);
>
> Considering the above, a suitable replacement is `strscpy` [2] due to
> the fact that it guarantees NUL-termination on the destination buffer
> without unnecessarily NUL-padding.
>
> Note that there's no overread bugs in the current implementation as the
> string literal "n/a" has a size much smaller than PARAMS_LEN or
> NODEID_LEN. Nonetheless, let's favor strscpy().
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Note: build-tested only.
>
> Found with: $ rg "strncpy\("
> ---
> drivers/s390/cio/chsc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Applied, thank you!
prev parent reply other threads:[~2023-10-25 10:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 19:24 [PATCH] s390/cio: replace deprecated strncpy with strscpy Justin Stitt
2023-10-24 23:58 ` Kees Cook
2023-10-25 7:32 ` Vineeth Vijayan
2023-10-25 10:25 ` Vasily Gorbik [this message]
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=your-ad-here.call-01698229504-ext-3663@work.hours \
--to=gor@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=justinstitt@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=oberpar@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=vneethv@linux.ibm.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.