linux-m68k.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] m68k: apollo: replace strcpy() with strscpy()
@ 2025-05-14  5:23 Siddarth Gundu
  2025-05-14  7:10 ` Geert Uytterhoeven
  2025-05-20 11:38 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Siddarth Gundu @ 2025-05-14  5:23 UTC (permalink / raw)
  To: geert; +Cc: linux-m68k, linux-kernel, Siddarth Gundu

strcpy() is deprecated; use strscpy() instead.

strscpy was chosen because the code expects a NUL-terminated string
without zero-padding.

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>
---
 arch/m68k/apollo/config.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index e161ecd76035..d4cc145e1611 100644
--- a/arch/m68k/apollo/config.c
+++ b/arch/m68k/apollo/config.c
@@ -7,6 +7,7 @@
 #include <linux/rtc.h>
 #include <linux/vt_kern.h>
 #include <linux/interrupt.h>
+#include <linux/string.h>
 
 #include <asm/setup.h>
 #include <asm/bootinfo.h>
@@ -218,7 +219,7 @@ static void dn_dummy_reset(void)
 
 static void dn_get_model(char *model)
 {
-    strcpy(model, "Apollo ");
+    strscpy(model, "Apollo ");
     if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
         strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] m68k: apollo: replace strcpy() with strscpy()
  2025-05-14  5:23 [PATCH] m68k: apollo: replace strcpy() with strscpy() Siddarth Gundu
@ 2025-05-14  7:10 ` Geert Uytterhoeven
  2025-05-20 11:38 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2025-05-14  7:10 UTC (permalink / raw)
  To: Siddarth Gundu; +Cc: linux-m68k, linux-kernel

Hi Siddarth,

Thanks for your patch!

On Wed, 14 May 2025 at 07:23, Siddarth Gundu <siddarthsgml@gmail.com> wrote:
> strcpy() is deprecated; use strscpy() instead.
>
> strscpy was chosen because the code expects a NUL-terminated string
> without zero-padding.

... which are not sufficient reasons: there is no size information
about the destination buffer.

> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Siddarth Gundu <siddarthsgml@gmail.com>

> --- a/arch/m68k/apollo/config.c
> +++ b/arch/m68k/apollo/config.c
> @@ -218,7 +219,7 @@ static void dn_dummy_reset(void)
>
>  static void dn_get_model(char *model)
>  {
> -    strcpy(model, "Apollo ");
> +    strscpy(model, "Apollo ");

include/linux/compiler.h:197:62: error: static assertion failed: "must be array"
[...]
arch/m68k/apollo/config.c:222:5: note: in expansion of macro ‘strscpy’
  222 |     strscpy(model, "Apollo ");
      |     ^~~~~~~

Please try to (at least) test-compile your patches before submitting.

>      if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
>          strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);

FWIW, if the strscpy() would have prevented a buffer overflow, the
strcat() would still cause one.  But none of these can happen for real.
>  }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] m68k: apollo: replace strcpy() with strscpy()
  2025-05-14  5:23 [PATCH] m68k: apollo: replace strcpy() with strscpy() Siddarth Gundu
  2025-05-14  7:10 ` Geert Uytterhoeven
@ 2025-05-20 11:38 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2025-05-20 11:38 UTC (permalink / raw)
  To: Siddarth Gundu, geert
  Cc: oe-kbuild-all, linux-m68k, linux-kernel, Siddarth Gundu

Hi Siddarth,

kernel test robot noticed the following build errors:

[auto build test ERROR on geert-m68k/for-next]
[also build test ERROR on geert-m68k/for-linus gerg-m68knommu/for-next linus/master v6.15-rc7 next-20250516]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Siddarth-Gundu/m68k-apollo-replace-strcpy-with-strscpy/20250514-132427
base:   https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link:    https://lore.kernel.org/r/20250514052327.96537-1-siddarthsgml%40gmail.com
patch subject: [PATCH] m68k: apollo: replace strcpy() with strscpy()
config: m68k-defconfig (https://download.01.org/0day-ci/archive/20250520/202505201919.YX6T8TcK-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250520/202505201919.YX6T8TcK-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505201919.YX6T8TcK-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/build_bug.h:5,
                    from include/linux/init.h:5,
                    from arch/m68k/apollo/config.c:2:
   arch/m68k/apollo/config.c: In function 'dn_get_model':
>> include/linux/compiler.h:197:62: error: static assertion failed: "must be array"
     197 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                              ^~~~~~~~~~~~~~
   include/linux/compiler.h:202:33: note: in expansion of macro '__BUILD_BUG_ON_ZERO_MSG'
     202 | #define __must_be_array(a)      __BUILD_BUG_ON_ZERO_MSG(!__is_array(a), \
         |                                 ^~~~~~~~~~~~~~~~~~~~~~~
   include/linux/string.h:80:47: note: in expansion of macro '__must_be_array'
      80 |         sized_strscpy(dst, src, sizeof(dst) + __must_be_array(dst) +    \
         |                                               ^~~~~~~~~~~~~~~
   include/linux/args.h:25:24: note: in expansion of macro '__strscpy0'
      25 | #define __CONCAT(a, b) a ## b
         |                        ^
   include/linux/args.h:26:27: note: in expansion of macro '__CONCAT'
      26 | #define CONCATENATE(a, b) __CONCAT(a, b)
         |                           ^~~~~~~~
   include/linux/string.h:114:9: note: in expansion of macro 'CONCATENATE'
     114 |         CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
         |         ^~~~~~~~~~~
   arch/m68k/apollo/config.c:222:5: note: in expansion of macro 'strscpy'
     222 |     strscpy(model, "Apollo ");
         |     ^~~~~~~


vim +197 include/linux/compiler.h

230fa253df6352a Christian Borntraeger 2014-11-25  193  
cb7380de9e4cbc9 Kees Cook             2025-02-05  194  #ifdef __CHECKER__
cb7380de9e4cbc9 Kees Cook             2025-02-05  195  #define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0)
cb7380de9e4cbc9 Kees Cook             2025-02-05  196  #else /* __CHECKER__ */
cb7380de9e4cbc9 Kees Cook             2025-02-05 @197  #define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
cb7380de9e4cbc9 Kees Cook             2025-02-05  198  #endif /* __CHECKER__ */
cb7380de9e4cbc9 Kees Cook             2025-02-05  199  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-20 11:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14  5:23 [PATCH] m68k: apollo: replace strcpy() with strscpy() Siddarth Gundu
2025-05-14  7:10 ` Geert Uytterhoeven
2025-05-20 11:38 ` kernel test robot

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).