All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/build-id: Fix xen_build_id_check() to be robust against malformed notes
@ 2018-12-31 17:34 Andrew Cooper
  2019-01-02 10:38 ` Roger Pau Monné
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Andrew Cooper @ 2018-12-31 17:34 UTC (permalink / raw)
  To: Xen-devel
  Cc: Stefano Stabellini, Wei Liu, Andrew Cooper, Julien Grall,
	Jan Beulich, Roger Pau Monné

A NT_GNU_BUILD_ID with namesz longer than 4 will cause the strncmp() to use
bytes in adjacent stringtable entries.

Instead, check for namesz exactly equal to 4, and use memcmp() with an
explicit size.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien.grall@arm.com>

Noticed while auditing Xen's use of strncmp() for the command line patch.
---
 xen/common/version.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/common/version.c b/xen/common/version.c
index 223cb52..1df7e78 100644
--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -97,17 +97,17 @@ int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
     if ( NT_GNU_BUILD_ID != n->type )
         return -ENODATA;
 
-    if ( n->namesz + n->descsz < n->namesz )
+    if ( n->namesz != 4 /* GNU\0 */)
         return -EINVAL;
 
-    if ( n->namesz < 4 /* GNU\0 */)
+    if ( n->namesz + n->descsz < n->namesz )
         return -EINVAL;
 
     if ( n->namesz + n->descsz > n_sz - sizeof(*n) )
         return -EINVAL;
 
     /* Sanity check, name should be "GNU" for ld-generated build-id. */
-    if ( strncmp(ELFNOTE_NAME(n), "GNU", n->namesz) != 0 )
+    if ( memcmp(ELFNOTE_NAME(n), "GNU", 4) != 0 )
         return -ENODATA;
 
     if ( len )
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2019-01-08  8:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-31 17:34 [PATCH] xen/build-id: Fix xen_build_id_check() to be robust against malformed notes Andrew Cooper
2019-01-02 10:38 ` Roger Pau Monné
2019-01-02 10:43 ` Wei Liu
2019-01-02 12:01   ` Andrew Cooper
2019-01-07 10:33   ` Jan Beulich
2019-01-07 10:36 ` Jan Beulich
2019-01-07 17:34   ` Andrew Cooper
2019-01-08  8:44     ` Jan Beulich

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.