linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (Oracle)" <ljs@kernel.org>
To: syzbot <syzbot+001b9efd14d3e8fac896@syzkaller.appspotmail.com>
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
	david@kernel.org,  jannh@google.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	 syzkaller-bugs@googlegroups.com, vbabka@kernel.org
Subject: Re: [syzbot] [mm?] KASAN: slab-use-after-free Read in madvise_walk_vmas
Date: Tue, 31 Mar 2026 12:54:43 +0100	[thread overview]
Message-ID: <64b4e45a-bfd6-4bbe-8774-5fc80d0d2cf1@lucifer.local> (raw)
In-Reply-To: <e1cb33b8-c1f7-4972-8628-3a2169077d6e@lucifer.local>

On Tue, Mar 31, 2026 at 12:43:32PM +0100, Lorenzo Stoakes (Oracle) wrote:
> On Tue, Mar 31, 2026 at 02:07:28AM -0700, syzbot wrote:
> > Hello,
> >
> > syzbot found the following issue on:
> >
> > HEAD commit:    e77a5a5cfe43 Add linux-next specific files for 20260326
> > git tree:       linux-next
> > console output: https://syzkaller.appspot.com/x/log.txt?x=13640f52580000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=51ca7cbda5f81780
> > dashboard link: https://syzkaller.appspot.com/bug?extid=001b9efd14d3e8fac896
> > compiler:       Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8
> >
> > Unfortunately, I don't have any reproducer for this issue yet.
> >
> > Downloadable assets:
> > disk image: https://storage.googleapis.com/syzbot-assets/63883a48e879/disk-e77a5a5c.raw.xz
> > vmlinux: https://storage.googleapis.com/syzbot-assets/cfdff9b548ab/vmlinux-e77a5a5c.xz
> > kernel image: https://storage.googleapis.com/syzbot-assets/f2e4eca37d44/bzImage-e77a5a5c.xz
> >
> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+001b9efd14d3e8fac896@syzkaller.appspotmail.com
> >
> > ==================================================================
> > BUG: KASAN: slab-use-after-free in madvise_walk_vmas+0x661/0xae0 mm/madvise.c:1726
>
> This is:
>
> 		if (vma && range->end < vma->vm_end) <-- 1726
> 			range->end = vma->vm_end;
>
> > Read of size 8 at addr ffff88803322aa08 by task syz.0.3603/14995
>
> It'd make no sense for a UAF on stack variable range, so it's vma->vm_end
> (offset lines up).
>
> So it means we have a stale vma pointer here in madvise_walk_vmas():
>
> 		error = madvise_vma_behavior(madv_behavior);
> 		if (error)
> 			return error;
> 		if (madv_behavior->lock_dropped) { <--- this is a big clue
> 			/* We dropped the mmap lock, we can't ref the VMA. */
> 			prev = NULL;
> 			vma = NULL;
> 			madv_behavior->lock_dropped = false;
> 		} else {
> 			vma = madv_behavior->vma;
> 			prev = vma;
> 		}
>
> 		if (vma && range->end < vma->vm_end)
> 			range->end = vma->vm_end;
>
> So _after_ the madvise_vma_behavior() call, we won't look at a vma if the lock
> was dropped.
>
> So perhaps we're not correctly propagating this + then getting a stale VMA pointer...
>
> (See below for analysis from registers as to why this is MADV_COLLAPSE)
>
> In madvise_colapse(), we pass the lock_dropped parameter to
> collapse_single_pmd(), which can then set the pointed-to boolean to true.
>
> But then it refreshes the vma via hugepage_vma_revalidate on the next iteration:
>
> 	for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
> 		enum scan_result result = SCAN_FAIL;
>
> 		if (*lock_dropped) {
> 			...
> 			mmap_read_lock(mm);
> 			*lock_dropped = false;
> 			result = hugepage_vma_revalidate(mm, addr, false, &vma,
> 							 cc);
> 			...
> 		}
>
> 		result = collapse_single_pmd(addr, vma, lock_dropped, cc);
>
> 		...
> 	}
>
> And something might have raced to change what that VMA is.
>
> However... coming back to madvise_walk_vmas():
>
> 		if (madv_behavior->lock_dropped) {
> 			...
> 		} else {
> 			vma = madv_behavior->vma; <-- we are reading a stale VMA...
> 			prev = vma;		  <-- ...and even assigning it to prev!
> 		}
>
> This whole 'lock dropped' notion is somewhat horrible... I guess it's really
> about detecting a gap in VMAs, which is not exactly crucial since we tolerate
> there being gaps (but return -ENOMEM for some reason to signify it).
>
> Anyway, the proximate fix here is for *lock_dropped in madvise_collapse() to
> actually be relative to whether the lock _was every dropped_ not whether it
> currently is... which is of course what the meaning always was, it's just that
> commit e24d552a17e9 ("mm/madvise: eliminate very confusing manipulation of prev
> VMA") messed this up.
>
> I'll send a fix.

Actually looks to be Nico's series - mm/khugepaged: unify khugepaged and
 madv_collapse with collapse_single_pmd() - that has the bug. Replying there.

Cheers, Lorenzo


      reply	other threads:[~2026-03-31 11:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  9:07 syzbot
2026-03-31 10:52 ` Lorenzo Stoakes (Oracle)
2026-03-31 11:43 ` Lorenzo Stoakes (Oracle)
2026-03-31 11:54   ` Lorenzo Stoakes (Oracle) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64b4e45a-bfd6-4bbe-8774-5fc80d0d2cf1@lucifer.local \
    --to=ljs@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=syzbot+001b9efd14d3e8fac896@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox