[PATCH] soc: fsl: qe: Replace all non-returning strlcpy with strscpy

Subsystems: freescale quicc engine library, freescale soc drivers, the rest

STALE1212d

2 messages, 1 author, 2023-05-30 · open the first message on its own page

[PATCH] soc: fsl: qe: Replace all non-returning strlcpy with strscpy

From: Azeem Shaikh <hidden>
Date: 2023-05-30 16:00:42

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().
No return values were used, so direct replacement is safe.

[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 <redacted>
---
 drivers/soc/fsl/qe/qe.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index b3c226eb5292..58746e570d14 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -524,7 +524,7 @@ int qe_upload_firmware(const struct qe_firmware *firmware)
 	 * saved microcode information and put in the new.
 	 */
 	memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
-	strlcpy(qe_firmware_info.id, firmware->id, sizeof(qe_firmware_info.id));
+	strscpy(qe_firmware_info.id, firmware->id, sizeof(qe_firmware_info.id));
 	qe_firmware_info.extended_modes = be64_to_cpu(firmware->extended_modes);
 	memcpy(qe_firmware_info.vtraps, firmware->vtraps,
 		sizeof(firmware->vtraps));
@@ -599,7 +599,7 @@ struct qe_firmware_info *qe_get_firmware_info(void)
 	/* Copy the data into qe_firmware_info*/
 	sprop = of_get_property(fw, "id", NULL);
 	if (sprop)
-		strlcpy(qe_firmware_info.id, sprop,
+		strscpy(qe_firmware_info.id, sprop,
 			sizeof(qe_firmware_info.id));
 
 	of_property_read_u64(fw, "extended-modes",

Re: [PATCH] soc: fsl: qe: Replace all non-returning strlcpy with strscpy

From: Azeem Shaikh <hidden>
Date: 2023-05-30 16:09:29

Duplicate of https://lore.kernel.org/all/20230523021425.2406309-1-azeemshaikh38@gmail.com/.
Sorry about that.

On Tue, May 30, 2023 at 12:00 PM Azeem Shaikh [off-list ref] wrote:
quoted hunk
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().
No return values were used, so direct replacement is safe.

[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 <redacted>
---
 drivers/soc/fsl/qe/qe.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index b3c226eb5292..58746e570d14 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -524,7 +524,7 @@ int qe_upload_firmware(const struct qe_firmware *firmware)
         * saved microcode information and put in the new.
         */
        memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
-       strlcpy(qe_firmware_info.id, firmware->id, sizeof(qe_firmware_info.id));
+       strscpy(qe_firmware_info.id, firmware->id, sizeof(qe_firmware_info.id));
        qe_firmware_info.extended_modes = be64_to_cpu(firmware->extended_modes);
        memcpy(qe_firmware_info.vtraps, firmware->vtraps,
                sizeof(firmware->vtraps));
@@ -599,7 +599,7 @@ struct qe_firmware_info *qe_get_firmware_info(void)
        /* Copy the data into qe_firmware_info*/
        sprop = of_get_property(fw, "id", NULL);
        if (sprop)
-               strlcpy(qe_firmware_info.id, sprop,
+               strscpy(qe_firmware_info.id, sprop,
                        sizeof(qe_firmware_info.id));

        of_property_read_u64(fw, "extended-modes",
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help