linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined
@ 2024-08-26  3:27 Max Filippov
  2024-08-26  7:00 ` Greg Ungerer
  2024-08-26 20:06 ` Kees Cook
  0 siblings, 2 replies; 3+ messages in thread
From: Max Filippov @ 2024-08-26  3:27 UTC (permalink / raw)
  To: Greg Ungerer, linux-kernel
  Cc: linux-mm, linux-fsdevel, Alexander Viro, Christian Brauner,
	Jan Kara, Eric Biederman, Kees Cook, Max Filippov, stable

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")
Cc: stable@vger.kernel.org
Reported-by: Greg Ungerer <gregungerer@westnet.com.au>
Closes: https://lore.kernel.org/lkml/5b51975f-6d0b-413c-8b38-39a6a45e8821@westnet.com.au/
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 fs/binfmt_elf_fdpic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index c11289e1301b..a5cb45cb30c8 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -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);
-- 
2.39.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined
  2024-08-26  3:27 [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined Max Filippov
@ 2024-08-26  7:00 ` Greg Ungerer
  2024-08-26 20:06 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Ungerer @ 2024-08-26  7:00 UTC (permalink / raw)
  To: Max Filippov, linux-kernel
  Cc: linux-mm, linux-fsdevel, Alexander Viro, Christian Brauner,
	Jan Kara, Eric Biederman, Kees Cook, stable

Hi Max,

On 26/8/24 13:27, Max Filippov wrote:
> 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")
> Cc: stable@vger.kernel.org
> Reported-by: Greg Ungerer <gregungerer@westnet.com.au>

Feel free to use my gerg@kernel.org email for this.


> Closes: https://lore.kernel.org/lkml/5b51975f-6d0b-413c-8b38-39a6a45e8821@westnet.com.au/
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

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

Tested-by: Greg Ungerer <gerg@kernel.org>

Thanks for looking into it and the fix.

Regards
Greg


> ---
>   fs/binfmt_elf_fdpic.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
> index c11289e1301b..a5cb45cb30c8 100644
> --- a/fs/binfmt_elf_fdpic.c
> +++ b/fs/binfmt_elf_fdpic.c
> @@ -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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined
  2024-08-26  3:27 [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined Max Filippov
  2024-08-26  7:00 ` Greg Ungerer
@ 2024-08-26 20:06 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2024-08-26 20:06 UTC (permalink / raw)
  To: Greg Ungerer, linux-kernel, Max Filippov
  Cc: Kees Cook, linux-mm, linux-fsdevel, Alexander Viro,
	Christian Brauner, Jan Kara, Eric Biederman, stable

On Sun, 25 Aug 2024 20:27:45 -0700, Max Filippov wrote:
> 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,

-- 
Kees Cook



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-26 20:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-26  3:27 [PATCH] binfmt_elf_fdpic: fix AUXV size calculation when ELF_HWCAP2 is defined Max Filippov
2024-08-26  7:00 ` Greg Ungerer
2024-08-26 20:06 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox