Replace strcpy with strncpy for copying the rpmsg
device name in rpmsg_register_device_override
Signed-off-by: Saud Farooqui <[email protected]>
---
drivers/rpmsg/rpmsg_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 290c1f02da10..d3b29c19715d 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -604,7 +604,7 @@ int rpmsg_register_device_override(struct rpmsg_device *rpdev,
int ret;
if (driver_override)
- strcpy(rpdev->id.name, driver_override);
+ strncpy(rpdev->id.name, driver_override, sizeof(rpdev->id.name));
dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
rpdev->id.name, rpdev->src, rpdev->dst);
--
2.25.1
Hi Saud,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on v5.19-rc1]
[also build test WARNING on next-20220609]
[cannot apply to remoteproc/rpmsg-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Saud-Farooqui/rpmsg-strcpy-is-not-safe-use-strncpy/20220609-024555
base: f2906aa863381afb0015a9eb7fefad885d4e5a56
config: sparc64-randconfig-r026-20220609 (https://download.01.org/0day-ci/archive/20220610/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b6e6a64ab89042911604aa4741584a422cdfe8a5
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Saud-Farooqui/rpmsg-strcpy-is-not-safe-use-strncpy/20220609-024555
git checkout b6e6a64ab89042911604aa4741584a422cdfe8a5
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=sparc64 SHELL=/bin/bash drivers/rpmsg/
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
drivers/rpmsg/rpmsg_core.c: In function 'rpmsg_register_device_override':
>> drivers/rpmsg/rpmsg_core.c:607:17: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
607 | strncpy(rpdev->id.name, driver_override, sizeof(rpdev->id.name));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/strncpy +607 drivers/rpmsg/rpmsg_core.c
595
596 /*
597 * A helper for registering rpmsg device with driver override and name.
598 * Drivers should not be using it, but instead rpmsg_register_device().
599 */
600 int rpmsg_register_device_override(struct rpmsg_device *rpdev,
601 const char *driver_override)
602 {
603 struct device *dev = &rpdev->dev;
604 int ret;
605
606 if (driver_override)
> 607 strncpy(rpdev->id.name, driver_override, sizeof(rpdev->id.name));
608
609 dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
610 rpdev->id.name, rpdev->src, rpdev->dst);
611
612 dev->bus = &rpmsg_bus;
613
614 device_initialize(dev);
615 if (driver_override) {
616 ret = driver_set_override(dev, &rpdev->driver_override,
617 driver_override,
618 strlen(driver_override));
619 if (ret) {
620 dev_err(dev, "device_set_override failed: %d\n", ret);
621 return ret;
622 }
623 }
624
625 ret = device_add(dev);
626 if (ret) {
627 dev_err(dev, "device_add failed: %d\n", ret);
628 kfree(rpdev->driver_override);
629 rpdev->driver_override = NULL;
630 put_device(dev);
631 }
632
633 return ret;
634 }
635 EXPORT_SYMBOL(rpmsg_register_device_override);
636
--
0-DAY CI Kernel Test Service
https://01.org/lkp
Hi Saud,
On Wed, Jun 08, 2022 at 11:43:30PM +0500, Saud Farooqui wrote:
> Replace strcpy with strncpy for copying the rpmsg
> device name in rpmsg_register_device_override
>
> Signed-off-by: Saud Farooqui <[email protected]>
> ---
> drivers/rpmsg/rpmsg_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 290c1f02da10..d3b29c19715d 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -604,7 +604,7 @@ int rpmsg_register_device_override(struct rpmsg_device *rpdev,
> int ret;
>
> if (driver_override)
> - strcpy(rpdev->id.name, driver_override);
> + strncpy(rpdev->id.name, driver_override, sizeof(rpdev->id.name));
Please use strscpy_pad() instead of strncpy().
Thanks,
Mathieu
>
> dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
> rpdev->id.name, rpdev->src, rpdev->dst);
> --
> 2.25.1
>
Replace strcpy() with strscpy_pad() for copying the rpmsg
device name in rpmsg_register_device_override().
Reported-by: kernel test robot <[email protected]>
Signed-off-by: Saud Farooqui <[email protected]>
---
drivers/rpmsg/rpmsg_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 290c1f02da10..a4bad4b00414 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -604,7 +604,7 @@ int rpmsg_register_device_override(struct rpmsg_device *rpdev,
int ret;
if (driver_override)
- strcpy(rpdev->id.name, driver_override);
+ strscpy_pad(rpdev->id.name, driver_override, RPMSG_NAME_SIZE);
dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
rpdev->id.name, rpdev->src, rpdev->dst);
--
2.25.1
On Thu, Jun 23, 2022 at 02:20:47PM +0500, Saud Farooqui wrote:
> Replace strcpy() with strscpy_pad() for copying the rpmsg
> device name in rpmsg_register_device_override().
>
> Reported-by: kernel test robot <[email protected]>
> Signed-off-by: Saud Farooqui <[email protected]>
> ---
> drivers/rpmsg/rpmsg_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 290c1f02da10..a4bad4b00414 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -604,7 +604,7 @@ int rpmsg_register_device_override(struct rpmsg_device *rpdev,
> int ret;
>
> if (driver_override)
> - strcpy(rpdev->id.name, driver_override);
> + strscpy_pad(rpdev->id.name, driver_override, RPMSG_NAME_SIZE);
Applied.
Thanks,
Mathieu
>
> dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
> rpdev->id.name, rpdev->src, rpdev->dst);
> --
> 2.25.1
>