linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: KASAN: stack-out-of-bounds Write in mpol_to_str
       [not found] <CALzBtjLSqFhSNAf4YusxuE1piUTzOSLFGFD4RrhPLQAmgpyL5g@mail.gmail.com>
@ 2020-03-16 18:46 ` Randy Dunlap
       [not found]   ` <CALzBtj+8AYASaYW2fqgmgthCgeAJ2N0Q+ey2wqgEKjBtH34Vcg@mail.gmail.com>
  2020-03-26  0:45 ` [PATCH] mm: mempolicy: require at least one nodeid for MPOL_PREFERRED Randy Dunlap
  1 sibling, 1 reply; 6+ messages in thread
From: Randy Dunlap @ 2020-03-16 18:46 UTC (permalink / raw)
  To: Entropy Moe, linux-kernel, linux-mm, akpm

On 3/15/20 12:57 PM, Entropy Moe wrote:
> Hello team,
> how are you ?
> I wanted to report a bug on mempolicy.c. I found the bug on the latest version of the kernel.
> 
> which is stack out of bound vulnerability.
> 
> I am attaching  report. 
> 
> If you need the POC crash code, I can provide.

Hi Moe,

Please post the POC code and your kernel .config file.

thanks.
-- 
~Randy


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

* Re: KASAN: stack-out-of-bounds Write in mpol_to_str
       [not found]   ` <CALzBtj+8AYASaYW2fqgmgthCgeAJ2N0Q+ey2wqgEKjBtH34Vcg@mail.gmail.com>
@ 2020-03-21  6:45     ` Andrew Morton
  2020-03-26  0:54     ` Randy Dunlap
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2020-03-21  6:45 UTC (permalink / raw)
  To: Entropy Moe; +Cc: Randy Dunlap, linux-kernel, linux-mm

On Fri, 20 Mar 2020 12:36:38 +0400 Entropy Moe <3ntr0py1337@gmail.com> wrote:

> Hello Randy,
> please see attached POC for the vulnerability.
> 

Thanks.  Ouch.  afaict shmem's S_IFREG inode's mpol's preferred_node is
messed up.

I don't think anyone has worked on this code in a decade or more.  Is
someone up to taking a look please?


> On Mon, Mar 16, 2020 at 10:46 PM Randy Dunlap <rdunlap@infradead.org> wrote:
> 
> > On 3/15/20 12:57 PM, Entropy Moe wrote:
> > > Hello team,
> > > how are you ?
> > > I wanted to report a bug on mempolicy.c. I found the bug on the latest
> > version of the kernel.
> > >
> > > which is stack out of bound vulnerability.
> > >
> > > I am attaching  report.
> > >
> > > If you need the POC crash code, I can provide.
> >
> > Hi Moe,
> >
> > Please post the POC code and your kernel .config file.
> >
> > thanks.
> > --
> > ~Randy
> >
> >

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

* [PATCH] mm: mempolicy: require at least one nodeid for MPOL_PREFERRED
       [not found] <CALzBtjLSqFhSNAf4YusxuE1piUTzOSLFGFD4RrhPLQAmgpyL5g@mail.gmail.com>
  2020-03-16 18:46 ` KASAN: stack-out-of-bounds Write in mpol_to_str Randy Dunlap
@ 2020-03-26  0:45 ` Randy Dunlap
  1 sibling, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2020-03-26  0:45 UTC (permalink / raw)
  To: Entropy Moe, linux-kernel, linux-mm, akpm

From: Randy Dunlap <rdunlap@infradead.org>

Using an empty (malformed) nodelist that is not caught during
mount option parsing leads to a stack-out-of-bounds access.

The option string that was used was: "mpol=prefer:,".
However, MPOL_PREFERRED requires a single node number,
which is not being provided here.

Add a check that 'nodes' is not empty after parsing for
MPOL_PREFERRED's nodeid.

Fixes: 095f1fc4ebf3 ("mempolicy: rework shmem mpol parsing and display")
Reported-by: Entropy Moe <3ntr0py1337@gmail.com>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
---
 mm/mempolicy.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- lnx-56-rc6.orig/mm/mempolicy.c
