All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] tools: include: add proper strscpy() declaration
@ 2026-05-11  0:23 kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2026-05-11  0:23 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20260504212301.63750-1-lucasp.linux@gmail.com>
References: <20260504212301.63750-1-lucasp.linux@gmail.com>
TO: Lucas Poupeau <lucasp.linux@gmail.com>
TO: jpoimboe@kernel.org
TO: pmladek@suse.com
CC: m32285159@gmail.com
CC: linux-kernel@vger.kernel.org
CC: Lucas Poupeau <lucasp.linux@gmail.com>

Hi Lucas,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.16-rc1 next-20260508]
[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/Lucas-Poupeau/tools-include-add-proper-strscpy-declaration/20260511-022707
base:   linus/master
patch link:    https://lore.kernel.org/r/20260504212301.63750-1-lucasp.linux%40gmail.com
patch subject: [PATCH] tools: include: add proper strscpy() declaration
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
config: x86_64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260511/202605110223.Yionans2-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260511/202605110223.Yionans2-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/r/202605110223.Yionans2-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from ./linux/scatterlist.h:5,
                    from scatterlist.c:9:
>> ../../include/linux/string.h:32:8: error: unknown type name 'ssize_t'; did you mean 'size_t'?
      32 | extern ssize_t strscpy(char *dest, const char *src, size_t count);
         |        ^~~~~~~
         |        size_t
   In file included from ./linux/scatterlist.h:7:
   ../../include/linux/bug.h:9:9: warning: "BUILD_BUG_ON_ZERO" redefined
       9 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
         |         ^~~~~~~~~~~~~~~~~
   In file included from ../../include/linux/bits.h:30,
                    from ../../include/linux/gfp_types.h:5,
                    from ../../include/linux/gfp.h:6,
                    from ../../include/linux/slab.h:6,
                    from scatterlist.c:8:
   ../../include/linux/build_bug.h:16:9: note: this is the location of the previous definition
      16 | #define BUILD_BUG_ON_ZERO(e, ...) \
         |         ^~~~~~~~~~~~~~~~~
   In file included from ./linux/scatterlist.h:8:
   ./linux/mm.h:13:9: warning: "unlikely" redefined
      13 | #define unlikely
         |         ^~~~~~~~
   In file included from ../../include/linux/build_bug.h:5:
   ../../include/linux/compiler.h:154:10: note: this is the location of the previous definition
     154 | # define unlikely(x)            __builtin_expect(!!(x), 0)
         |          ^~~~~~~~
   ./linux/mm.h:33:9: warning: "__ALIGN_KERNEL" redefined
      33 | #define __ALIGN_KERNEL(x, a)            __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
         |         ^~~~~~~~~~~~~~
   In file included from ../../include/vdso/const.h:5,
                    from ../../include/vdso/bits.h:5,
                    from ../../include/linux/bits.h:5:
   ../../include/uapi/linux/const.h:48:9: note: this is the location of the previous definition
      48 | #define __ALIGN_KERNEL(x, a)            __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
         |         ^~~~~~~~~~~~~~
   ./linux/mm.h:62:9: warning: "__PASTE" redefined
      62 | #define __PASTE(a,b) ___PASTE(a,b)
         |         ^~~~~~~
   ../../include/linux/compiler.h:243:9: note: this is the location of the previous definition
     243 | #define __PASTE(a, b) ___PASTE(a, b)
         |         ^~~~~~~
   ./linux/mm.h:112:21: error: conflicting types for 'kmalloc'; have 'void *(unsigned int,  unsigned int)'
     112 | static inline void *kmalloc(unsigned int size, unsigned int flags)
         |                     ^~~~~~~
   ../../include/linux/slab.h:33:7: note: previous declaration of 'kmalloc' with type 'void *(size_t,  gfp_t)' {aka 'void *(long unsigned int,  gfp_t)'}
      33 | void *kmalloc(size_t size, gfp_t gfp);
         |       ^~~~~~~
   ./linux/mm.h:118:1: error: conflicting types for 'kmalloc_array'; have 'void *(unsigned int,  unsigned int,  unsigned int)'
     118 | kmalloc_array(unsigned int n, unsigned int size, unsigned int flags)
         | ^~~~~~~~~~~~~
   ../../include/linux/slab.h:35:7: note: previous declaration of 'kmalloc_array' with type 'void *(size_t,  size_t,  gfp_t)' {aka 'void *(long unsigned int,  long unsigned int,  gfp_t)'}
      35 | void *kmalloc_array(size_t n, size_t size, gfp_t gfp);
         |       ^~~~~~~~~~~~~
   ./linux/scatterlist.h: In function 'sg_set_page':
   ./linux/scatterlist.h:161:9: error: implicit declaration of function 'VM_WARN_ON_ONCE'; did you mean 'WARN_ON_ONCE'? [-Wimplicit-function-declaration]
     161 |         VM_WARN_ON_ONCE(!page_range_contiguous(page, ALIGN(len + offset, PAGE_SIZE) / PAGE_SIZE));
         |         ^~~~~~~~~~~~~~~
         |         WARN_ON_ONCE
   ./linux/scatterlist.h:161:26: error: implicit declaration of function 'page_range_contiguous' [-Wimplicit-function-declaration]
     161 |         VM_WARN_ON_ONCE(!page_range_contiguous(page, ALIGN(len + offset, PAGE_SIZE) / PAGE_SIZE));
         |                          ^~~~~~~~~~~~~~~~~~~~~
   ./linux/scatterlist.h: At top level:
   ./linux/scatterlist.h:181:64: warning: 'struct folio' declared inside parameter list will not be visible outside of this definition or declaration
     181 | static inline void sg_set_folio(struct scatterlist *sg, struct folio *folio,
         |                                                                ^~~~~
   ./linux/scatterlist.h: In function 'sg_set_folio':
   ./linux/scatterlist.h:186:34: error: invalid use of undefined type 'struct folio'
     186 |         sg_assign_page(sg, &folio->page);
         |                                  ^~
   ./linux/scatterlist.h: In function 'sg_page_iter_page':
   ./linux/scatterlist.h:606:35: error: invalid use of undefined type 'struct page'
     606 |         return sg_page(piter->sg) + piter->sg_pgoffset;
         |                                   ^
   scatterlist.c: At top level:
   scatterlist.c:12:10: fatal error: linux/bvec.h: No such file or directory
      12 | #include <linux/bvec.h>
         |          ^~~~~~~~~~~~~~
   compilation terminated.

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

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] tools: include: add proper strscpy() declaration
@ 2026-05-06 16:34 Lucas Poupeau
  2026-05-06 16:47 ` Maxwell Doose
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Lucas Poupeau @ 2026-05-06 16:34 UTC (permalink / raw)
  To: m32285159, richard.weiyang; +Cc: linux-kernel, Lucas Poupeau

Remove the macro hack and add a proper implementation in tools/lib/string.c.
This avoids unsafe strcpy usage when strscpy is expected and fixes
potential compilation warnings regarding str_error_r.

Fixes: 9e3d665 ("memblock test: fix implicit declaration of function 'strscpy'")
Suggested-by: Maxwell Doose <m32285159@gmail.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Lucas Poupeau <lucasp.linux@gmail.com>
---
 tools/include/linux/string.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 51ad3cf4fa82..d6e53109e786 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -12,7 +12,7 @@ void argv_free(char **argv);
 
 int strtobool(const char *s, bool *res);
 
-#define strscpy strcpy
+ssize_t strscpy(char *dest, const char *src, size_t count);
 
 /*
  * glibc based builds needs the extern while uClibc doesn't.
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH] tools: include: add proper strscpy() declaration
@ 2026-05-04 21:23 Lucas Poupeau
  2026-05-04 21:38 ` Maxwell Doose
  2026-05-10 23:26 ` kernel test robot
  0 siblings, 2 replies; 11+ messages in thread
From: Lucas Poupeau @ 2026-05-04 21:23 UTC (permalink / raw)
  To: jpoimboe, pmladek; +Cc: m32285159, linux-kernel, Lucas Poupeau

Currently, strscpy() is defined as a macro for strcpy() in the tools
headers. This is unsafe and prevents using the real strscpy() logic
that provides better buffer overflow protection.

Remove the macro hack and add a proper extern declaration for
strscpy(). This allows tools to use the safer string copying API
once the implementation is provided.

Suggested-by: Maxwell Doose <m32285159@gmail.com>
Signed-off-by: Lucas Poupeau <lucasp.linux@gmail.com>
---
 tools/include/linux/string.h |  5 ++++-
 tools/lib/string.c           | 37 ++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 51ad3cf4fa82..4f3547d0cd84 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -12,7 +12,6 @@ void argv_free(char **argv);
 
 int strtobool(const char *s, bool *res);
 
-#define strscpy strcpy
 
 /*
  * glibc based builds needs the extern while uClibc doesn't.
@@ -30,6 +29,10 @@ extern size_t strlcpy(char *dest, const char *src, size_t size);
 #endif
 #endif
 
+extern ssize_t strscpy(char *dest, const char *src, size_t count);
+
+char *str_error_r(int errnum, char *buf, size_t buflen);
+
 char *str_error_r(int errnum, char *buf, size_t buflen);
 
 char *strreplace(char *s, char old, char new);
diff --git a/tools/lib/string.c b/tools/lib/string.c
index 3126d2cff716..12fabbe583cf 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -36,6 +36,43 @@ void *memdup(const void *src, size_t len)
 	return p;
 }
 
+/**
+ * strscpy - Copy a C-string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @count: Size of destination buffer
+ *
+ * Copy the source string to the destination buffer. The result is
+ * always a valid NUL-terminated string that fits in the buffer.
+ *
+ * Return:
+ * * The number of characters copied (not including the trailing NUL)
+ * * -E2BIG if count is 0 or @src was truncated.
+ */
+ssize_t strscpy(char *dest, const char *src, size_t count)
+{
+	size_t res = 0;
+
+	if (count == 0)
+		return -E2BIG;
+
+	while (count) {
+		char c = src[res];
+
+		dest[res] = c;
+		if (!c)
+			return res;
+		res++;
+		count--;
+	}
+
+	/* Hit buffer length without finding a NUL; force NUL-termination. */
+	if (res)
+		dest[res-1] = '\0';
+
+	return -E2BIG;
+}
+
 /**
  * strtobool - convert common user inputs into boolean values
  * @s: input string
-- 
2.54.0


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

end of thread, other threads:[~2026-05-11  7:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11  0:23 [PATCH] tools: include: add proper strscpy() declaration kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-05-06 16:34 Lucas Poupeau
2026-05-06 16:47 ` Maxwell Doose
2026-05-07  2:42 ` Wei Yang
2026-05-07  3:11   ` Maxwell Doose
2026-05-11  7:08 ` kernel test robot
2026-05-04 21:23 Lucas Poupeau
2026-05-04 21:38 ` Maxwell Doose
2026-05-04 21:47   ` Maxwell Doose
2026-05-06  4:21     ` Maxwell Doose
2026-05-10 23:26 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.