Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1857571rwb; Fri, 12 Aug 2022 07:57:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qWZHbb+o58L1cZ6Cvk8GfUoHQrGC9pdf4GmBKVMeWW/GhlKTk9SwNtkv//e58jpWdcNKG X-Received: by 2002:a17:907:94c3:b0:730:9641:8dd8 with SMTP id dn3-20020a17090794c300b0073096418dd8mr3015579ejc.586.1660316262438; Fri, 12 Aug 2022 07:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660316262; cv=none; d=google.com; s=arc-20160816; b=j+k1cy3XOFu6SvAAn5Gi9Veyx/aJfKaHLRGhMkRaXrlM8JQXnJSTIS/hDWSX8pnAuG OfxnRbN1xiYPWIuEZIv7V9zvN0K04kyqSMYJiPtrG4jnkpUt8lzBZS3hxnmZJFl0zpiR z5SnBQ1mqAEfSMtCFQ8fw99xLsj7DFdC3AkgrRr2oKM2hKLVDSbkTQW9zzwyD+PySIVj VVTjkdLF6Koa4BN0hSks8MK10s8xw/ciKan8t/Awdvo+bFg/Wl+Sv0BJxXQjY30lbJOp SQEa8ADlx7KH6snqOBoF8j86aYnyIxtVPnmLsKF8/4GbftTi44VHoz3GH3XT0+lVbyF9 dCNg== 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=nDo9jxSoqsTTmKEfgmK2FMxOdzfQz7HzKWbpbCRdkZs=; b=U9tHsJuJr+2WStzk4CeDsw317Kyu4avGHu6Ed5+JKGNCAT92s6BueQqC7ZQCJ0bbDh DoWqmxVM7oCMWZRXOrWsSRNglmAian02CIV6Abv5s12HzRNmc+FnYIT0K+Cuaa/jbiRq G0WAwDSOzVSr/7yyq6R2HZ4A6Utq1aeQZ5yvByff6tDUIwjQQblFUsedtL0pkJxGMhqH qxS12yWEXOAaCdSezOhreaJwi9VPMz4KOrtB0sR0ioe/l6xktLo4WSTQepXNUIxiMPcY chdHQCB6OUSw2+W7YfkAHyZP9uRvOvJ4s9ie2TFmlbvuUBjme3rjWFVBoeNdadCZXwxd 9XBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z8UAxovA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg38-20020a170907972600b0073155d3575esi2081143ejc.804.2022.08.12.07.57.16; Fri, 12 Aug 2022 07:57:42 -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=@linuxfoundation.org header.s=korg header.b=z8UAxovA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237852AbiHLOcg (ORCPT + 99 others); Fri, 12 Aug 2022 10:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbiHLOcd (ORCPT ); Fri, 12 Aug 2022 10:32:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54007901B1 for ; Fri, 12 Aug 2022 07:32:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E278F60B3D for ; Fri, 12 Aug 2022 14:32:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9C96C433C1; Fri, 12 Aug 2022 14:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660314751; bh=/rqqYC6tk7WxEyqeuTVLmmFiz/8xN6QAqZLGMUp+wTM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=z8UAxovAeKkD/UvhTS1dZAqysq7Hj8/ptOwtPyUkSqqRKJRgmLymHLPPPxpf5x/9H gk9tfEkHXBVaXhKahZIvBJXpZxsbyIOiFuJv74N8eCF1uf36763N4fiqs3PZbTYMv1 a3tQ/MhZ2k+M9rLa0SdFZmzio7oOhezZjmD6pQI8= Date: Fri, 12 Aug 2022 16:32:28 +0200 From: Greg Kroah-Hartman To: Christian Brauner Cc: Dongliang Mu , Dongliang Mu , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Kees Cook , syzkaller , linux-kernel Subject: Re: [PATCH] drivers: binderfs: fix memory leak in binderfs_fill_super Message-ID: References: <20220812132124.2053673-1-dzm91@hust.edu.cn> <20220812142423.33wnvnjg6v2h2m3y@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220812142423.33wnvnjg6v2h2m3y@wittgenstein> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 Fri, Aug 12, 2022 at 04:24:23PM +0200, Christian Brauner wrote: > On Fri, Aug 12, 2022 at 04:09:23PM +0200, Greg Kroah-Hartman wrote: > > On Fri, Aug 12, 2022 at 09:56:46PM +0800, Dongliang Mu wrote: > > > On Fri, Aug 12, 2022 at 9:41 PM Greg Kroah-Hartman > > > wrote: > > > > > > > > On Fri, Aug 12, 2022 at 09:21:24PM +0800, Dongliang Mu wrote: > > > > > From: Dongliang Mu > > > > > > > > > > In binderfs_fill_super, if s_root is not successfully initialized by > > > > > d_make_root, the previous allocated s_sb_info will not be freed since > > > > > generic_shutdown_super first checks if sb->s_root and then does > > > > > put_super operation. The put_super operation calls binderfs_put_super > > > > > to deallocate s_sb_info and put ipc_ns. This will lead to memory leak > > > > > in binderfs_fill_super. > > > > > > > > > > Fix this by invoking binderfs_put_super at error sites before s_root > > > > > is successfully initialized. > > > > > > > > > > Fixes: 095cf502b31e ("binderfs: port to new mount api") > > > > > Reported-by: syzkaller > > > > > > > > Where is the specific syzkaller link for this report? It would be good > > > > to reference it so it can be properly checked. > > > > > > > > Also, how did you test this change? > > > > > > I found this memory leak in my local syzkaller, and there is no any > > > syzbot report about this crash, therefore I use such a Reported-by to > > > indicate. > > > > > > Although my local syzkaller does generate any reproducer, this bug can > > > be triggered by injecting faults at new_inode and d_make_root (i.e., > > > between s_sb_info allocation and code after d_make_root). > > > > > > > > > > > > Signed-off-by: Dongliang Mu > > > > > --- > > > > > drivers/android/binderfs.c | 8 ++++++-- > > > > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c > > > > > index 588d753a7a19..20f5bc77495f 100644 > > > > > --- a/drivers/android/binderfs.c > > > > > +++ b/drivers/android/binderfs.c > > > > > @@ -710,8 +710,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc) > > > > > info->mount_opts.stats_mode = ctx->stats_mode; > > > > > > > > > > inode = new_inode(sb); > > > > > - if (!inode) > > > > > + if (!inode) { > > > > > + binderfs_put_super(sb); > > > > > return -ENOMEM; > > > > > + } > > > > > > > > > > inode->i_ino = FIRST_INODE; > > > > > inode->i_fop = &simple_dir_operations; > > > > > @@ -721,8 +723,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc) > > > > > set_nlink(inode, 2); > > > > > > > > > > sb->s_root = d_make_root(inode); > > > > > - if (!sb->s_root) > > > > > + if (!sb->s_root) { > > > > > + binderfs_put_super(sb); > > > > > return -ENOMEM; > > > > > + } > > > > > > > > How did you test this change to verify that you are not now just leaking > > > > memory? It looks to me like you just changed one problem for another > > > > one :( > > > > > > As mentioned above, I just tested my change by injecting faults at > > > new_inode and d_make_root. > > > > > > Can you explain more about "changed one problem for another one"? I > > > don't quite understand this statement. > > > > I think you are leaking memory in at least your second change here, > > possibly the first, I didn't look at the code very closely. > > It's a bit tricky to follow but d_make_root() always consumes the inode. > On success via d_instantiate() and on failure via iput(). So when > d_make_root() has been called the inode is off limits. And as soon as > d_make_root() has returned successfully we're guaranteed that > sb->s_fs_info is cleaned up if a ->put_super() method has been defined. > Just fyi. Ah, thanks, that wasn't obvious at all. greg k-h