Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Recognize the SuSE ABI note.



details:   https://anonhg.NetBSD.org/src/rev/25baeab10ec2
branches:  trunk
changeset: 779352:25baeab10ec2
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 22 02:40:05 2012 +0000

description:
- Recognize the SuSE ABI note.
- Restructure the code to do the checking in the appropriate note type,
and harmonize all the checks to be positive.
- Print only the tag data being careful not to overrun the allocated buffer.

diffstat:

 sys/kern/exec_elf.c |  69 +++++++++++++++++++++++++++++++---------------------
 sys/sys/exec_elf.h  |  27 ++++++++++++++++---
 2 files changed, 63 insertions(+), 33 deletions(-)

diffs (158 lines):

diff -r 5aabde3a64e9 -r 25baeab10ec2 sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c       Mon May 21 22:38:25 2012 +0000
+++ b/sys/kern/exec_elf.c       Tue May 22 02:40:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.c,v 1.38 2012/04/08 11:27:44 martin Exp $     */
+/*     $NetBSD: exec_elf.c,v 1.39 2012/05/22 02:40:05 christos Exp $   */
 
 /*-
  * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.38 2012/04/08 11:27:44 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.39 2012/05/22 02:40:05 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -891,15 +891,40 @@
                        continue;
 
                ndata = (char *)(np + 1);
+               unsigned int maxlen = (unsigned int)(shp->sh_size -
+                   ((char *)ndata - (char *)np));
+               if (maxlen < np->n_namesz)
+                       goto bad;
                switch (np->n_type) {
                case ELF_NOTE_TYPE_NETBSD_TAG:
-                       if (np->n_namesz != ELF_NOTE_NETBSD_NAMESZ ||
-                           np->n_descsz != ELF_NOTE_NETBSD_DESCSZ ||
+                       /*
+                        * It is us
+                        */
+                       if (np->n_namesz == ELF_NOTE_NETBSD_NAMESZ &&
+                           np->n_descsz == ELF_NOTE_NETBSD_DESCSZ &&
                            memcmp(ndata, ELF_NOTE_NETBSD_NAME,
-                           ELF_NOTE_NETBSD_NAMESZ))
-                               goto bad;
-                       isnetbsd = 1;
-                       break;
+                           ELF_NOTE_NETBSD_NAMESZ) == 0) {
+                               isnetbsd = 1;
+                               break;
+                       }
+                       /*
+                        * Ignore GNU tags
+                        */
+                       if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
+                           memcmp(ndata, ELF_NOTE_GNU_NAME,
+                           ELF_NOTE_GNU_NAMESZ) == 0)
+                               break;
+                       /*
+                        * Ignore SuSE tags
+                        */
+                       if (np->n_namesz == ELF_NOTE_SUSE_NAMESZ &&
+                           memcmp(ndata, ELF_NOTE_SUSE_NAME,
+                           ELF_NOTE_SUSE_NAMESZ) == 0)
+                               break;
+                       /*
+                        * Dunno, warn for diagnostic
+                        */
+                       goto bad;
 
                case ELF_NOTE_TYPE_PAX_TAG:
                        if (np->n_namesz != ELF_NOTE_PAX_NAMESZ ||
@@ -907,26 +932,14 @@
                            memcmp(ndata, ELF_NOTE_PAX_NAME,
                            ELF_NOTE_PAX_NAMESZ)) {
 bad:
-                           /*
-                            * Ignore GNU tags
-                            */
-                           if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
-                               memcmp(ndata, ELF_NOTE_GNU_NAME,
-                               ELF_NOTE_GNU_NAMESZ) == 0)
-                                       break;
 #ifdef DIAGNOSTIC
-                               printf("%s: bad tag %d: "
-                                   "[%d %d, %d %d, %*.*s %*.*s]\n",
-                                   epp->ep_kname,
-                                   np->n_type,
-                                   np->n_namesz, ELF_NOTE_PAX_NAMESZ,
-                                   np->n_descsz, ELF_NOTE_PAX_DESCSZ,
-                                   ELF_NOTE_PAX_NAMESZ,
-                                   ELF_NOTE_PAX_NAMESZ,
-                                   ndata,
-                                   ELF_NOTE_PAX_NAMESZ,
-                                   ELF_NOTE_PAX_NAMESZ,
-                                   ELF_NOTE_PAX_NAME);
+                       {
+                               int ns = MIN(np->n_namesz, maxlen);
+                               printf("%s: Unknown elf note type %d: "
+                                   "[namesz=%d, descsz=%d name=%*.*s]\n",
+                                   epp->ep_kname, np->n_type, np->n_namesz,
+                                   np->n_descsz, ns, ns, ndata);
+                       }
 #endif
                                continue;
                        }
@@ -935,7 +948,7 @@
                            sizeof(epp->ep_pax_flags));
                        break;
 
-               case ELF_NOTE_TYPE_SUSE_TAG:
+               case ELF_NOTE_TYPE_SUSE_VERSION_TAG:
                        break;
 
                default:
diff -r 5aabde3a64e9 -r 25baeab10ec2 sys/sys/exec_elf.h
--- a/sys/sys/exec_elf.h        Mon May 21 22:38:25 2012 +0000
+++ b/sys/sys/exec_elf.h        Tue May 22 02:40:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.h,v 1.122 2012/02/04 18:12:02 joerg Exp $     */
+/*     $NetBSD: exec_elf.h,v 1.123 2012/05/22 02:40:06 christos Exp $  */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -805,6 +805,23 @@
  */
 #define ELF_NOTE_TYPE_GNU_BUILD_ID     3
 
+/* SuSE-specific note type: ABI
+ * name: SuSE\0
+ * namesz: 5
+ * desc:
+ *     half[0] = MMmm
+ *
+ *     M = product major version
+ *     m = product minor version
+ * descsz: 2
+ */
+#define ELF_NOTE_TYPE_SUSE_TAG 1
+/* SuSE-specific note name and description sizes */
+#define ELF_NOTE_SUSE_NAMESZ   5
+#define ELF_NOTE_SUSE_DESCSZ   2
+/* SuSE-specific note name */
+#define ELF_NOTE_SUSE_NAME             "SuSE\0"
+
 /* SuSE-specific note type: version
  * name: SuSE\0\0\0\0
  * namesz: 8
@@ -817,12 +834,12 @@
  *     m = product minor version
  * descsz: 8
  */
-#define ELF_NOTE_TYPE_SUSE_TAG         0x45537553      /* SuSE in LE */
+#define ELF_NOTE_TYPE_SUSE_VERSION_TAG 0x45537553      /* SuSE in LE */
 /* SuSE-specific note name and description sizes */
-#define ELF_NOTE_SUSE_NAMESZ           8
-#define ELF_NOTE_SUSE_DESCSZ           8
+#define ELF_NOTE_SUSE_VERSION_NAMESZ   8
+#define ELF_NOTE_SUSE_VERSION_DESCSZ   8
 /* SuSE-specific note name */
-#define ELF_NOTE_SUSE_NAME             "SuSE\0\0\0\0"
+#define ELF_NOTE_SUSE_VERSION_NAME             "SuSE\0\0\0\0"
 
 /* NetBSD-specific note type: Emulation name.
  * name: NetBSD\0\0



Home | Main Index | Thread Index | Old Index