public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/fw/bug25097] Avoid zero-length array at the end of struct link_map [BZ #25097]
@ 2019-11-03 17:12 Florian Weimer
0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2019-11-03 17:12 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6a771621414cc85f218d6b13c204552afd0294c3
commit 6a771621414cc85f218d6b13c204552afd0294c3
Author: Florian Weimer <fweimer@redhat.com>
Date: Sun Nov 3 11:20:23 2019 +0100
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
Diff:
---
include/link.h | 18 ++++++++++--------
sysdeps/generic/ldsodefs.h | 17 +++++++++++++----
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 @@ struct link_map
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 @@ struct rtld_global
/* 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 @@ rtld_active (void)
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 */
^ permalink raw reply [flat|nested] 2+ messages in thread
* [glibc/fw/bug25097] Avoid zero-length array at the end of struct link_map [BZ #25097]
@ 2019-11-03 17:08 Florian Weimer
0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2019-11-03 17:08 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6d241445b417089ac7d26976f520f35d3442abc0
commit 6d241445b417089ac7d26976f520f35d3442abc0
Author: Florian Weimer <fweimer@redhat.com>
Date: Sun Nov 3 11:20:23 2019 +0100
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.
Diff:
---
include/link.h | 18 ++++++++++--------
sysdeps/generic/ldsodefs.h | 17 +++++++++++++----
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 @@ struct link_map
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 @@ struct rtld_global
/* 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 @@ rtld_active (void)
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 */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-03 17:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-03 17:12 [glibc/fw/bug25097] Avoid zero-length array at the end of struct link_map [BZ #25097] Florian Weimer
-- strict thread matches above, loose matches on Subject: below --
2019-11-03 17:08 Florian Weimer
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).