Skip to contentSkip to conversation

increase AT_VECTOR_SIZE to terminate saved_auxv properly

PATCH In review Olaf Hering 3 participants 7 messages Sep 14, 2007 – Sep 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

include/asm-powerpc/elf.h has 6 entries in ARCH_DLINFO. fs/binfmt_elf.c has 14 unconditional NEW_AUX_ENT entries and 2 conditional NEW_AUX_ENT entries.
So in the worst case, saved_auxv does not get an AT_NULL entry at the end.

Is an AT_NULL entry required or must userspace use the AT_VECTOR_SIZE to not loop past the end of the array?
If AT_NULL is required, AT_VECTOR_SIZE should be changed from 44 to 46.

#1 lore raw
Quoted 8 lines · Olaf Hering

include/asm-powerpc/elf.h has 6 entries in ARCH_DLINFO. fs/binfmt_elf.c has 14 unconditional NEW_AUX_ENT entries and 2 conditional NEW_AUX_ENT entries.
So in the worst case, saved_auxv does not get an AT_NULL entry at the end.

Is an AT_NULL entry required or must userspace use the AT_VECTOR_SIZE to not loop past the end of the array?

Of course it is required, AT_VECTOR_SIZE is a kernel implementation detail.

Quoted 1 line

If AT_NULL is required, AT_VECTOR_SIZE should be changed from 44 to 46.

No, it should be computed instead from the number of target independent aux vector pairs and then from an per-arch macro which says how many arch specific aux vector pairs are needed.

Jakub

#2 lore raw
Quoted 5 lines · Jakub Jelinek
Quoted 1 line

If AT_NULL is required, AT_VECTOR_SIZE should be changed from 44 to 46.

No, it should be computed instead from the number of target independent aux vector pairs and then from an per-arch macro which says how many arch specific aux vector pairs are needed.

How should I define the arch specific part? ARCH_DLINFO is in asm/elf.h. I suspect that sched.h should not include elh.h.
What asm/xyz.h would be a good place for AT_VECTOR_SIZE_ARCH? The attempt below does currently not compile.

include/asm-powerpc/elf.h has 6 entries in ARCH_DLINFO. fs/binfmt_elf.c has 14 unconditional NEW_AUX_ENT entries and 2 conditional NEW_AUX_ENT entries.
So in the worst case, saved_auxv does not get an AT_NULL entry at the end.

The saved_auxv array must be terminated with an AT_NULL entry. Make the size of mm_struct->saved_auxv arch dependend, based on the number of ARCH_DLINFO entries.

---
 include/asm-alpha/elf.h   |    1 +
 include/asm-i386/elf.h    |    1 +
 include/asm-ia64/elf.h    |    1 +
 include/asm-powerpc/elf.h |    1 +
 include/asm-sh/elf.h      |    1 +
 include/linux/auxvec.h    |    4 +++-
 include/linux/elf.h       |    5 +++++
 include/linux/sched.h     |    1 -
 8 files changed, 13 insertions(+), 2 deletions(-)
include/asm-alpha/elf.h +1 -0
@@ -155,6 +155,7 @@ extern int alpha_l1d_cacheshape;
 extern int alpha_l2_cacheshape;
 extern int alpha_l3_cacheshape;
 
