From: Justin Stitt <justinstitt@google.com>
To: Stefan Haberland <sth@linux.ibm.com>,
Jan Hoeppner <hoeppner@linux.ibm.com>,
Jens Axboe <axboe@kernel.dk>
Cc: Kees Cook <keescook@chromium.org>,
linux-s390@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
Justin Stitt <justinstitt@google.com>
Subject: [PATCH v2] partitions/ibm: refactor deprecated strncpy
Date: Wed, 23 Aug 2023 21:24:22 +0000 [thread overview]
Message-ID: <20230823-strncpy-block-partitions-cmdline-ibm-v2-1-40c77f7182fc@google.com> (raw)
`strncpy` is deprecated [1] and we should favor different interfaces.
A suitable replacement is `strtomem_pad` as it is a more robust and less
ambiguous interface. In this case, the destination buffer is not
necessarily NUL-terminated as Heiko points out [2]. Using `strtomem_pad`
over strncpy means it is now more obvious what is expected of the
destination buffer: 1) Not necessarily NUL-terminated and 2) padded with
NUL-bytes
Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1]
Link: https://lore.kernel.org/all/20230823134936.14378-E-hca@linux.ibm.com/ [2]
Link: https://github.com/KSPP/linux/issues/90
Suggested-by: Kees Cook <keescook@chromium.org>
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Changes in v2:
- prefer `strtomem_pad` over `strscpy` (thanks Kees)
- Link to v1: https://lore.kernel.org/r/20230822-strncpy-block-partitions-cmdline-ibm-v1-1-154dea8f755c@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..56c076c5523d 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);
+ strtomem_pad(type, label->vol.vollbl, 4);
+ strtomem_pad(name, label->vol.volid, 6);
} else {
- strncpy(type, label->lnx.vollbl, 4);
- strncpy(name, label->lnx.volid, 6);
+ strtomem_pad(type, label->lnx.vollbl, 4);
+ strtomem_pad(name, label->lnx.volid, 6);
}
EBCASC(type, 4);
EBCASC(name, 6);
---
base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230822-strncpy-block-partitions-cmdline-ibm-7f5bcca507ea
Best regards,
--
Justin Stitt <justinstitt@google.com>
next reply other threads:[~2023-08-23 21:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 21:24 Justin Stitt [this message]
2023-08-24 9:02 ` [PATCH v2] partitions/ibm: refactor deprecated strncpy Heiko Carstens
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=20230823-strncpy-block-partitions-cmdline-ibm-v2-1-40c77f7182fc@google.com \
--to=justinstitt@google.com \
--cc=axboe@kernel.dk \
--cc=hoeppner@linux.ibm.com \
--cc=keescook@chromium.org \
--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=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;
as well as URLs for NNTP newsgroup(s).