unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Florian Weimer (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>
Subject: [review] Avoid zero-length array at the end of struct link_map [BZ #25097]
Date: Sun, 3 Nov 2019 12:11:46 -0500	[thread overview]
Message-ID: <gerrit.1572801105000.Ic911100730f9124d4ea977ead8e13cee64b84d45@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: gerrit.1572801105000.Ic911100730f9124d4ea977ead8e13cee64b84d45@gnutoolchain-gerrit.osci.io

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/488
......................................................................

Avoid zero-length array at the end of struct link_map [BZ #25097]

l_audit ends up as an internal array with _rtld_global, and GCC 10
warns about this.

This commit does not change the layout of _rtld_global, so it is
suitable for backporting.  Future changes could allocate more of the
audit state dynamically and remove it from always-allocated data
structures, to optimize the common case of inactive auditing.

Change-Id: Ic911100730f9124d4ea977ead8e13cee64b84d45
---
M include/link.h
M sysdeps/generic/ldsodefs.h
2 files changed, 23 insertions(+), 12 deletions(-)



diff --git a/include/link.h b/include/link.h
index 1184201..be52b97 100644
--- a/include/link.h
+++ b/include/link.h
@@ -325,16 +325,18 @@
     size_t l_relro_size;
 
     unsigned long long int l_serial;
-
-    /* Audit information.  This array apparent must be the last in the
-       structure.  Never add something after it.  */
-    struct auditstate
-    {
-      uintptr_t cookie;
-      unsigned int bindflags;
-    } l_audit[0];
   };
 
+/* Information used by audit modules.  For most link maps, this data
+   immediate follows the link map in memory.  For the dynamic linker,
+   it is allocated separately.  See link_map_audit_state in
+   <ldsodefs.h>.  */
+struct auditstate
+{
+  uintptr_t cookie;
+  unsigned int bindflags;
+};
+
 
 #if __ELF_NATIVE_CLASS == 32
 # define symbind symbind32
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 04b6d17..eb6cbea 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -379,11 +379,12 @@
   /* List of search directories.  */
   EXTERN struct r_search_path_elem *_dl_all_dirs;
 
-  /* Structure describing the dynamic linker itself.  We need to
-     reserve memory for the data the audit libraries need.  */
+  /* Structure describing the dynamic linker itself.  */
   EXTERN struct link_map _dl_rtld_map;
 #ifdef SHARED
-  struct auditstate audit_data[DL_NNS];
+  /* Used to store the audit information for the link map of the
+     dynamic loader.  */
+  struct auditstate _dl_rtld_auditstate[DL_NNS];
 #endif
 
 #if defined SHARED && defined _LIBC_REENTRANT \
@@ -1178,7 +1179,15 @@
 static inline struct auditstate *
 link_map_audit_state (struct link_map *l, size_t index)
 {
-  return &l->l_audit[index];
+  if (l == &GL (dl_rtld_map))
+    /* The auditstate array is stored separately.  */
+    return &GL (dl_rtld_auditstate) [index];
+  else
+    {
+      /* The auditstate array follows the link map in memory.  */
+      struct auditstate *base = (struct auditstate *) (l + 1);
+      return &base[index];
+    }
 }
 #endif /* SHARED */
 

-- 
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: Ic911100730f9124d4ea977ead8e13cee64b84d45
Gerrit-Change-Number: 488
Gerrit-PatchSet: 1
Gerrit-Owner: Florian Weimer <fweimer@redhat.com>
Gerrit-MessageType: newchange

       reply	other threads:[~2019-11-03 17:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-03 17:11 Florian Weimer (Code Review) [this message]
2019-11-03 17:44 ` [review] Avoid zero-length array at the end of struct link_map [BZ #25097] Jeff Law
2019-11-03 21:19 ` Carlos O'Donell (Code Review)
2019-11-03 21:23   ` Carlos O'Donell
2019-11-14 14:59 ` Carlos O'Donell (Code Review)
2019-11-15 12:30 ` [pushed] " Sourceware to Gerrit sync (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gerrit.1572801105000.Ic911100730f9124d4ea977ead8e13cee64b84d45@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).