stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Azeem Shaikh <azeemshaikh38@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Sasha Levin <sashal@kernel.org>,
	davem@davemloft.net, linux-crypto@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 02/15] crypto: lrw,xts - Replace strlcpy with strscpy
Date: Fri,  8 Sep 2023 14:19:05 -0400	[thread overview]
Message-ID: <20230908181920.3460520-2-sashal@kernel.org> (raw)
In-Reply-To: <20230908181920.3460520-1-sashal@kernel.org>

From: Azeem Shaikh <azeemshaikh38@gmail.com>

[ Upstream commit babb80b3ecc6f40c962e13c654ebcd27f25ee327 ]

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().

Direct replacement is safe here since return value of -errno
is used to check for truncation instead of sizeof(dest).

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 crypto/lrw.c | 6 +++---
 crypto/xts.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/crypto/lrw.c b/crypto/lrw.c
index bcf09fbc750af..80d9076e42e0b 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -357,10 +357,10 @@ static int lrw_create(struct crypto_template *tmpl, struct rtattr **tb)
 	 * cipher name.
 	 */
 	if (!strncmp(cipher_name, "ecb(", 4)) {
-		unsigned len;
+		int len;
 
-		len = strlcpy(ecb_name, cipher_name + 4, sizeof(ecb_name));
-		if (len < 2 || len >= sizeof(ecb_name))
+		len = strscpy(ecb_name, cipher_name + 4, sizeof(ecb_name));
+		if (len < 2)
 			goto err_free_inst;
 
 		if (ecb_name[len - 1] != ')')
diff --git a/crypto/xts.c b/crypto/xts.c
index de6cbcf69bbd6..b05020657cdc8 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -396,10 +396,10 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)
 	 * cipher name.
 	 */
 	if (!strncmp(cipher_name, "ecb(", 4)) {
-		unsigned len;
+		int len;
 
-		len = strlcpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
-		if (len < 2 || len >= sizeof(ctx->name))
+		len = strscpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
+		if (len < 2)
 			goto err_free_inst;
 
 		if (ctx->name[len - 1] != ')')
-- 
2.40.1


  reply	other threads:[~2023-09-08 18:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 18:19 [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Sasha Levin
2023-09-08 18:19 ` Sasha Levin [this message]
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 03/15] wifi: ath9k: fix fortify warnings Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 04/15] wifi: ath9k: fix printk specifier Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 05/15] wifi: mwifiex: fix fortify warning Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 06/15] wifi: wil6210: fix fortify warnings Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 07/15] crypto: lib/mpi - avoid null pointer deref in mpi_cmp_ui() Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 08/15] tpm_tis: Resend command to recover from data transfer errors Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 09/15] mmc: sdhci-esdhc-imx: improve ESDHC_FLAG_ERR010450 Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 10/15] alx: fix OOB-read compiler warning Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 11/15] wifi: mac80211: check S1G action frame size Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 12/15] netfilter: ebtables: fix fortify warnings in size_entry_mwt() Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 13/15] wifi: mac80211_hwsim: drop short frames Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 14/15] libbpf: Free btf_vmlinux when closing bpf_object Sasha Levin
2023-09-08 18:19 ` [PATCH AUTOSEL 5.15 15/15] Bluetooth: btusb: Fix quirks table naming Sasha Levin
2023-09-08 21:44 ` [PATCH AUTOSEL 5.15 01/15] devlink: remove reload failed checks in params get/set callbacks Jacob Keller

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=20230908181920.3460520-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=azeemshaikh38@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=keescook@chromium.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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;
as well as URLs for NNTP newsgroup(s).