linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] elf: fix NT_FILE integer overflow
@ 2018-01-12 20:34 Alexey Dobriyan
  2018-01-12 22:52 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2018-01-12 20:34 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

If vm.max_map_count bumped above 2^26 (67+ mil) and system has enough
RAM to allocate all the VMAs (~12.8 GB on Fedora 27 with 200-byte VMAs),
then it should be possible to overflow 32-bit "size", pass paranoia check,
allocate very little vmalloc space and oops while writing into vmalloc
guard page...

But I didn't test this, only coredump of regular process.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/binfmt_elf.c |    2 ++
 1 file changed, 2 insertions(+)

--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1599,6 +1599,8 @@ static int fill_files_note(struct memelfnote *note)
 
 	/* *Estimated* file count and total data size needed */
 	count = current->mm->map_count;
+	if (count > UINT_MAX / 64)
+		return -EINVAL;
 	size = count * 64;
 
 	names_ofs = (2 + 3 * count) * sizeof(data[0]);

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

* Re: [PATCH] elf: fix NT_FILE integer overflow
  2018-01-12 20:34 [PATCH] elf: fix NT_FILE integer overflow Alexey Dobriyan
@ 2018-01-12 22:52 ` Andrew Morton
  2018-01-13  9:14   ` Alexey Dobriyan
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2018-01-12 22:52 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel

On Fri, 12 Jan 2018 23:34:27 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

> If vm.max_map_count bumped above 2^26 (67+ mil) and system has enough
> RAM to allocate all the VMAs (~12.8 GB on Fedora 27 with 200-byte VMAs),
> then it should be possible to overflow 32-bit "size", pass paranoia check,
> allocate very little vmalloc space and oops while writing into vmalloc
> guard page...
> 
> But I didn't test this, only coredump of regular process.
> 
> ...
>
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -1599,6 +1599,8 @@ static int fill_files_note(struct memelfnote *note)
>  
>  	/* *Estimated* file count and total data size needed */
>  	count = current->mm->map_count;
> +	if (count > UINT_MAX / 64)
> +		return -EINVAL;
>  	size = count * 64;
>  
>  	names_ofs = (2 + 3 * count) * sizeof(data[0]);

Why not make `size' a ulong (or size_t)?  That seems to be the
appropriate type and the code will then immediately barf over the
MAX_FILE_NOTE_SIZE comparison anyway.

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

* Re: [PATCH] elf: fix NT_FILE integer overflow
  2018-01-12 22:52 ` Andrew Morton
@ 2018-01-13  9:14   ` Alexey Dobriyan
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2018-01-13  9:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On Fri, Jan 12, 2018 at 02:52:08PM -0800, Andrew Morton wrote:
> On Fri, 12 Jan 2018 23:34:27 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > If vm.max_map_count bumped above 2^26 (67+ mil) and system has enough
> > RAM to allocate all the VMAs (~12.8 GB on Fedora 27 with 200-byte VMAs),
> > then it should be possible to overflow 32-bit "size", pass paranoia check,
> > allocate very little vmalloc space and oops while writing into vmalloc
> > guard page...
> > 
> > But I didn't test this, only coredump of regular process.
> > 
> > ...
> >
> > --- a/fs/binfmt_elf.c
> > +++ b/fs/binfmt_elf.c
> > @@ -1599,6 +1599,8 @@ static int fill_files_note(struct memelfnote *note)
> >  
> >  	/* *Estimated* file count and total data size needed */
> >  	count = current->mm->map_count;
> > +	if (count > UINT_MAX / 64)
> > +		return -EINVAL;
> >  	size = count * 64;
> >  
> >  	names_ofs = (2 + 3 * count) * sizeof(data[0]);
> 
> Why not make `size' a ulong (or size_t)?  That seems to be the
> appropriate type and the code will then immediately barf over the
> MAX_FILE_NOTE_SIZE comparison anyway.

You can do it, but MAX_FILE_NOTE_SIZE is only 4 MB, and 32-bit code is
smaller than 64-bit code.

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

end of thread, other threads:[~2018-01-13  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-12 20:34 [PATCH] elf: fix NT_FILE integer overflow Alexey Dobriyan
2018-01-12 22:52 ` Andrew Morton
2018-01-13  9:14   ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).