From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2286CC433EF for ; Tue, 12 Jul 2022 13:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80CB0940072; Tue, 12 Jul 2022 09:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BC57940063; Tue, 12 Jul 2022 09:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6ABA9940072; Tue, 12 Jul 2022 09:29:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5BAB8940063 for ; Tue, 12 Jul 2022 09:29:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 346CA604E4 for ; Tue, 12 Jul 2022 13:29:44 +0000 (UTC) X-FDA: 79678530288.24.69DC942 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf26.hostedemail.com (Postfix) with ESMTP id C6AA8140064 for ; Tue, 12 Jul 2022 13:29:43 +0000 (UTC) Received: by mail-lf1-f44.google.com with SMTP id bu42so14009645lfb.0 for ; Tue, 12 Jul 2022 06:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ank7/+L/mHMnE+3QMD4hHykXxDa+TqpdlWx4EC12KRU=; b=s3RcM+j8m46/k2eVgR8woEMqkM+wqG9kPOKHBmTKXM8HC5RpdGkj+4rPp9rNd6b7Iu YfU3nUvqIJxVhhDo9krinLiGuuJe5iKGOiOxDsPXZ+/Xr7xWQmHfCM49OhLzO4BnQ0KW a+BbcdtQ1go80SMGxbqFEfw2a31DL4iBD7udY8wA9qze2opjB+WDCwZMPlF2fV3WWSf8 fS5J673kKkrFRKSFyFWma7OSxSY7nJf8vsdQKTExjwJghv/0A9jg/bCEiNcv068Yr4LD RtlHd05ZTjGNkcVkEmGlE5h+Y78JCRweOo9qWgjgdql3l9oh+2Wd/NRdK7ntv4isEzD5 dG2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ank7/+L/mHMnE+3QMD4hHykXxDa+TqpdlWx4EC12KRU=; b=ki4luCS073fv1RKnSA2Pw5u1uGEkFtzXkfMIrCk2JprusUopgACsWcBrCo8y8hvxtk KKoa8ZLz0khQG2JhdnPuJYlkLtWzlTTBFtFehSxYSRIVcG1+fNVuvj8MYtCxURogaULP 4TaLpaH6J6QyqCVi5CHvsZUvgw9CrTpVOn3JFa/d9gU9Se5C9p353+R37Z4352Ab50X4 xaSU+sjoxcDArsRmLxpSTW43qYyPn9QueaUFwrPAJ73Kz7wEQLjlYqit6z1ILV/5/wnE neqnXhx1tmjQU5jzEP0TEeAl/JJVi/pUQAhDVZHSxnty3FH9/L/a4Bsi9Qn1o7QD1FjI LLxQ== X-Gm-Message-State: AJIora+1vw/xX2HU3JR+30EErdmHDvru2iDqrbi/DWpJfd+DUSozXLqL Av+BbBePvIgqzQSgJKkyyhrSkD2TjCNUblHU7K7pjA== X-Google-Smtp-Source: AGRyM1uLe+Eot9/Gii9FHCNSp9e4B0AO9L5cu6BJRa/gKyT6RVxluqJtSDtIZcceEkz8EFXA7UMlariTheatj1THTrk= X-Received: by 2002:ac2:4d43:0:b0:489:cb6e:b293 with SMTP id 3-20020ac24d43000000b00489cb6eb293mr12061439lfp.376.1657632582048; Tue, 12 Jul 2022 06:29:42 -0700 (PDT) MIME-Version: 1.0 References: <000000000000eb2d6c05e35a0d73@google.com> <20220711133808.d86400ce9960febcb0fd537b@linux-foundation.org> In-Reply-To: From: Dmitry Vyukov Date: Tue, 12 Jul 2022 15:29:29 +0200 Message-ID: Subject: Re: [syzbot] memory leak in xas_create To: Matthew Wilcox Cc: Andrew Morton , syzbot , linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, "Zach O'Keefe" , Yang Shi , Liam Howlett Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657632583; a=rsa-sha256; cv=none; b=XESE/ym4dNIdD7cUd8d4p4oEo8H684RZbeE+pZXqSEXmxFSdRo4Coo5v4sgFL3R+AIPR+8 dXVxgYYdnbMFI+hK23wf2mz/m2w8kdwZLltCuGdQ5PXFCpatl6hLkKTM8tv2e+37VoNA25 V5faIWQB6Sy+J0IAXV/46mDZsGNPGs4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=s3RcM+j8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of dvyukov@google.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=dvyukov@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657632583; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ank7/+L/mHMnE+3QMD4hHykXxDa+TqpdlWx4EC12KRU=; b=pe1t5TqT7aiyGmPKRVGvtFvRpwuGD0a9iH+xfGWQdVH0YDgxXiFPmUiwe1idB67iw8538/ 3LOsZWnem1N7t+d7UYSk5XblfyOhu82r3T7r3ZXrcwkDQEzfgzBgHE24jAlPN4Uiw6ox5s VTym5UpvxDMqGi/ldR4+XmmqeOascP4= X-Stat-Signature: 5a4p8c5yqdudb6x5psukn6keug7f6fbm X-Rspamd-Queue-Id: C6AA8140064 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=s3RcM+j8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of dvyukov@google.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=dvyukov@google.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1657632583-239220 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 12 Jul 2022 at 14:58, Matthew Wilcox wrote: > > > > > > On Sat, 09 Jul 2022 00:13:23 -0700 syzbot 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(). I see. Thanks for the explanation. Then I think it's still possible that this is a KMEMLEAK false positive. IIRC it may have some false positives since it does not do full stop-the-world before scanning memory/registers. syzkaller tries to circumvent this by doing multiple scans with some delays, but it does not give 100% guarantee. And I am assuming this code does not try to hide pointers by storing something in low/high bits, etc. > > 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 */ > > } > >