Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4345137imw; Tue, 12 Jul 2022 06:28:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uz6eB4Ldcd+i/4evgHGQmuRdUqRZcBdZ/6CScYgMXDhDPtG2UfgchdpQKs0jIvyP1zGYXi X-Received: by 2002:a17:907:2e0d:b0:72b:8cd4:ca52 with SMTP id ig13-20020a1709072e0d00b0072b8cd4ca52mr814156ejc.541.1657632539340; Tue, 12 Jul 2022 06:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657632539; cv=none; d=google.com; s=arc-20160816; b=k6ymIE51azPjbFLtzFjXyE/p/VgaZlwtcSQQajiKVZBEoFnDWgSEHg+Urac5fp+uwE hrFCbY8SgQ+iylvorp1jzASr2QzhR6FdVx5SMXHveyVK5m9FWQ+csKLNSJq7aA8GA9MB NCz4V+I9X/FC7T6YJfSSA7Sv4KTBZK3OxQXeAlh7clsaOjtokBSBKguzEPjge4e60ENX W6CkZVlbY7I/6S+QoW88RAILtZwbb1qxzWADWEvvt8VMG/gxZwYTgKkD+pyB32S4jDfT Lb6cz+6W7euGcfkMClT0L9cvGQ0ZXZ1OWrt04OiIQ/s4b+o7J/BiUE7mrQktRuuawNGT i5zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AdhEHYr8+2vzJ5ieaWHpDyda90wFHDOWzppwqyUC9n8=; b=cEc8KcaKTeRC2grneHdwv/HFqROukzaeb5IJEsKl/oJESJM1ZJC6wBFRuQtIfVOlwb F/OZdS7239jRJyir65Kyd7yHfGrlWZjYRHWeHgzT8OTHDb7bFcFZeNOkUoYdZPBBp3lk i+9RjPKkHYXyXzlEJV2KdqSo/VSMZqjytLe0Or3COoUxaXEZvjfR0crg7HB5rWwfiG4p ukGbiUK6D9JxA4l1iYe79+fsv3nqh4q/hjqaYB4PIpBw/1MP1dHSe+BuxPJOAhidhXTd 3A9UlJQWXFWq6F49EeNtXNY5TmIc8E38xUe3F9mBGTAsOybM946ecDj0plfIS8f1fSxu xhdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Pv9rMtaJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs31-20020a1709072d1f00b0072b40db0091si12912151ejc.901.2022.07.12.06.28.34; Tue, 12 Jul 2022 06:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Pv9rMtaJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbiGLM6M (ORCPT + 99 others); Tue, 12 Jul 2022 08:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiGLM6K (ORCPT ); Tue, 12 Jul 2022 08:58:10 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3747DAA761 for ; Tue, 12 Jul 2022 05:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=AdhEHYr8+2vzJ5ieaWHpDyda90wFHDOWzppwqyUC9n8=; b=Pv9rMtaJNlryzmYE7km5XCMOam vdHV/99a/k+NILfGven3UhK9+SDXJfEE7RVvca24Vqj2Yoj22TI8zjqQiorYc6Q24/f4eYNVJ00R7 mft5zWm26mvW0iKvcuPGf++H0oeU4JNUnEGRp2gFWwVjveB5erlus28bF0qEHFuTTbQ+/KKSVhAZK st3Sz7vnbCHGUSLUA2B4ruuUA9BJWn1yggNtRQactz076eGLOcmSrW8QQcRe4ltCZz3TdFUHMKyK8 eGufGrV7yIoJv7KnEIGXSdHogVZgqx8/0EDxDpsMKVcJ3wTtVl2aO2amUFFd3PzQKbfsJOENcmsf8 5dJL8TCw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oBFSi-006w3J-0m; Tue, 12 Jul 2022 12:58:00 +0000 Date: Tue, 12 Jul 2022 13:57:59 +0100 From: Matthew Wilcox To: Dmitry Vyukov Cc: Andrew Morton , syzbot , linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Zach O'Keefe , Yang Shi , Liam Howlett Subject: Re: [syzbot] memory leak in xas_create Message-ID: References: <000000000000eb2d6c05e35a0d73@google.com> <20220711133808.d86400ce9960febcb0fd537b@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2022 at 02:50:50PM +0200, Dmitry Vyukov wrote: > On Tue, 12 Jul 2022 at 14:40, Matthew Wilcox wrote: > > > > On Tue, Jul 12, 2022 at 08:54:28AM +0200, Dmitry Vyukov wrote: > > > On Mon, 11 Jul 2022 at 22:47, Matthew Wilcox wrote: > > > > > > > > On Mon, Jul 11, 2022 at 01:38:08PM -0700, Andrew Morton 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(). > 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 */ > } >