Patch "accel/ivpu: refactor deprecated strncpy" has been added to the 6.5-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    accel/ivpu: refactor deprecated strncpy

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     accel-ivpu-refactor-deprecated-strncpy.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6a989b30d8c170fc2dfbc4e03f883768d4c059ba
Author: Justin Stitt <justinstitt@xxxxxxxxxx>
Date:   Thu Aug 24 21:20:25 2023 +0000

    accel/ivpu: refactor deprecated strncpy
    
    [ Upstream commit 4b2fd81f2af7147e844ecec0c5c07a16bca6b86e ]
    
    `strncpy` is deprecated for use on NUL-terminated destination strings [1].
    
    A suitable replacement is `strscpy` [2] due to the fact that it
    guarantees NUL-termination on its destination buffer argument which is
    _not_ the case for `strncpy`!
    
    Also remove extraneous if-statement as it can never be entered. The
    return value from `strncpy` is it's first argument. In this case,
    `...dyndbg_cmd` is an array:
    |       char dyndbg_cmd[VPU_DYNDBG_CMD_MAX_LEN];
                 ^^^^^^^^^^
    This can never be NULL which means `strncpy`'s return value cannot be
    NULL here. Just use `strscpy` which is more robust and results in
    simpler and less ambiguous code.
    
    Moreover, remove needless `... - 1` as `strscpy`'s implementation
    ensures NUL-termination and we do not need to carefully dance around
    ending boundaries with a "- 1" anymore.
    
    Fixes: 5d7422cfb498 ("accel/ivpu: Add IPC driver and JSM messages")
    Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
    Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
    Link: https://github.com/KSPP/linux/issues/90
    Cc: linux-hardening@xxxxxxxxxxxxxxx
    Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
    Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@xxxxxxxxxxxxxxx>
    Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@xxxxxxxxxxxxxxx>
    Link: https://patchwork.freedesktop.org/patch/msgid/20230824-strncpy-drivers-accel-ivpu-ivpu_jsm_msg-c-v1-1-12d9b52d2dff@xxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/accel/ivpu/ivpu_jsm_msg.c b/drivers/accel/ivpu/ivpu_jsm_msg.c
index 831bfd2b2d39d..bdddef2c59eec 100644
--- a/drivers/accel/ivpu/ivpu_jsm_msg.c
+++ b/drivers/accel/ivpu/ivpu_jsm_msg.c
@@ -118,8 +118,7 @@ int ivpu_jsm_dyndbg_control(struct ivpu_device *vdev, char *command, size_t size
 	struct vpu_jsm_msg resp;
 	int ret;
 
-	if (!strncpy(req.payload.dyndbg_control.dyndbg_cmd, command, VPU_DYNDBG_CMD_MAX_LEN - 1))
-		return -ENOMEM;
+	strscpy(req.payload.dyndbg_control.dyndbg_cmd, command, VPU_DYNDBG_CMD_MAX_LEN);
 
 	ret = ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_DYNDBG_CONTROL_RSP, &resp,
 				    VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux