2007-09-14 11:00:38

by Olaf Hering

[permalink] [raw]
Subject: increase AT_VECTOR_SIZE to terminate saved_auxv properly

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.


2007-09-15 14:01:33

by Jakub Jelinek

[permalink] [raw]
Subject: Re: increase AT_VECTOR_SIZE to terminate saved_auxv properly

On Fri, Sep 14, 2007 at 01:00:57PM +0200, Olaf Hering 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.
>
> 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.

> 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

2007-09-17 09:11:29

by Olaf Hering

[permalink] [raw]
Subject: Re: increase AT_VECTOR_SIZE to terminate saved_auxv properly

On Sat, Sep 15, Jakub Jelinek wrote:

> > 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(-)

--- a/include/asm-alpha/elf.h
+++ b/include/asm-alpha/elf.h
@@ -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); \
--- a/include/asm-i386/elf.h
+++ b/include/asm-i386/elf.h
@@ -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); \
--- a/include/asm-ia64/elf.h
+++ b/include/asm-ia64/elf.h
@@ -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[]; \
--- a/include/asm-powerpc/elf.h
+++ b/include/asm-powerpc/elf.h
@@ -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. */ \
--- a/include/asm-sh/elf.h
+++ b/include/asm-sh/elf.h
@@ -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) \
--- a/include/linux/auxvec.h
+++ b/include/linux/auxvec.h
@@ -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 */
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -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
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1,7 +1,6 @@
#ifndef _LINUX_SCHED_H
#define _LINUX_SCHED_H

-#include <linux/auxvec.h> /* For AT_VECTOR_SIZE */

/*
* cloning flags:

2007-09-18 11:54:36

by Olaf Hering

[permalink] [raw]
Subject: [PATCH] increase AT_VECTOR_SIZE to terminate saved_auxv properly


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.

Signed-off-by: Olaf Hering <[email protected]>

---
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(-)

--- a/include/asm-alpha/system.h
+++ b/include/asm-alpha/system.h
@@ -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
--- a/include/asm-i386/system.h
+++ b/include/asm-i386/system.h
@@ -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));
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -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 */
--- a/include/asm-powerpc/system.h
+++ b/include/asm-powerpc/system.h
@@ -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()
--- a/include/asm-sh/system.h
+++ b/include/asm-sh/system.h
@@ -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
*/
--- a/include/linux/auxvec.h
+++ b/include/linux/auxvec.h
@@ -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 */
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -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>

--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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.

2007-09-20 06:44:25

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] increase AT_VECTOR_SIZE to terminate saved_auxv properly

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.

2007-09-20 19:19:06

by Olaf Hering

[permalink] [raw]
Subject: Re: [PATCH] increase AT_VECTOR_SIZE to terminate saved_auxv properly

On Wed, Sep 19, Andrew Morton wrote:

> 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?

2007-09-20 20:22:53

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] increase AT_VECTOR_SIZE to terminate saved_auxv properly

On Thu, 20 Sep 2007 21:19:44 +0200
Olaf Hering <[email protected]> wrote:

> On Wed, Sep 19, Andrew Morton wrote:
>
> > 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.