* [PATCH] rpmsg: strcpy is not safe, use strncpy
@ 2022-06-08 18:43 Saud Farooqui
2022-06-09 21:08 ` kernel test robot
2022-06-22 17:46 ` Mathieu Poirier
0 siblings, 2 replies; 5+ messages in thread
From: Saud Farooqui @ 2022-06-08 18:43 UTC (permalink / raw)
To: bjorn.andersson, mathieu.poirier, linux-remoteproc, linux-kernel
Cc: Saud Farooqui
Replace strcpy with strncpy for copying the rpmsg
device name in rpmsg_register_device_override
Signed-off-by: Saud Farooqui <farooqui_saud@hotmail.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] rpmsg: strcpy is not safe, use strncpy
2022-06-08 18:43 [PATCH] rpmsg: strcpy is not safe, use strncpy Saud Farooqui
@ 2022-06-09 21:08 ` kernel test robot
2022-06-22 17:46 ` Mathieu Poirier
1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-06-09 21:08 UTC (permalink / raw)
To: Saud Farooqui, bjorn.andersson, mathieu.poirier,
linux-remoteproc, linux-kernel
Cc: kbuild-all, Saud Farooqui
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/202206100428.A3CCM24E-lkp@intel.com/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 <lkp@intel.com>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rpmsg: strcpy is not safe, use strncpy
2022-06-08 18:43 [PATCH] rpmsg: strcpy is not safe, use strncpy Saud Farooqui
2022-06-09 21:08 ` kernel test robot
@ 2022-06-22 17:46 ` Mathieu Poirier
2022-06-23 9:20 ` [PATCH v1] rpmsg: strcpy is not safe, use strscpy_pad() instead Saud Farooqui
1 sibling, 1 reply; 5+ messages in thread
From: Mathieu Poirier @ 2022-06-22 17:46 UTC (permalink / raw)
To: Saud Farooqui; +Cc: bjorn.andersson, linux-remoteproc, linux-kernel
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 <farooqui_saud@hotmail.com>
> ---
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1] rpmsg: strcpy is not safe, use strscpy_pad() instead
2022-06-22 17:46 ` Mathieu Poirier
@ 2022-06-23 9:20 ` Saud Farooqui
2022-06-24 17:38 ` Mathieu Poirier
0 siblings, 1 reply; 5+ messages in thread
From: Saud Farooqui @ 2022-06-23 9:20 UTC (permalink / raw)
To: mathieu.poirier
Cc: bjorn.andersson, linux-remoteproc, linux-kernel, lkp, Saud Farooqui
Replace strcpy() with strscpy_pad() for copying the rpmsg
device name in rpmsg_register_device_override().
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Saud Farooqui <farooqui_saud@hotmail.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] rpmsg: strcpy is not safe, use strscpy_pad() instead
2022-06-23 9:20 ` [PATCH v1] rpmsg: strcpy is not safe, use strscpy_pad() instead Saud Farooqui
@ 2022-06-24 17:38 ` Mathieu Poirier
0 siblings, 0 replies; 5+ messages in thread
From: Mathieu Poirier @ 2022-06-24 17:38 UTC (permalink / raw)
To: Saud Farooqui; +Cc: bjorn.andersson, linux-remoteproc, linux-kernel, lkp
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 <lkp@intel.com>
> Signed-off-by: Saud Farooqui <farooqui_saud@hotmail.com>
> ---
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-24 17:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 18:43 [PATCH] rpmsg: strcpy is not safe, use strncpy Saud Farooqui
2022-06-09 21:08 ` kernel test robot
2022-06-22 17:46 ` Mathieu Poirier
2022-06-23 9:20 ` [PATCH v1] rpmsg: strcpy is not safe, use strscpy_pad() instead Saud Farooqui
2022-06-24 17:38 ` Mathieu Poirier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).