+++ lnx-56-rc6/mm/mempolicy.c
@@ -2841,7 +2841,9 @@ int mpol_parse_str(char *str, struct mem
 	switch (mode) {
 	case MPOL_PREFERRED:
 		/*
-		 * Insist on a nodelist of one node only
+		 * Insist on a nodelist of one node only, although later
+		 * we use first_node(nodes) to grab a single node, so here
+		 * nodelist (or nodes) cannot be empty.
 		 */
 		if (nodelist) {
 			char *rest = nodelist;
@@ -2849,6 +2851,8 @@ int mpol_parse_str(char *str, struct mem
 				rest++;
 			if (*rest)
 				goto out;
+			if (nodes_empty(nodes))
+				goto out;
 		}
 		break;
 	case MPOL_INTERLEAVE:


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

* Re: KASAN: stack-out-of-bounds Write in mpol_to_str
       [not found]   ` <CALzBtj+8AYASaYW2fqgmgthCgeAJ2N0Q+ey2wqgEKjBtH34Vcg@mail.gmail.com>
  2020-03-21  6:45     ` Andrew Morton
@ 2020-03-26  0:54     ` Randy Dunlap
  1 sibling, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2020-03-26  0:54 UTC (permalink / raw)
  To: Entropy Moe; +Cc: linux-kernel, linux-mm, akpm, Dmitry Vyukov

On 3/20/20 1:36 AM, Entropy Moe wrote:
> Hello Randy,
> please see attached POC for the vulnerability.
> 

Hi Moe,

Do you have anything to do with the syzkaller source code generation? (POC; reproducers)

I don't expect it to be beautiful, but it could be a lot easier to read in a few places.

E.g., the POC that you provided sets a tmpfs mount option string to
"mpol=prefer:,", which is probably purposely malformed (OK), but it does
so in an unreadable manner: (I added the // comments.)

memcpy((void*)0x20000340, "mpol", 4);
*(uint8_t*)0x20000344 = 0x3d; // =
memcpy((void*)0x20000345, "prefer", 6);
*(uint8_t*)0x2000034b = 0x3a; // :
*(uint8_t*)0x2000034c = 0x2c; // ,
*(uint8_t*)0x2000034d = 0;


That kind of obfuscation just helps slow down debugging. :(

-- 
~Randy


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

* Re: KASAN: stack-out-of-bounds Write in mpol_to_str
  2020-03-26  2:23 KASAN: stack-out-of-bounds Write in mpol_to_str syzbot
@ 2020-03-26  3:47 ` Randy Dunlap
  0 siblings, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2020-03-26  3:47 UTC (permalink / raw)
  To: syzbot, akpm, linux-kernel, linux-mm, syzkaller-bugs

On 3/25/20 7:23 PM, syzbot wrote:
> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    e2cf67f6 Merge tag 'zonefs-5.6-rc7' of git://git.kernel.or..
> git tree:       upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=11c4bd39e00000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=2b05d5a033f5be50
> dashboard link: https://syzkaller.appspot.com/bug?extid=b055b1a6b2b958707a21
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=13252bf9e00000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1632c813e00000
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+b055b1a6b2b958707a21@syzkaller.appspotmail.com

Hi,

Please try the patch at
https://lore.kernel.org/lkml/89526377-7eb6-b662-e1d8-4430928abde9@infradead.org/T/#u

thanks.

> ==================================================================
> BUG: KASAN: stack-out-of-bounds in set_bit include/asm-generic/bitops/instrumented-atomic.h:28 [inline]
> BUG: KASAN: stack-out-of-bounds in __node_set include/linux/nodemask.h:130 [inline]
> BUG: KASAN: stack-out-of-bounds in mpol_to_str+0x377/0x3be mm/mempolicy.c:2962
> Write of size 8 at addr ffffc90000c7fb60 by task systemd/1
> 
> CPU: 0 PID: 1 Comm: systemd Not tainted 5.6.0-rc7-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0x188/0x20d lib/dump_stack.c:118
>  print_address_description.constprop.0.cold+0x5/0x315 mm/kasan/report.c:374
>  __kasan_report.cold+0x1a/0x32 mm/kasan/report.c:506
>  kasan_report+0xe/0x20 mm/kasan/common.c:641
>  check_memory_region_inline mm/kasan/generic.c:185 [inline]
>  check_memory_region+0x128/0x190 mm/kasan/generic.c:192
>  set_bit include/asm-generic/bitops/instrumented-atomic.h:28 [inline]
>  __node_set include/linux/nodemask.h:130 [inline]
>  mpol_to_str+0x377/0x3be mm/mempolicy.c:2962
>  shmem_show_mpol mm/shmem.c:1406 [inline]
>  shmem_show_options+0x418/0x630 mm/shmem.c:3609
>  show_mountinfo+0x616/0x900 fs/proc_namespace.c:187
>  seq_read+0xad0/0x1160 fs/seq_file.c:268
>  __vfs_read+0x76/0x100 fs/read_write.c:425
>  vfs_read+0x1ea/0x430 fs/read_write.c:461
>  ksys_read+0x127/0x250 fs/read_write.c:587
>  do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:294
>  entry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x7f17892db92d
> Code: 2d 2c 00 00 75 10 b8 00 00 00 00 0f 05 48 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 de 9b 01 00 48 89 04 24 b8 00 00 00 00 0f 05 <48> 8b 3c 24 48 89 c2 e8 27 9c 01 00 48 89 d0 48 83 c4 08 48 3d 01
> RSP: 002b:00007ffc058b86b0 EFLAGS: 00000293 ORIG_RAX: 0000000000000000
> RAX: ffffffffffffffda RBX: 0000556657fec630 RCX: 00007f17892db92d
> RDX: 0000000000000400 RSI: 0000556657fec860 RDI: 000000000000002c
> RBP: 0000000000000d68 R08: 00007f178ad11500 R09: 00000000000000e0
> R10: 0000556657fecc47 R11: 0000000000000293 R12: 00007f1789596440
> R13: 00007f1789595900 R14: 0000000000000019 R15: 0000000000000000
> 
> 
> addr ffffc90000c7fb60 is located in stack of task systemd/1 at offset 40 in frame:
>  mpol_to_str+0x0/0x3be mm/mempolicy.c:2924
> 
> this frame has 1 object:
>  [32, 40) 'nodes'
> 
> Memory state around the buggy address:
>  ffffc90000c7fa00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>  ffffc90000c7fa80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>> ffffc90000c7fb00: 00 00 00 00 00 00 00 f1 f1 f1 f1 00 f3 f3 f3 00
>                                                        ^
>  ffffc90000c7fb80: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00
>  ffffc90000c7fc00: 00 00 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00
> ==================================================================
> 
> 
> ---
> This bug is generated by a bot. It may contain errors.
> See https://goo.gl/tpsmEJ for more information about syzbot.
> syzbot engineers can be reached at syzkaller@googlegroups.com.
> 
> syzbot will keep track of this bug report. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patches
> 


-- 
~Randy
Reported-by: Randy Dunlap <rdunlap@infradead.org>

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

* KASAN: stack-out-of-bounds Write in mpol_to_str
@ 2020-03-26  2:23 syzbot
  2020-03-26  3:47 ` Randy Dunlap
  0 siblings, 1 reply; 6+ messages in thread
From: syzbot @ 2020-03-26  2:23 UTC (permalink / raw)
  To: akpm, linux-kernel, linux-mm, syzkaller-bugs

Hello,

syzbot found the following crash on:

HEAD commit:    e2cf67f6 Merge tag 'zonefs-5.6-rc7' of git://git.kernel.or..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=11c4bd39e00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=2b05d5a033f5be50
dashboard link: https://syzkaller.appspot.com/bug?extid=b055b1a6b2b958707a21
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=13252bf9e00000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1632c813e00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+b055b1a6b2b958707a21@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: stack-out-of-bounds in set_bit include/asm-generic/bitops/instrumented-atomic.h:28 [inline]
BUG: KASAN: stack-out-of-bounds in __node_set include/linux/nodemask.h:130 [inline]
BUG: KASAN: stack-out-of-bounds in mpol_to_str+0x377/0x3be mm/mempolicy.c:2962
Write of size 8 at addr ffffc90000c7fb60 by task systemd/1

CPU: 0 PID: 1 Comm: systemd Not tainted 5.6.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x188/0x20d lib/dump_stack.c:118
 print_address_description.constprop.0.cold+0x5/0x315 mm/kasan/report.c:374
 __kasan_report.cold+0x1a/0x32 mm/kasan/report.c:506
 kasan_report+0xe/0x20 mm/kasan/common.c:641
 check_memory_region_inline mm/kasan/generic.c:185 [inline]
 check_memory_region+0x128/0x190 mm/kasan/generic.c:192
 set_bit include/asm-generic/bitops/instrumented-atomic.h:28 [inline]
 __node_set include/linux/nodemask.h:130 [inline]
 mpol_to_str+0x377/0x3be mm/mempolicy.c:2962
 shmem_show_mpol mm/shmem.c:1406 [inline]
 shmem_show_options+0x418/0x630 mm/shmem.c:3609
 show_mountinfo+0x616/0x900 fs/proc_namespace.c:187
 seq_read+0xad0/0x1160 fs/seq_file.c:268
 __vfs_read+0x76/0x100 fs/read_write.c:425
 vfs_read+0x1ea/0x430 fs/read_write.c:461
 ksys_read+0x127/0x250 fs/read_write.c:587
 do_syscall_64+0xf6/0x7d0 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x7f17892db92d
Code: 2d 2c 00 00 75 10 b8 00 00 00 00 0f 05 48 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 de 9b 01 00 48 89 04 24 b8 00 00 00 00 0f 05 <48> 8b 3c 24 48 89 c2 e8 27 9c 01 00 48 89 d0 48 83 c4 08 48 3d 01
RSP: 002b:00007ffc058b86b0 EFLAGS: 00000293 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000556657fec630 RCX: 00007f17892db92d
RDX: 0000000000000400 RSI: 0000556657fec860 RDI: 000000000000002c
RBP: 0000000000000d68 R08: 00007f178ad11500 R09: 00000000000000e0
R10: 0000556657fecc47 R11: 0000000000000293 R12: 00007f1789596440
R13: 00007f1789595900 R14: 0000000000000019 R15: 0000000000000000


addr ffffc90000c7fb60 is located in stack of task systemd/1 at offset 40 in frame:
 mpol_to_str+0x0/0x3be mm/mempolicy.c:2924

this frame has 1 object:
 [32, 40) 'nodes'

Memory state around the buggy address:
 ffffc90000c7fa00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffffc90000c7fa80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc90000c7fb00: 00 00 00 00 00 00 00 f1 f1 f1 f1 00 f3 f3 f3 00
                                                       ^
 ffffc90000c7fb80: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00
 ffffc90000c7fc00: 00 00 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00
==================================================================


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

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

end of thread, other threads:[~2020-03-26  3:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CALzBtjLSqFhSNAf4YusxuE1piUTzOSLFGFD4RrhPLQAmgpyL5g@mail.gmail.com>
2020-03-16 18:46 ` KASAN: stack-out-of-bounds Write in mpol_to_str Randy Dunlap
     [not found]   ` <CALzBtj+8AYASaYW2fqgmgthCgeAJ2N0Q+ey2wqgEKjBtH34Vcg@mail.gmail.com>
2020-03-21  6:45     ` Andrew Morton
2020-03-26  0:54     ` Randy Dunlap
2020-03-26  0:45 ` [PATCH] mm: mempolicy: require at least one nodeid for MPOL_PREFERRED Randy Dunlap
2020-03-26  2:23 KASAN: stack-out-of-bounds Write in mpol_to_str syzbot
2020-03-26  3:47 ` Randy Dunlap

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).