* [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems
@ 2024-12-04 12:07 Dan Carpenter
2025-01-10 11:51 ` Dan Carpenter
2025-01-10 16:49 ` Kees Cook
0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2024-12-04 12:07 UTC (permalink / raw)
To: Nicolas Pitre
Cc: Alexander Viro, Christian Brauner, Jan Kara, Kees Cook,
Eric Biederman, linux-fsdevel, linux-mm, linux-kernel,
kernel-janitors
Most of these sizes and counts are capped at 256MB so the math doesn't
result in an integer overflow. The "relocs" count needs to be checked
as well. Otherwise on 32bit systems the calculation of "full_data"
could be wrong.
full_data = data_len + relocs * sizeof(unsigned long);
Fixes: c995ee28d29d ("binfmt_flat: prevent kernel dammage from corrupted executable headers")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
fs/binfmt_flat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 390808ce935d..b5b5ca1a44f7 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -478,7 +478,7 @@ static int load_flat_file(struct linux_binprm *bprm,
* 28 bits (256 MB) is way more than reasonable in this case.
* If some top bits are set we have probable binary corruption.
*/
- if ((text_len | data_len | bss_len | stack_len | full_data) >> 28) {
+ if ((text_len | data_len | bss_len | stack_len | relocs | full_data) >> 28) {
pr_err("bad header\n");
ret = -ENOEXEC;
goto err;
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems
2024-12-04 12:07 [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems Dan Carpenter
@ 2025-01-10 11:51 ` Dan Carpenter
2025-01-10 15:55 ` Nicolas Pitre
2025-01-10 16:49 ` Kees Cook
1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2025-01-10 11:51 UTC (permalink / raw)
To: Nicolas Pitre
Cc: Alexander Viro, Christian Brauner, Jan Kara, Kees Cook,
Eric Biederman, linux-fsdevel, linux-mm, linux-kernel,
kernel-janitors
Ping.
regards,
dan carpenter
On Wed, Dec 04, 2024 at 03:07:15PM +0300, Dan Carpenter wrote:
> Most of these sizes and counts are capped at 256MB so the math doesn't
> result in an integer overflow. The "relocs" count needs to be checked
> as well. Otherwise on 32bit systems the calculation of "full_data"
> could be wrong.
>
> full_data = data_len + relocs * sizeof(unsigned long);
>
> Fixes: c995ee28d29d ("binfmt_flat: prevent kernel dammage from corrupted executable headers")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> fs/binfmt_flat.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> index 390808ce935d..b5b5ca1a44f7 100644
> --- a/fs/binfmt_flat.c
> +++ b/fs/binfmt_flat.c
> @@ -478,7 +478,7 @@ static int load_flat_file(struct linux_binprm *bprm,
> * 28 bits (256 MB) is way more than reasonable in this case.
> * If some top bits are set we have probable binary corruption.
> */
> - if ((text_len | data_len | bss_len | stack_len | full_data) >> 28) {
> + if ((text_len | data_len | bss_len | stack_len | relocs | full_data) >> 28) {
> pr_err("bad header\n");
> ret = -ENOEXEC;
> goto err;
> --
> 2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems
2025-01-10 11:51 ` Dan Carpenter
@ 2025-01-10 15:55 ` Nicolas Pitre
0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Pitre @ 2025-01-10 15:55 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alexander Viro, Christian Brauner, Jan Kara, Kees Cook,
Eric Biederman, linux-fsdevel, linux-mm, linux-kernel,
kernel-janitors
On Fri, 10 Jan 2025, Dan Carpenter wrote:
> Ping.
>
> regards,
> dan carpenter
>
> On Wed, Dec 04, 2024 at 03:07:15PM +0300, Dan Carpenter wrote:
> > Most of these sizes and counts are capped at 256MB so the math doesn't
> > result in an integer overflow. The "relocs" count needs to be checked
> > as well. Otherwise on 32bit systems the calculation of "full_data"
> > could be wrong.
> >
> > full_data = data_len + relocs * sizeof(unsigned long);
> >
> > Fixes: c995ee28d29d ("binfmt_flat: prevent kernel dammage from corrupted executable headers")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
> > ---
> > fs/binfmt_flat.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
> > index 390808ce935d..b5b5ca1a44f7 100644
> > --- a/fs/binfmt_flat.c
> > +++ b/fs/binfmt_flat.c
> > @@ -478,7 +478,7 @@ static int load_flat_file(struct linux_binprm *bprm,
> > * 28 bits (256 MB) is way more than reasonable in this case.
> > * If some top bits are set we have probable binary corruption.
> > */
> > - if ((text_len | data_len | bss_len | stack_len | full_data) >> 28) {
> > + if ((text_len | data_len | bss_len | stack_len | relocs | full_data) >> 28) {
> > pr_err("bad header\n");
> > ret = -ENOEXEC;
> > goto err;
> > --
> > 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems
2024-12-04 12:07 [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems Dan Carpenter
2025-01-10 11:51 ` Dan Carpenter
@ 2025-01-10 16:49 ` Kees Cook
1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2025-01-10 16:49 UTC (permalink / raw)
To: Nicolas Pitre, Dan Carpenter
Cc: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara,
Eric Biederman, linux-fsdevel, linux-mm, linux-kernel,
kernel-janitors
On Wed, 04 Dec 2024 15:07:15 +0300, Dan Carpenter wrote:
> Most of these sizes and counts are capped at 256MB so the math doesn't
> result in an integer overflow. The "relocs" count needs to be checked
> as well. Otherwise on 32bit systems the calculation of "full_data"
> could be wrong.
>
> full_data = data_len + relocs * sizeof(unsigned long);
>
> [...]
Applied to for-next/topic/execve/core, thanks!
[1/1] binfmt_flat: Fix integer overflow bug on 32 bit systems
https://git.kernel.org/kees/c/55cf2f4b945f
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-10 16:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-04 12:07 [PATCH] binfmt_flat: Fix integer overflow bug on 32 bit systems Dan Carpenter
2025-01-10 11:51 ` Dan Carpenter
2025-01-10 15:55 ` Nicolas Pitre
2025-01-10 16:49 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox