* [PATCH] binfmt_flat: Fix corruption when not offsetting data start
@ 2024-03-26 3:20 Stefan O'Rear
2024-03-26 5:53 ` Damien Le Moal
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stefan O'Rear @ 2024-03-26 3:20 UTC (permalink / raw)
To: linux-mm, linux-riscv
Cc: Eric Biederman, Kees Cook, Damien Le Moal, Greg Ungerer,
Waldemar Brodkorb, Stefan O'Rear
Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
introduced a RISC-V specific variant of the FLAT format which does not
allocate any space for the (obsolescent) array of shared library
pointers. However, it did not disable the code which initializes the
array, resulting in the corruption of sizeof(long) bytes before the DATA
segment, generally the end of the TEXT segment.
Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the
shared library pointer region so that it will only be initialized if
space is reserved for it.
Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
Tested-by: Waldemar Brodkorb <wbx@openadk.org>
---
fs/binfmt_flat.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index c26545d71d39..70c2b68988f4 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
if (res < 0)
return res;
+#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
/* Update data segment pointers for all libraries */
for (i = 0; i < MAX_SHARED_LIBS; i++) {
if (!libinfo.lib_list[i].loaded)
@@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
return -EFAULT;
}
}
+#endif
set_binfmt(&flat_format);
--
2.40.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] binfmt_flat: Fix corruption when not offsetting data start
2024-03-26 3:20 [PATCH] binfmt_flat: Fix corruption when not offsetting data start Stefan O'Rear
@ 2024-03-26 5:53 ` Damien Le Moal
2024-04-04 7:40 ` Greg Ungerer
2024-04-24 20:44 ` Alexandre Ghiti
2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2024-03-26 5:53 UTC (permalink / raw)
To: Stefan O'Rear, linux-mm, linux-riscv
Cc: Eric Biederman, Kees Cook, Damien Le Moal, Greg Ungerer,
Waldemar Brodkorb
On 3/26/24 12:20, Stefan O'Rear wrote:
> Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> introduced a RISC-V specific variant of the FLAT format which does not
> allocate any space for the (obsolescent) array of shared library
> pointers. However, it did not disable the code which initializes the
> array, resulting in the corruption of sizeof(long) bytes before the DATA
> segment, generally the end of the TEXT segment.
>
> Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the
s/initialization the/the initialization of the
> shared library pointer region so that it will only be initialized if
> space is reserved for it.
>
> Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
> Tested-by: Waldemar Brodkorb <wbx@openadk.org>
It feels like CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is not a very good name...
Maybe something like CONFIG_BINFMT_FLAT_NO_SHARED_LIBRARY would be better. But
renaming can be done in a followup patch.
Reviewed-by: Damien Le Moal <dlemoal
> ---
> fs/binfmt_flat.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index c26545d71d39..70c2b68988f4 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> if (res < 0)
> return res;
>
> +#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
> /* Update data segment pointers for all libraries */
> for (i = 0; i < MAX_SHARED_LIBS; i++) {
> if (!libinfo.lib_list[i].loaded)
> @@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> return -EFAULT;
> }
> }
> +#endif
>
> set_binfmt(&flat_format);
>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] binfmt_flat: Fix corruption when not offsetting data start
2024-03-26 3:20 [PATCH] binfmt_flat: Fix corruption when not offsetting data start Stefan O'Rear
2024-03-26 5:53 ` Damien Le Moal
@ 2024-04-04 7:40 ` Greg Ungerer
2024-04-24 20:44 ` Alexandre Ghiti
2 siblings, 0 replies; 4+ messages in thread
From: Greg Ungerer @ 2024-04-04 7:40 UTC (permalink / raw)
To: Stefan O'Rear, linux-mm, linux-riscv
Cc: Eric Biederman, Kees Cook, Damien Le Moal, Waldemar Brodkorb
Hi Stefan,
On 26/3/24 13:20, Stefan O'Rear wrote:
> Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> introduced a RISC-V specific variant of the FLAT format which does not
> allocate any space for the (obsolescent) array of shared library
> pointers. However, it did not disable the code which initializes the
> array, resulting in the corruption of sizeof(long) bytes before the DATA
> segment, generally the end of the TEXT segment.
>
> Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the
> shared library pointer region so that it will only be initialized if
> space is reserved for it.
>
> Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
> Tested-by: Waldemar Brodkorb <wbx@openadk.org>
> ---
> fs/binfmt_flat.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index c26545d71d39..70c2b68988f4 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> if (res < 0)
> return res;
>
> +#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
> /* Update data segment pointers for all libraries */
> for (i = 0; i < MAX_SHARED_LIBS; i++) {
^^^^^^^^^^^^^^^
It may be cleaner (ie no # conditional required) if this was changed to
DATA_START_OFFSET_WORDS. So becoming:
for (i = 0; i < DATA_START_OFFSET_WORDS; i++) {
My only concern is does this make it less clear what the code is doing?
Regards
Greg
> if (!libinfo.lib_list[i].loaded)
> @@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> return -EFAULT;
> }
> }
> +#endif
>
> set_binfmt(&flat_format);
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] binfmt_flat: Fix corruption when not offsetting data start
2024-03-26 3:20 [PATCH] binfmt_flat: Fix corruption when not offsetting data start Stefan O'Rear
2024-03-26 5:53 ` Damien Le Moal
2024-04-04 7:40 ` Greg Ungerer
@ 2024-04-24 20:44 ` Alexandre Ghiti
2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Ghiti @ 2024-04-24 20:44 UTC (permalink / raw)
To: Stefan O'Rear, linux-mm, linux-riscv
Cc: Eric Biederman, Kees Cook, Damien Le Moal, Greg Ungerer,
Waldemar Brodkorb
Hi Stefan,
On 26/03/2024 04:20, Stefan O'Rear wrote:
> Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> introduced a RISC-V specific variant of the FLAT format which does not
> allocate any space for the (obsolescent) array of shared library
> pointers. However, it did not disable the code which initializes the
> array, resulting in the corruption of sizeof(long) bytes before the DATA
> segment, generally the end of the TEXT segment.
>
> Use CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard initialization the
> shared library pointer region so that it will only be initialized if
> space is reserved for it.
>
> Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
> Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
> Tested-by: Waldemar Brodkorb <wbx@openadk.org>
> ---
> fs/binfmt_flat.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index c26545d71d39..70c2b68988f4 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -879,6 +879,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> if (res < 0)
> return res;
>
> +#ifndef CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET
> /* Update data segment pointers for all libraries */
> for (i = 0; i < MAX_SHARED_LIBS; i++) {
> if (!libinfo.lib_list[i].loaded)
> @@ -893,6 +894,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
> return -EFAULT;
> }
> }
> +#endif
>
> set_binfmt(&flat_format);
>
I have this fix on my list for quite some time, will you respin a new
version for 6.9?
Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-24 20:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26 3:20 [PATCH] binfmt_flat: Fix corruption when not offsetting data start Stefan O'Rear
2024-03-26 5:53 ` Damien Le Moal
2024-04-04 7:40 ` Greg Ungerer
2024-04-24 20:44 ` Alexandre Ghiti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox