Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: octeontx - use strscpy_pad in ucode_load_store
@ 2026-05-20 10:00 Thorsten Blum
  2026-05-20 13:36 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-05-20 10:00 UTC (permalink / raw)
  To: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	Thorsten Blum, Kees Cook
  Cc: linux-crypto, linux-kernel

Instead of zero-initializing the temporary buffer and then copying into
it with strscpy(), use strscpy_pad() to copy the string and zero-pad any
trailing bytes. Drop the explicit size argument to further simplify the
code since strscpy_pad() can determine it automatically when the
destination buffer has a fixed length.

Also use strscpy_pad() to check for string truncation instead of the
hard-coded OTX_CPT_UCODE_NAME_LENGTH.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c b/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
index e0f38d32bc93..205579a6ba2b 100644
--- a/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
+++ b/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
@@ -1318,7 +1318,7 @@ static ssize_t ucode_load_store(struct device *dev,
 {
 	struct otx_cpt_engines engs[OTX_CPT_MAX_ETYPES_PER_GRP] = { {0} };
 	char *ucode_filename[OTX_CPT_MAX_ETYPES_PER_GRP];
-	char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH] = { 0 };
+	char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH];
 	char *start, *val, *err_msg, *tmp;
 	struct otx_cpt_eng_grps *eng_grps;
 	int grp_idx = 0, ret = -EINVAL;
@@ -1326,12 +1326,11 @@ static ssize_t ucode_load_store(struct device *dev,
 	int del_grp_idx = -1;
 	int ucode_idx = 0;
 
-	if (count >= OTX_CPT_UCODE_NAME_LENGTH)
+	if (strscpy_pad(tmp_buf, buf) < 0)
 		return -EINVAL;
 
 	eng_grps = container_of(attr, struct otx_cpt_eng_grps, ucode_load_attr);
 	err_msg = "Invalid engine group format";
-	strscpy(tmp_buf, buf, OTX_CPT_UCODE_NAME_LENGTH);
 	start = tmp_buf;
 
 	has_se = has_ie = has_ae = false;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: octeontx - use strscpy_pad in ucode_load_store
  2026-05-20 10:00 [PATCH] crypto: octeontx - use strscpy_pad in ucode_load_store Thorsten Blum
@ 2026-05-20 13:36 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2026-05-20 13:36 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Srujana Challa, Bharat Bhushan, Herbert Xu, David S. Miller,
	Kees Cook, linux-crypto, linux-kernel

On Wed, 20 May 2026 12:00:30 +0200
Thorsten Blum <thorsten.blum@linux.dev> wrote:

> Instead of zero-initializing the temporary buffer and then copying into
> it with strscpy(), use strscpy_pad() to copy the string and zero-pad any
> trailing bytes. Drop the explicit size argument to further simplify the
> code since strscpy_pad() can determine it automatically when the
> destination buffer has a fixed length.
> 
> Also use strscpy_pad() to check for string truncation instead of the
> hard-coded OTX_CPT_UCODE_NAME_LENGTH.

This code is horrid :-)
It really ought to be possible to parse the string without taking a writeable
copy.
There is also the 'fun' that it is passed the length of the string - hopefully
it is '\0' terminated at the same length.

Then there is this beauty:
	if (strnstr(val, " ", strlen(val)))

-- David

> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c b/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
> index e0f38d32bc93..205579a6ba2b 100644
> --- a/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
> +++ b/drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c
> @@ -1318,7 +1318,7 @@ static ssize_t ucode_load_store(struct device *dev,
>  {
>  	struct otx_cpt_engines engs[OTX_CPT_MAX_ETYPES_PER_GRP] = { {0} };
>  	char *ucode_filename[OTX_CPT_MAX_ETYPES_PER_GRP];
> -	char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH] = { 0 };
> +	char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH];
>  	char *start, *val, *err_msg, *tmp;
>  	struct otx_cpt_eng_grps *eng_grps;
>  	int grp_idx = 0, ret = -EINVAL;
> @@ -1326,12 +1326,11 @@ static ssize_t ucode_load_store(struct device *dev,
>  	int del_grp_idx = -1;
>  	int ucode_idx = 0;
>  
> -	if (count >= OTX_CPT_UCODE_NAME_LENGTH)
> +	if (strscpy_pad(tmp_buf, buf) < 0)
>  		return -EINVAL;
>  
>  	eng_grps = container_of(attr, struct otx_cpt_eng_grps, ucode_load_attr);
>  	err_msg = "Invalid engine group format";
> -	strscpy(tmp_buf, buf, OTX_CPT_UCODE_NAME_LENGTH);
>  	start = tmp_buf;
>  
>  	has_se = has_ie = has_ae = false;
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-20 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20 10:00 [PATCH] crypto: octeontx - use strscpy_pad in ucode_load_store Thorsten Blum
2026-05-20 13:36 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox