public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Heiko Carstens <hca@linux.ibm.com>, Jens Axboe <axboe@kernel.dk>
Cc: Justin Stitt <justinstitt@google.com>,
	Peter Oberparleiter <oberpar@linux.ibm.com>,
	Stefan Haberland <sth@linux.ibm.com>,
	Jan Hoeppner <hoeppner@linux.ibm.com>,
	linux-s390@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	Viktor Mihajlovski <mihajlov@linux.ibm.com>
Subject: Re: [PATCH] partitions/ibm: refactor deprecated strncpy
Date: Wed, 23 Aug 2023 07:22:29 -0700	[thread overview]
Message-ID: <D14D69B0-63E4-4650-A7F0-44F6CF81F9F9@kernel.org> (raw)
In-Reply-To: <20230823141304.14378-F-hca@linux.ibm.com>

On August 23, 2023 7:13:04 AM PDT, Heiko Carstens <hca@linux.ibm.com> wrote:
>On Wed, Aug 23, 2023 at 03:49:36PM +0200, Heiko Carstens wrote:
>> On Tue, Aug 22, 2023 at 11:59:26PM +0000, Justin Stitt wrote:
>> > `strncpy` is deprecated for use on NUL-terminated destination strings [1].
>> > 
>> > A suitable replacement is `strscpy` [2] due to the fact that it
>> > guarantees NUL-termination on its destination buffer argument which is
>> > _not_ the case for `strncpy`!
>> > 
>> > Link: 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>
>> > ---
>> >  block/partitions/ibm.c | 8 ++++----
>> >  1 file changed, 4 insertions(+), 4 deletions(-)
>> > 
>> > diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c
>> > index 403756dbd50d..e5893cf71b57 100644
>> > --- a/block/partitions/ibm.c
>> > +++ b/block/partitions/ibm.c
>> > @@ -111,11 +111,11 @@ static int find_label(struct parsed_partitions *state,
>> >  		    !strcmp(temp, "LNX1") ||
>> >  		    !strcmp(temp, "CMS1")) {
>> >  			if (!strcmp(temp, "VOL1")) {
>> > -				strncpy(type, label->vol.vollbl, 4);
>> > -				strncpy(name, label->vol.volid, 6);
>> > +				strscpy(type, label->vol.vollbl, 4);
>> > +				strscpy(name, label->vol.volid, 6);
>> >  			} else {
>> > -				strncpy(type, label->lnx.vollbl, 4);
>> > -				strncpy(name, label->lnx.volid, 6);
>> > +				strscpy(type, label->lnx.vollbl, 4);
>> > +				strscpy(name, label->lnx.volid, 6);
>> >  			}
>> >  			EBCASC(type, 4);
>> >  			EBCASC(name, 6);
>> 
>> I'm quite sure this is not correct, since both type and name are not
>> necessarily NUL-terminated, and this code operates on purpose on such
>> strings.
>> 
>> Since currently Stefan and Jan are both not available, I added Peter
>> Oberparleiter to Cc who hopefully knows better than me.
>
>I was just made aware of that this patch is already in linux-next. And
>indeed: partition detection does not work anymore for DASDs. With this
>patch reverted it works again.
>
>Jens, can you remove or revert this patch again, please?


Looks like this should be strtomem_pad() rather than strscpy()...


-- 
Kees Cook

      parent reply	other threads:[~2023-08-23 14:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 23:59 [PATCH] partitions/ibm: refactor deprecated strncpy Justin Stitt
2023-08-23  0:09 ` Jens Axboe
2023-08-23 13:49 ` Heiko Carstens
2023-08-23 14:13   ` Heiko Carstens
2023-08-23 14:14     ` Jens Axboe
2023-08-23 14:22     ` Kees Cook [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=D14D69B0-63E4-4650-A7F0-44F6CF81F9F9@kernel.org \
    --to=kees@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hca@linux.ibm.com \
    --cc=hoeppner@linux.ibm.com \
    --cc=justinstitt@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mihajlov@linux.ibm.com \
    --cc=oberpar@linux.ibm.com \
    --cc=sth@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox