Skip to contentSkip to conversation

binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined

PATCH Applied Max Filippov 3 participants 3 messages Aug 26, 2024

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

PATCH 1/1 binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined

create_elf_fdpic_tables() does not correctly account the space for the AUX vector when an architecture has ELF_HWCAP2 defined. Prior to the commit 10e29251be0e ("binfmt_elf_fdpic: fix /proc/<pid>/auxv") it resulted in the last entry of the AUX vector being set to zero, but with that change it results in a kernel BUG.

Fix that by adding one to the number of AUXV entries (nitems) when ELF_HWCAP2 is defined.

Fixes 10e29251be0e ("binfmt_elf_fdpic: fix /proc/<pid>/auxv")
---
 fs/binfmt_elf_fdpic.c | 3 +++
 1 file changed, 3 insertions(+)
fs/binfmt_elf_fdpic.c +3 -0
index c11289e1301b..a5cb45cb30c8 100644
@@ -594,6 +594,9 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
 
 	if (bprm->have_execfd)
 		nitems++;
+#ifdef ELF_HWCAP2
+	nitems++;
+#endif
 
 	csp = sp;
 	sp -= nitems * 2 * sizeof(unsigned long);
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw

Hi Max,

Quoted 6 lines · Max Filippov

create_elf_fdpic_tables() does not correctly account the space for the AUX vector when an architecture has ELF_HWCAP2 defined. Prior to the commit 10e29251be0e ("binfmt_elf_fdpic: fix /proc/<pid>/auxv") it resulted in the last entry of the AUX vector being set to zero, but with that change it results in a kernel BUG.

Quoted 6 lines

Fix that by adding one to the number of AUXV entries (nitems) when ELF_HWCAP2 is defined.

Fixes 10e29251be0e ("binfmt_elf_fdpic: fix /proc/<pid>/auxv")

Feel free to use my [email protected] email for this.

Quoted 2 lines

Certainly fixes it for all my failing test cases, so:

Thanks for looking into it and the fix.

Regards
Greg

Quoted 18 lines
---
  fs/binfmt_elf_fdpic.c | 3 +++
  1 file changed, 3 insertions(+)
fs/binfmt_elf_fdpic.c +3 -0
index c11289e1301b..a5cb45cb30c8 100644
@@ -594,6 +594,9 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm,
 
  	if (bprm->have_execfd)
  		nitems++;
+#ifdef ELF_HWCAP2
+	nitems++;
+#endif
 
  	csp = sp;
  	sp -= nitems * 2 * sizeof(unsigned long);
maintainer Applied
#2 lore raw
In reply to Max Filippov
Quoted 10 lines · Max Filippov

create_elf_fdpic_tables() does not correctly account the space for the AUX vector when an architecture has ELF_HWCAP2 defined. Prior to the commit 10e29251be0e ("binfmt_elf_fdpic: fix /proc/<pid>/auxv") it resulted in the last entry of the AUX vector being set to zero, but with that change it results in a kernel BUG.

Fix that by adding one to the number of AUXV entries (nitems) when ELF_HWCAP2 is defined.

[...]

Applied to for-linus/execve, thanks!

[1/1] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined

      https://git.kernel.org/kees/c/c6a09e342f8e

Take care,

Signature · 1 line
Kees Cook