crypto: octeontx: Fix length check to avoid truncation in ucode_load_store
Subsystems (3)
PATCH 1/1 crypto: octeontx: Fix length check to avoid truncation in ucode_load_store
OTX_CPT_UCODE_NAME_LENGTH limits the microcode name to 64 bytes. If a user writes a string of exactly 64 characters, the original code used 'strlen(buf) > 64' to check the length, but then strscpy() copies only 63 characters before adding a NUL terminator, silently truncating the copied string.
Fix this off-by-one error by using 'count' directly for the length check to ensure long names are rejected early and copied without truncation.
--- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c +1 -1
@@ -1326,7 +1326,7 @@ static ssize_t ucode_load_store(struct device *dev,int del_grp_idx =-1 ;int ucode_idx =0 ; -if (strlen (buf) >OTX_CPT_UCODE_NAME_LENGTH ) +if (count >=OTX_CPT_UCODE_NAME_LENGTH )return -EINVAL ; eng_grps = container_of(attr, struct otx_cpt_eng_grps, ucode_load_attr);
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Herbert Xu
maintainerQuoted 9 lines · Thorsten Blum
OTX_CPT_UCODE_NAME_LENGTHlimits the microcode name to 64 bytes. If a user writes a string of exactly 64 characters, the original code used 'strlen(buf) > 64' to check the length, but thenstrscpy()copies only 63 characters before adding a NUL terminator, silently truncating the copied string.Fix this off-by-one error by using 'count' directly for the length check to ensure long names are rejected early and copied without truncation.
Quoted 6 lines
Fixes d9110b0b01ff ("crypto: marvell - add support for OCTEON TX CPT engine")Signed-off-by Thorsten Blum <[email protected]>--- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt