linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmod/depmod: explicitly include the header for basename()
@ 2024-04-08 20:22 Laurent Bercot
  2024-04-09 15:03 ` Lucas De Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Laurent Bercot @ 2024-04-08 20:22 UTC (permalink / raw)
  To: linux-modules

  Hello list,

(Please Cc: me on the replies.)

  Recent versions of the musl libc declare basename() (and dirname())
exclusively in <libgen.h>, as specified by POSIX. If this header is
not properly included, when building kmod with musl, basename() is an
unknown symbol and will be assumed as returning int, which causes
problems as soon as kmod performs a printf("%s", basename(argv[0])),
e.g. in kmod_help(). (On x86_64, int is 32 bit, so the pointer address
is truncated, which causes a segfault on access.)

  Simply including libgen.h wherever basename() is used, i.e. depmod.c
and kmod.c, fixes the issue. It will print warnings because you store
the result in a const char *, but these are harmless and can be fixed
later.

  None of the kmod files seems to use dirname(), but several of them use
dirname as a symbol, including depmod.c, where it will shadow the libc's
dirname symbol. This does not cause a problem right now, but it might be
a good idea to rename the dirname variables at some point.


diff -rNU3 kmod-32.old/tools/depmod.c kmod-32/tools/depmod.c
--- kmod-32.old/tools/depmod.c  2023-12-06 16:34:31.000000000 +0100
+++ kmod-32/tools/depmod.c      2024-04-08 20:55:03.998592078 +0200
@@ -22,6 +22,7 @@
  #include <dirent.h>
  #include <errno.h>
  #include <getopt.h>
+#include <libgen.h>
  #include <limits.h>
  #include <regex.h>
  #include <stdio.h>
diff -rNU3 kmod-32.old/tools/kmod.c kmod-32/tools/kmod.c
--- kmod-32.old/tools/kmod.c    2024-02-20 23:10:55.000000000 +0100
+++ kmod-32/tools/kmod.c        2024-04-08 21:55:03.888577992 +0200
@@ -19,6 +19,7 @@

  #include <errno.h>
  #include <getopt.h>
+#include <libgen.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>


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

end of thread, other threads:[~2024-04-10 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 20:22 [PATCH] kmod/depmod: explicitly include the header for basename() Laurent Bercot
2024-04-09 15:03 ` Lucas De Marchi
2024-04-09 16:16   ` Laurent Bercot
2024-04-10 18:51     ` Lucas De Marchi

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