Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1826823rwb; Fri, 12 Aug 2022 07:28:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ne9UVeTMpwDDQpjwA+VJ3nmQitrfU/MuAZbjfNC/YTsIWQSyNLL77xgqrOolv7OGKYW6j X-Received: by 2002:aca:1e09:0:b0:33f:25e0:110a with SMTP id m9-20020aca1e09000000b0033f25e0110amr5455062oic.299.1660314497682; Fri, 12 Aug 2022 07:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660314497; cv=none; d=google.com; s=arc-20160816; b=q3xFYTPJnBDAarb6Y/UB12TNJWmoam6vis8kLl2LopvUMZobrSiK3rmksYVozaUKD9 H9yCzZSWIJe2pRDHaNqpRTwyezW7YbVWWTV441grFh35CDKm5haBDrlWFnwtY5zGaBOO Qd8aq9MxDxX3LMW2m8JpiW7PjKfDCBQCv1B+6YZTzOBkIerjWLUfiaJjBzT2S8KERdRs t7nRImL+k2rDzp9Wry6m+gLdQkhB5hIFJkJsnTfAIjqf3jmzGyifxCdpjOrunDwUbbFc SQdOf9DGL0dKoxB4IJ7Z5uLMeG1ohWpi+LMe+hjClY6F60Rs+I/s1E/SUygm1NeGxmBo hpyA== 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=xSwCD3+XMXN+QQFyqEi1dXDrB60NyPJMxQYDAcuQGhA=; b=Kc7z43sFQ/BuixJuTLvJKJMgcZ2qedxjSylywmLmydEbi5JNJ7hxj3KgVLBXEvk4KR TzHKH8rBwloZfhMXI8HlEArF3/ympCXOAgBPW3bQk/UOniy3In7e9Kz1FmN+NdGRyOju Dw2cfVAiFmc63faB/cYbAAwGVdoqLquX3vlI24wb6oELYmkVHq/3mf+MaFzDiRzmEF+6 z/z4/Ksk+5ntFgn+x0cEkIVq1iZN7v+ZLunh+IxcLkDuelwtBP5Uf9ayzBm8HeK594Zb /iSlJeWnvM3EiptQkiTx8xyWu3TvQ1xbZvb13kRipWGskvIW1AvBEAzcG2TNn7YVJAjH RkWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vLy6Ga5N; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a9d73c7000000b00636e6dea5e8si1280391otk.89.2022.08.12.07.28.05; Fri, 12 Aug 2022 07:28:17 -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=@kernel.org header.s=k20201202 header.b=vLy6Ga5N; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235068AbiHLOT1 (ORCPT + 99 others); Fri, 12 Aug 2022 10:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233383AbiHLOS5 (ORCPT ); Fri, 12 Aug 2022 10:18:57 -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 D97A788DEE for ; Fri, 12 Aug 2022 07:18:55 -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 75279611F3 for ; Fri, 12 Aug 2022 14:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DFECC433C1; Fri, 12 Aug 2022 14:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660313934; bh=LKSX97qIpVp1SoIQq8FuEbRs7glpftMTG5SDJwbiRRA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vLy6Ga5NCs8KJ1DyouPpdSmXKHe6AD/x2Ak9/dfV7GiW2WT1enm/hwQ8mJMPH0Sur yKvE86TrV7TEEgX+UP0sF6ohR1WSU0DadSbzXAhKU8lMyxThI6B5yTsNYD2gbBjChB BfHCrf3xfYxn7FSTVgaccqqkGe3SFz97NqvHTFcsBbpQPrQczYc1PIXMvNic2Qk727 NRks6WRjrWcf2cK7HAsjfwxPufkVjwKEqDQBJiG1L1YEqp4xTKbULzrWE4P2r8N3JH HGP+NBY4aNkL/tAsvPD2mAXs4egJTre21YBZBxRoaJPAxUXMI5FVDJt1r0VU19wsQI 9ao5BpmPK4gmw== Date: Fri, 12 Aug 2022 16:18:49 +0200 From: Christian Brauner To: Dongliang Mu Cc: Dongliang Mu , Greg Kroah-Hartman , Arve =?utf-8?B?SGrDuG5uZXbDpWc=?= , 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: <20220812141849.nhwpvg6vte22lg2s@wittgenstein> References: <20220812132124.2053673-1-dzm91@hust.edu.cn> <20220812134138.gpu7274yahlvr6hr@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 09:48:40PM +0800, Dongliang Mu wrote: > On Fri, Aug 12, 2022 at 9:41 PM Christian Brauner 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 > > > Signed-off-by: Dongliang Mu > > > --- > > > > Seems right but where's the full syzbot link to the issue? > > Also, wouldn't (untested) sm like the below be better?: > > I originally would like to change the order to object initialization, > but I am not sure if they can be exchanged since many *_fill_super are > ended with d_make_root. > > If you are sure about this exchange, I can resubmit a v2 patch. I think we should just always clean up the allocated memory in binderfs_fill_super() when d_make_root() fails and before via a goto block after the successful return. So we keep the cleanup in binderfs_fill_super() consistent and restricted to a single location.