+#define AT_VECTOR_SIZE_ARCH 4
 #define ARCH_DLINFO						\
   do {								\
     NEW_AUX_ENT(AT_L1I_CACHESHAPE, alpha_l1i_cacheshape);	\
include/asm-i386/elf.h +1 -0
@@ -152,6 +152,7 @@ extern int arch_setup_additional_pages(s
 
 extern unsigned int vdso_enabled;
 
+#define AT_VECTOR_SIZE_ARCH 2
 #define ARCH_DLINFO							\
 do if (vdso_enabled) {							\
 		NEW_AUX_ENT(AT_SYSINFO,	VDSO_ENTRY);			\
include/asm-ia64/elf.h +1 -0
@@ -192,6 +192,7 @@ extern int dump_task_fpu (struct task_st
 
 #define GATE_EHDR	((const struct elfhdr *) GATE_ADDR)
 
+#define AT_VECTOR_SIZE_ARCH 2
 #define ARCH_DLINFO								\
 do {										\
 	extern char __kernel_syscall_via_epc[];					\
include/asm-powerpc/elf.h +1 -0
@@ -282,6 +282,7 @@ extern int arch_setup_additional_pages(s
  * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
  *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
  */
+#define AT_VECTOR_SIZE_ARCH 6
 #define ARCH_DLINFO							\
 do {									\
 	/* Handle glibc compatibility. */				\
include/asm-sh/elf.h +1 -0
@@ -133,6 +133,7 @@ extern void __kernel_vsyscall;
 #define VDSO_BASE		((unsigned long)current->mm->context.vdso)
 #define VDSO_SYM(x)		(VDSO_BASE + (unsigned long)(x))
 
+#define AT_VECTOR_SIZE_ARCH 1
 #define ARCH_DLINFO						\
 do {								\
 	if (vdso_enabled)					\
include/linux/auxvec.h +3 -1
@@ -26,6 +26,8 @@
 
 #define AT_SECURE 23   /* secure mode boolean */
 
-#define AT_VECTOR_SIZE  44 /* Size of auxiliary table.  */
+#ifdef __KERNEL__
+#define AT_VECTOR_SIZE_BASE  (14 + 2) /* generic entries in auxiliary table. */
+#endif
 
 #endif /* _LINUX_AUXVEC_H */
include/linux/elf.h +5 -0
@@ -6,6 +6,11 @@
 #include <linux/elf-em.h>
 #include <asm/elf.h>
 
+#ifndef AT_VECTOR_SIZE_ARCH
+#define AT_VECTOR_SIZE_ARCH 0
+#endif
+#define AT_VECTOR_SIZE (AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1)
+
 struct file;
 
 #ifndef elf_read_implies_exec
include/linux/sched.h +0 -1
@@ -1,7 +1,6 @@
 #ifndef _LINUX_SCHED_H
 #define _LINUX_SCHED_H
 
-#include <linux/auxvec.h>	/* For AT_VECTOR_SIZE */
 
 /*
  * cloning flags:
#3 lore raw

PATCH 1/1 increase AT_VECTOR_SIZE to terminate saved_auxv properly

In reply to Olaf Hering

include/asm-powerpc/elf.h has 6 entries in ARCH_DLINFO. fs/binfmt_elf.c has 14 unconditional NEW_AUX_ENT entries and 2 conditional NEW_AUX_ENT entries.
So in the worst case, saved_auxv does not get an AT_NULL entry at the end.

The saved_auxv array must be terminated with an AT_NULL entry. Make the size of mm_struct->saved_auxv arch dependend, based on the number of ARCH_DLINFO entries.

---
 include/asm-alpha/system.h   |    1 +
 include/asm-i386/system.h    |    1 +
 include/asm-ia64/system.h    |    2 ++
 include/asm-powerpc/system.h |    1 +
 include/asm-sh/system.h      |    1 +
 include/linux/auxvec.h       |    4 +++-
 include/linux/elf.h          |    1 -
 include/linux/sched.h        |    6 +++++-
 8 files changed, 14 insertions(+), 3 deletions(-)
include/asm-alpha/system.h +1 -0
@@ -48,6 +48,7 @@
 
 #ifndef __ASSEMBLY__
 #include <linux/kernel.h>
+#define AT_VECTOR_SIZE_ARCH 4
 
 /*
  * This is the logout header that should be common to all platforms
include/asm-i386/system.h +1 -0
@@ -7,6 +7,7 @@
 #include <asm/cmpxchg.h>
 
 #ifdef __KERNEL__
+#define AT_VECTOR_SIZE_ARCH 2
 
 struct task_struct;	/* one of the stranger aspects of C forward declarations.. */
 extern struct task_struct * FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));
include/asm-ia64/system.h +2 -0
@@ -32,6 +32,8 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 
+#define AT_VECTOR_SIZE_ARCH 2
+
 struct pci_vector_struct {
 	__u16 segment;	/* PCI Segment number */
 	__u16 bus;	/* PCI Bus number */
include/asm-powerpc/system.h +1 -0
@@ -40,6 +40,7 @@
 #define set_mb(var, value)	do { var = value; mb(); } while (0)
 
 #ifdef __KERNEL__
+#define AT_VECTOR_SIZE_ARCH 6
 #ifdef CONFIG_SMP
 #define smp_mb()	mb()
 #define smp_rmb()	rmb()
include/asm-sh/system.h +1 -0
@@ -11,6 +11,7 @@
 #include <asm/types.h>
 #include <asm/ptrace.h>
 
+#define AT_VECTOR_SIZE_ARCH 1
 /*
  *	switch_to() should switch tasks to task nr n, first
  */
include/linux/auxvec.h +3 -1
@@ -26,6 +26,8 @@
 
 #define AT_SECURE 23   /* secure mode boolean */
 
-#define AT_VECTOR_SIZE  44 /* Size of auxiliary table.  */
+#ifdef __KERNEL__
+#define AT_VECTOR_SIZE_BASE  (14 + 2) /* generic entries in auxiliary table. */
+#endif
 
 #endif /* _LINUX_AUXVEC_H */
include/linux/elf.h +0 -1
@@ -2,7 +2,6 @@
 #define _LINUX_ELF_H
 
 #include <linux/types.h>
-#include <linux/auxvec.h>
 #include <linux/elf-em.h>
 #include <asm/elf.h>
 
include/linux/sched.h +5 -1
@@ -1,7 +1,6 @@
 #ifndef _LINUX_SCHED_H
 #define _LINUX_SCHED_H
 
-#include <linux/auxvec.h>	/* For AT_VECTOR_SIZE */
 
 /*
  * cloning flags:
@@ -90,6 +89,11 @@ struct exec_domain;
 struct futex_pi_state;
 struct bio;
 
+#include <linux/auxvec.h>
+#ifndef AT_VECTOR_SIZE_ARCH
+#define AT_VECTOR_SIZE_ARCH 0
+#endif
+#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
 /*
  * List of flags we want to share for kernel threads,
  * if only because they are not used by them anyway.
#4 lore raw
Quoted 9 lines · On Tue, 18 Sep 2007 13:55:04 +0200 Olaf Hering <[email protected]> wrote:

include/asm-powerpc/elf.h has 6 entries in ARCH_DLINFO. fs/binfmt_elf.c has 14 unconditional NEW_AUX_ENT entries and 2 conditional NEW_AUX_ENT entries.
So in the worst case, saved_auxv does not get an AT_NULL entry at the end.

The saved_auxv array must be terminated with an AT_NULL entry. Make the size of mm_struct->saved_auxv arch dependend, based on the number of ARCH_DLINFO entries.

I'm not very confident that this will work well with the already-queued move-mm_struct-and-vm_area_struct.patch.

It moves the saved_auxv[AT_VECTOR_SIZE] definition over into mm_types.h and mm_types.h doesn't include sched.h.

#5 lore raw
Quoted 2 lines · Andrew Morton

I'm not very confident that this will work well with the already-queued move-mm_struct-and-vm_area_struct.patch.

You want me to redo my patch agains the current -mm kernel?

#6 lore raw
Quoted 6 lines · On Thu, 20 Sep 2007 21:19:44 +0200 Olaf Hering <[email protected]> wrote:
Quoted 2 lines · Andrew Morton

I'm not very confident that this will work well with the already-queued move-mm_struct-and-vm_area_struct.patch.

You want me to redo my patch agains the current -mm kernel?

Would be appreciated, thanks. If there are any problems then they'll probably be build-time ones only, but they could be substantial ones - refactoring our crappy header files always hurts.