Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2045573rwb; Sun, 14 Aug 2022 19:54:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Q7s79WLLdf58tK5rxJYzlMLZDCe3DuxGk0dLmtQtM79CwHTGMNcL4VA/TZo22ffo2FtiU X-Received: by 2002:a17:907:1b0e:b0:72f:9b43:b98c with SMTP id mp14-20020a1709071b0e00b0072f9b43b98cmr9318005ejc.710.1660532051578; Sun, 14 Aug 2022 19:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660532051; cv=none; d=google.com; s=arc-20160816; b=GmMWyJAup3apOiXAO6K5vTVJe4BULg0vJQNI3rWrASpgB8Cfg1zLTGhtB0GBffisQV mXmZt5q8vC76MIhZ548CIeSLijOcUxG6MMAD+ikvXsfXR10d3BdffjtnWhDssFg74smC +HhTVTf3nl6/kFDBcUhkBwueZRWk9j4d6tvqQzoRBaUutMRSXE2J32nLAjWM/AMG7aOn HPrS8oIKYD1WxS2nfFH1BikREHry++9kcA2Msky8kyeBoFCeRAZ9TXIxUQvAm/jvhtoN HjAfJ0+KR2DQJPs+yM9t4/BGXXJu9gQQPYXTx4NkQ99RMU+tpBy2fSZudn5bfXL/aWl6 V4Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=04Ly7rVHtCVp63y7Is8m4DOrsuVX/Szmz+79w4M/yxc=; b=wiYMxPqCH4HJMZvEuSYydJwrTV/tleWTPfCZB5KEqhHLkpwXlpeYZwtVkajLjOudgX kh+N0Z5thkBhaCZyO15v3tI50A6w3I2tod0CMFeWGH17kbZ346k/zTYV/LsHuKpvItN4 YrXS9XTFTXdxh0nuUOE+8llA+I/9LBYy+8K5vCfIHaZaOnHXfZpVhrECs6b4jyzLPqhT 0v+KefhOo9CMzuRKBe2UIdkJKOip2QLzJNtF4bZ95CY4fCH5VAdsCZyYlWU3yOCtdjDI 5lJFMP2smYsJ9alM09b1bes1yoiojHkg4p456ov+tOvkpj5RjTDnUmgm7JvnUSsf8DQW 7lbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=luj+3rPh; 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=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a056402430400b0043aa8412576si7749156edc.227.2022.08.14.19.53.46; Sun, 14 Aug 2022 19:54:11 -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=@linux.org.uk header.s=zeniv-20220401 header.b=luj+3rPh; 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=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbiHOBq6 (ORCPT + 99 others); Sun, 14 Aug 2022 21:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiHOBq4 (ORCPT ); Sun, 14 Aug 2022 21:46:56 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 021B5270F for ; Sun, 14 Aug 2022 18:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=04Ly7rVHtCVp63y7Is8m4DOrsuVX/Szmz+79w4M/yxc=; b=luj+3rPhMJ1NYhS2VgcrtPh+DD 9yMwyNDUyrgEolY89SijzP9UR8j4tnRS7E4UTkxFHHOpPsvj1kbgsn5wgiol9FIn9bvFVcgrVNuT5 RfE5/cUfSdPglvRDGPj8ML68Y1GBEtfE1kTUJ5ZXcxg7DTU7Rc4YBhQ2rqGhFRBimADNMBfA7hg0/ uklvDu+hiitgYXsQ/TmIYrg+MI7C9v0WYr5Tc2EaL4RR4siMJwhb82GQfjc8o3v2Bb5HHeApoeoX9 z0zjxPd0CtDbbQAbLEl4DiF8znEVDD/X8j3b5/ePvC/XLSHbB3HV9IDadsDsq1UruifVLvHgy7+AU fbIakg3g==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1oNPBc-004OEl-1R; Mon, 15 Aug 2022 01:46:36 +0000 Date: Mon, 15 Aug 2022 02:46:36 +0100 From: Al Viro To: Greg Kroah-Hartman Cc: Christian Brauner , 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: Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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 Fri, Aug 12, 2022 at 04:32:28PM +0200, Greg Kroah-Hartman wrote: > > 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 FWIW, I would rather provide a proper ->kill_sb() and gotten rid of all that stuff. The thing is, unlike ->put_super(), ->kill_sb() is called for *anything* that has gotten to foo_fill_super(). Usually allows to get rid of those "call all of or parts of foo_put_super() on failure exits" and associated bitrot... Like this (completely untested): Signed-off-by: Al Viro --- diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 588d753a7a19..c760f3129768 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -340,22 +340,21 @@ static int binderfs_show_options(struct seq_file *seq, struct dentry *root) return 0; } -static void binderfs_put_super(struct super_block *sb) +static void binderfs_kill_super(struct super_block *sb) { struct binderfs_info *info = sb->s_fs_info; + kill_litter_super(sb); if (info && info->ipc_ns) put_ipc_ns(info->ipc_ns); kfree(info); - sb->s_fs_info = NULL; } static const struct super_operations binderfs_super_ops = { .evict_inode = binderfs_evict_inode, .show_options = binderfs_show_options, .statfs = simple_statfs, - .put_super = binderfs_put_super, }; static inline bool is_binderfs_control_device(const struct dentry *dentry) @@ -789,7 +788,7 @@ static struct file_system_type binder_fs_type = { .name = "binder", .init_fs_context = binderfs_init_fs_context, .parameters = binderfs_fs_parameters, - .kill_sb = kill_litter_super, + .kill_sb = binderfs_kill_super, .fs_flags = FS_USERNS_MOUNT, };