From: Matthew Wilcox <willy@infradead.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
syzbot <syzbot+a785d07959bc94837d51@syzkaller.appspotmail.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
syzkaller-bugs@googlegroups.com,
Zach O'Keefe <zokeefe@google.com>, Yang Shi <shy828301@gmail.com>,
Liam Howlett <liam.howlett@oracle.com>
Subject: Re: [syzbot] memory leak in xas_create
Date: Tue, 12 Jul 2022 13:57:59 +0100 [thread overview]
Message-ID: <Ys1v1548IkSJ45F/@casper.infradead.org> (raw)
In-Reply-To: <CACT4Y+Z44fS04StzMh+sfUWo-k5sjYf3VGhhK2ppkHP=9RZQEw@mail.gmail.com>
On Tue, Jul 12, 2022 at 02:50:50PM +0200, Dmitry Vyukov wrote:
> On Tue, 12 Jul 2022 at 14:40, Matthew Wilcox <willy@infradead.org> wrote:
> >
> > On Tue, Jul 12, 2022 at 08:54:28AM +0200, Dmitry Vyukov wrote:
> > > On Mon, 11 Jul 2022 at 22:47, Matthew Wilcox <willy@infradead.org> wrote:
> > > >
> > > > On Mon, Jul 11, 2022 at 01:38:08PM -0700, Andrew Morton wrote:
> > > > > On Sat, 09 Jul 2022 00:13:23 -0700 syzbot <syzbot+a785d07959bc94837d51@syzkaller.appspotmail.com> wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > syzbot found the following issue on:
> > > > > >
> > > > > > HEAD commit: c1084b6c5620 Merge tag 'soc-fixes-5.19-2' of git://git.ker..
> > > > > > git tree: upstream
> > > > > > console output: https://syzkaller.appspot.com/x/log.txt?x=14967ccc080000
> > > > > > kernel config: https://syzkaller.appspot.com/x/.config?x=916233b7694a38ff
> > > > > > dashboard link: https://syzkaller.appspot.com/bug?extid=a785d07959bc94837d51
> > > > > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> > > > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=122ae834080000
> > > > > >
> > > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > > > > > Reported-by: syzbot+a785d07959bc94837d51@syzkaller.appspotmail.com
> > > > > >
> > > > > > 2022/07/05 05:22:17 executed programs: 828
> > > > > > 2022/07/05 05:22:23 executed programs: 846
> > > > > > 2022/07/05 05:22:30 executed programs: 866
> > > > > > 2022/07/05 05:22:37 executed programs: 875
> > > > > > BUG: memory leak
> > > > >
> > > > > Thanks. Presumably due to khugepaged changes.
> > > >
> > > > Huh, I was expecting it to be something I'd messed up. I've been
> > > > looking at it today, but no luck figuring it out so far.
> > > >
> > > > > Can we expect a bisection search?
> > > >
> > > > We only have a syz reproducer so far, and if I understand correctly,
> > > > it's probably because this is a flaky test (because it's trying to
> > > > find something that's a race condition).
> > > >
> > > > I expect a bisection search to go badly wrong if this is true.
> > >
> > > Is it possible that parts of xas are not freed on the error paths?
> > > I don't immediately see where anything is freed on these error paths:
> > >
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/xarray.c?id=c1084b6c5620a743f86947caca66d90f24060f56#n681
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/xarray.c?id=c1084b6c5620a743f86947caca66d90f24060f56#n721
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/khugepaged.c?id=c1084b6c5620a743f86947caca66d90f24060f56#n1675
> >
> > There's nothing to free; if a node is allocated, then it's stored in
> > the tree where it can later be found and reused.
>
> What I was thinking of is:
>
> The leaked memory is allocated with:
> xas_create_range(&xas);
> here:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/khugepaged.c?id=c1084b6c5620a743f86947caca66d90f24060f56#n1670
>
> So I assumed the nodes stored in the xas object, which is local to the
> collapse_file() function.
Yes, that's a reasonable thing to think, but it's actually not how
it works. When we allocate a node in xas_create(), we put it straight
into the tree without storing it in xas->xa_alloc. We may then end
up not using it, but the node isn't leaked because it's in the tree.
If the GFP_NOWAIT allocation fails (it didn't in these stack traces),
we call xas_nomem(), which sees an -ENOMEM, allocates a node and stores
it in xas->xa_alloc; then we go round the loop again where xas_create()
will take the node from xas->xa_alloc. But the backtraces here don't
implicate xas_nomem().
> So if we do "goto out" here:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/khugepaged.c?id=c1084b6c5620a743f86947caca66d90f24060f56#n1676
>
> There does not seem to be anything that frees anything stored in the xas:
>
> out:
> VM_BUG_ON(!list_empty(&pagelist));
> if (!IS_ERR_OR_NULL(*hpage))
> mem_cgroup_uncharge(page_folio(*hpage));
> /* TODO: tracepoints */
> }
>
next prev parent reply other threads:[~2022-07-12 12:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-09 7:13 [syzbot] memory leak in xas_create syzbot
2022-07-11 20:38 ` Andrew Morton
2022-07-11 20:46 ` Matthew Wilcox
2022-07-12 6:54 ` Dmitry Vyukov
2022-07-12 12:40 ` Matthew Wilcox
2022-07-12 12:50 ` Dmitry Vyukov
2022-07-12 12:57 ` Matthew Wilcox [this message]
2022-07-12 13:29 ` Dmitry Vyukov
2022-07-14 16:27 ` Matthew Wilcox
2022-07-12 13:35 ` Matthew Wilcox
2022-11-06 23:26 ` syzbot
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=Ys1v1548IkSJ45F/@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=syzbot+a785d07959bc94837d51@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=zokeefe@google.com \
/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;
as well as URLs for NNTP newsgroup(s).