]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwfl: fix potential overflow when reporting on kernel modules
authorMatthias Maennich <maennich@google.com>
Thu, 18 Nov 2021 19:44:50 +0000 (19:44 +0000)
committerMark Wielaard <mark@klomp.org>
Sat, 20 Nov 2021 00:05:11 +0000 (01:05 +0100)
dwfl_linux_kernel_report_modules_ has an outstanding ancient bug when
reading kernel module information from a modules list file. The target
buffer for the module name was sized too small to hold potential values.
Fix that by increasing the value to account for the null termination.

In practice, this unlikely ever happened, but it now got diagnosed by
LLVM as part of a stricter -Wfortify-source implementation [1]:

libdwfl/linux-kernel-modules.c:1019:7: error: 'sscanf' may overflow; destination buffer in argument 3 has size 128, but the corresponding specifier may require size 129 [-Werror,-Wfortify-source]
                    modname, &modsz, &modaddr) == 3)

[1] https://github.com/llvm/llvm-project/commit/2db66f8d48beeea835cb9a6940e25bc04ab5d941

Suggested-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
libdwfl/ChangeLog
libdwfl/linux-kernel-modules.c

index f7e24a211de9ed65448abc02cf664d488baa9f3a..57b2c494c2208af3e39f2ffeeefc58cdda5a2705 100644 (file)
@@ -1,3 +1,8 @@
+2021-11-18  Matthias Maennich  <maennich@google.com>
+
+       * linux-kernel-modules.c (dwfl_linux_kernel_report_modules):
+       Add one to modname array size.
+
 2021-02-14  Alexander Miller  <alex.miller@gmx.de>
 
        * core-file.c (dwfl_core_file_report): Move NEW_VERSION before
index c0f8dfa4aef2cf5c2894993cf0755e4ff8c98857..58c0c417a59721d865cf88dfb9c4211df70a72e3 100644 (file)
@@ -1008,7 +1008,7 @@ dwfl_linux_kernel_report_modules (Dwfl *dwfl)
   int result = 0;
   Dwarf_Addr modaddr;
   unsigned long int modsz;
-  char modname[128];
+  char modname[128+1];
   char *line = NULL;
   size_t linesz = 0;
   /* We can't just use fscanf here because it's not easy to distinguish \n