binfmt_elf_fdpic: auxvec updates, v2.
Subsystems (3)
cover binfmt_elf_fdpic: auxvec updates, v2.
This is a tiny series of patches for bringing binfmt_elf_fdpic back in line with binfmt_elf in terms of auxiliary vector layout, particularly for the new entries that have popped up recently.
[PATCH 1/3] binfmt_elf_fdpic: Support auxvec base platform string. [PATCH 2/3] binfmt_elf_fdpic: Convert initial stack alignment to arch_align_stack(). [PATCH 3/3] binfmt_elf_fdpic: Wire up AT_EXECFD, AT_EXECFN, AT_SECURE.
Changes since the last version include the updated 2/3 patch and a cosmetic fixup in 1/3.
---
fs/binfmt_elf_fdpic.c | 89 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 25 deletions(-)
PATCH 1/3 binfmt_elf_fdpic: Support auxvec base platform string.
Commit 483fad1c3fa1060d7e6710e84a065ad514571739 introduces AT_BASE_PLATFORM, but only implements it for binfmt_elf. Given that AT_VECTOR_SIZE_BASE is unconditionally enlarged for us, and it's only optionally added in for the platforms that set ELF_BASE_PLATFORM, wire it up for binfmt_elf_fdpic, too.
---
fs/binfmt_elf_fdpic.c | 50 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 43 insertions(+), 7 deletions(-)
fs/binfmt_elf_fdpic.c +43 -7
@@ -455,6 +455,16 @@ error_kill: }/*****************************************************************************/ + +#ifndef ELF_BASE_PLATFORM +/* +* AT_BASE_PLATFORM indicates the "real" hardware/microarchitecture. +* If the arch defines ELF_BASE_PLATFORM (in asm/elf.h), the value +* will be copied to the user stack in the same manner as AT_PLATFORM. +*/ +#define ELF_BASE_PLATFORM NULL +#endif +/* * present useful information to the program */
@@ -466,8 +476,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,unsigned long sp, csp, nitems;elf_caddr_t __user *argv, *envp;size_t platform_len =0 , len; -char *k_platform; -char __user *u_platform, *p; +char *k_platform, *k_base_platform; +char __user *u_platform, *u_base_platform, *p;long hwcap;int loop;int nr;/* reset for each csp adjustment */
@@ -483,11 +493,14 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,return -EFAULT ;#endif -/* get hold of platform and hardware capabilities masks for the machine -* we are running on. In some cases (Sparc), this info is impossible -* to get, in others (i386) it is merely difficult. -*/ hwcap =ELF_HWCAP ; + +/* +* If this architecture has a platform capability string, copy it +* to userspace. In some cases (Sparc), this info is impossible +* for userspace to get any other way, in others (i386) it is +* merely difficult. +*/ k_platform =ELF_PLATFORM ; u_platform =NULL ;
@@ -499,6 +512,21 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,return -EFAULT ; } +/* +* If this architecture has a "base" platform capability +* string, copy it to userspace. +*/ + k_base_platform =ELF_BASE_PLATFORM ; + u_base_platform =NULL ; + +if (k_base_platform) { + platform_len =strlen (k_base_platform) +1 ; + sp -= platform_len; + u_base_platform = (char __user *) sp; +if (__copy_to_user (u_base_platform, k_base_platform, platform_len) !=0 ) +return -EFAULT ; + } +#if defined(__i386__) && defined(CONFIG_SMP )/* in some cases (e.g. Hyper-Threading), we want to avoid L1 evictions * by the processes running on the same package. One thing we can do is
@@ -543,7 +571,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,/* force 16 byte _final_ alignment here for generality */ #define DLINFO_ITEMS 13 - nitems =1 +DLINFO_ITEMS + (k_platform ?1 :0 ) +AT_VECTOR_SIZE_ARCH ; + nitems =1 +DLINFO_ITEMS + (k_platform ?1 :0 ) + + (k_base_platform ?1 :0 ) +AT_VECTOR_SIZE_ARCH ; csp = sp; sp -= nitems *2 *sizeof (unsigned long );
@@ -575,6 +604,13 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, (elf_addr_t) (unsigned long) u_platform); } +if (k_base_platform) { + nr =0 ; + csp -=2 *sizeof (unsigned long ); +NEW_AUX_ENT (AT_BASE_PLATFORM , + (elf_addr_t ) (unsigned long ) u_base_platform); + } + nr =0 ; csp -=DLINFO_ITEMS *2 *sizeof (unsigned long );NEW_AUX_ENT (AT_HWCAP , hwcap);
PATCH 2/3 binfmt_elf_fdpic: Convert initial stack alignment to arch_align_stack()
In reply to Paul Mundtbinfmt_elf_fdpic seems to have grabbed a hard-coded hack from an ancient version of binfmt_elf in order to try and fix up initial stack alignment on multi-threaded x86, which while in addition to being unused, was also pushed down beyond the first set of operations on the stack pointer, negating the entire purpose.
These days, we have an architecture independent arch_align_stack(), so we switch to using that instead. Move the initial alignment up before the initial stores while we're at it.
---
fs/binfmt_elf_fdpic.c | 25 ++++++++----------------- 1 files changed, 8 insertions(+), 17 deletions(-)
fs/binfmt_elf_fdpic.c +8 -17
@@ -466,7 +466,8 @@ error_kill:#endif /* -* present useful information to the program +* present useful information to the program by shovelling it onto the new +* process's stack */ static int create_elf_fdpic_tables(struct linux_binprm *bprm, struct mm_struct *mm,
@@ -482,9 +483,13 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,int loop;int nr;/* reset for each csp adjustment */ -/* we're going to shovel a whole load of stuff onto the stack */ #ifdef CONFIG_MMU - sp = bprm->p; +/* In some cases (e.g. Hyper-Threading), we want to avoid L1 evictions +* by the processes running on the same package. One thing we can do is +* to shuffle the initial stack for them, so we give the architecture +* an opportunity to do so here. +*/ + sp =arch_align_stack (bprm->p);#else sp = mm->start_stack;
@@ -527,20 +532,6 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,return -EFAULT ; } -#if defined(__i386__) && defined(CONFIG_SMP ) -/* in some cases (e.g. Hyper-Threading), we want to avoid L1 evictions -* by the processes running on the same package. One thing we can do is -* to shuffle the initial stack for them. -* -* the conditionals here are unneeded, but kept in to make the code -* behaviour the same as pre change unless we have hyperthreaded -* processors. This keeps Mr Marcelo Person happier but should be -* removed for 2.5 -*/ -if (smp_num_siblings >1 ) - sp = sp - ((current->pid %64 ) <<7 ); -#endif - sp &= ~7UL ;/* stack the load map(s) */
PATCH 3/3 binfmt_elf_fdpic: Wire up AT_EXECFD, AT_EXECFN, AT_SECURE.
In reply to Paul MundtThese auxvec entries are the only ones left unhandled out of the current base implementation. This syncs up binfmt_elf_fdpic with linux/auxvec.h and current binfmt_elf.
---
fs/binfmt_elf_fdpic.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
fs/binfmt_elf_fdpic.c +13 -1
@@ -25,6 +25,7 @@#include <linux/fcntl.h> #include <linux/slab.h> #include <linux/pagemap.h> +#include <linux/security.h> #include <linux/highmem.h> #include <linux/highuid.h> #include <linux/personality.h>
@@ -562,11 +563,14 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, }/* force 16 byte _final_ alignment here for generality */ -#define DLINFO_ITEMS 13 +#define DLINFO_ITEMS 15 nitems =1 +DLINFO_ITEMS + (k_platform ?1 :0 ) + \ (k_base_platform ?1 :0 ) +AT_VECTOR_SIZE_ARCH ; +if (bprm->interp_flags &BINPRM_FLAGS_EXECFD ) + nitems++; + csp = sp; sp -= nitems *2 *sizeof (unsigned long ); sp -= (bprm->envc +1 ) *sizeof (char *);/* envv[] */
@@ -604,6 +608,12 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, (elf_addr_t) (unsigned long) u_base_platform); } +if (bprm->interp_flags &BINPRM_FLAGS_EXECFD ) { + nr =0 ; + csp -=2 *sizeof (unsigned long ); +NEW_AUX_ENT (AT_EXECFD , bprm->interp_data); + } + nr =0 ; csp -=DLINFO_ITEMS *2 *sizeof (unsigned long );NEW_AUX_ENT (AT_HWCAP , hwcap);
@@ -619,6 +629,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,NEW_AUX_ENT (AT_EUID , (elf_addr_t ) current->euid);NEW_AUX_ENT (AT_GID , (elf_addr_t ) current->gid);NEW_AUX_ENT (AT_EGID , (elf_addr_t ) current->egid); +NEW_AUX_ENT (AT_SECURE ,security_bprm_secureexec (bprm)); +NEW_AUX_ENT (AT_EXECFN , bprm->exec);#ifdef ARCH_DLINFO nr =0 ;
Re: [PATCH 3/3] binfmt_elf_fdpic: Wire up AT_EXECFD, AT_EXECFN, AT_SECURE.
Quoted 3 lines · On Wed, 6 Aug 2008 19:36:15 +0900 Paul Mundt <[email protected]> wrote:
These auxvec entries are the only ones left unhandled out of the current base implementation. This syncs up
binfmt_elf_fdpicwithlinux/auxvec.hand currentbinfmt_elf.
The patches ran afoul of the credentials changes in linux-next.
#1 and #2 applied OK, but #3 tossed the below reject. Please check that my (fairly obvious) fixups are OK.
***************
*** 562,572 ****
}
/* force 16 byte _final_ alignment here for generality */
- #define DLINFO_ITEMS 13
nitems = 1 + DLINFO_ITEMS + (k_platform ? 1 : 0) + \ (k_base_platform ? 1 : 0) + AT_VECTOR_SIZE_ARCH;
csp = sp;
sp -= nitems * 2 * sizeof(unsigned long);
sp -= (bprm->envc + 1) * sizeof(char *); /* envv[] */
--- 563,576 ----
}
/* force 16 byte _final_ alignment here for generality */
+ #define DLINFO_ITEMS 15
nitems = 1 + DLINFO_ITEMS + (k_platform ? 1 : 0) + \ (k_base_platform ? 1 : 0) + AT_VECTOR_SIZE_ARCH;
+ if (bprm->interp_flags & BINPRM_FLAGS_EXECFD)
+ nitems++;
+
csp = sp;
sp -= nitems * 2 * sizeof(unsigned long);
sp -= (bprm->envc + 1) * sizeof(char *); /* envv[] */
***************
*** 618,623 ****
NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid);
NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid);
NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid);
#ifdef ARCH_DLINFO
nr = 0;
--- 628,635 ----
NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid);
NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid);
NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid);
+ NEW_AUX_ENT(AT_SECURE, security_bprm_secureexec(bprm));
+ NEW_AUX_ENT(AT_EXECFN, bprm->exec);
#ifdef ARCH_DLINFO nr = 0;
Re: [PATCH 3/3] binfmt_elf_fdpic: Wire up AT_EXECFD, AT_EXECFN, AT_SECURE.
Quoted 12 lines · Andrew Morton
Quoted 3 lines · On Wed, 6 Aug 2008 19:36:15 +0900 Paul Mundt <[email protected]> wrote:
These auxvec entries are the only ones left unhandled out of the current base implementation. This syncs up
binfmt_elf_fdpicwithlinux/auxvec.hand currentbinfmt_elf.The patches ran afoul of the credentials changes in linux-next.
#1 and #2 applied OK, but #3 tossed the below reject. Please check that my (fairly obvious) fixups are OK.
Yes, your fixups look fine, thanks.
Also note that you are missing David's signed-off-by on 2/3: