Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1547757rwb; Mon, 7 Nov 2022 03:00:48 -0800 (PST) X-Google-Smtp-Source: AMsMyM662aHSEQ/kkynClVox6YvNw9+INQhx6r1PGFhMmmDkHuQ402TqHDFY9EKfaUZDXCpAurWU X-Received: by 2002:a05:6402:1553:b0:461:539d:9b88 with SMTP id p19-20020a056402155300b00461539d9b88mr48522729edx.286.1667818848467; Mon, 07 Nov 2022 03:00:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667818848; cv=none; d=google.com; s=arc-20160816; b=pKanL9LCqq7WxcEOBziYGR/mTdQ0isXQ7EsAm4c0406Jt4R/2lXxQNHYDk7WAxe0jt ETNvByGvIbP2TDx1KI9X579xa8RGO/+soP9KrMgD9MWXBaL5HqluHlv9hcweaPFdyLqq hc6UCgV7dzb0zbqbl8qg0G7k9+rwLFgpee6tyWvGJqLG9Z5qAdBucahjMaKkzy1STBh0 Z0emvM1WE8a3gLfEr3djlZwPBsfnlmncJvoLwHWMjv+fKk0oMeYvh7oOqoV+3+l5WuJh NeC6MUQZH0JR2J9u1s4rbSaJl4xALzW7K4H9GUCbsRWg00/nrKvVR+ncmAscCK8B429R 7w/g== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=jCn4MseqJcnTtCYiGPVCPesbMSniSjoMzrXJhKB4vOo=; b=n5FVxpecYU6zjOl34RpNXGHAUrWmkLXhNTb7al7y8lqWHTetGKS3+Gc7z7ZtQcCzBA rM4EZxWbyKNOxkkgMp+F99isaJmTBRZE/yOALZ6kTP+cYYn3zcZfbBQDbT/hUoAADKmZ gciP7jt1er3sbNKpcJWi2osVmmTEgVtB8PfzMweOLMvLywC1gTqff9crXCo6WcpIxM10 pnXr6D0lqt4XszPkO8rzeaeGYwgP2XzjhKg0jXVHoGb89YAuRPCQH65guJ1ELAFl0dSL BJqW7wEcHEQvWmyIunkR2gc3rX7YKmczc52X4UjXREoc26lbKg5ZYaF6vbbvOgzWPa+b LKaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=XaQBv0h9; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb6-20020a1709070a0600b00781bbff1cc1si8609623ejc.455.2022.11.07.03.00.24; Mon, 07 Nov 2022 03:00:48 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=XaQBv0h9; dkim=neutral (no key) header.i=@suse.de; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbiKGKXC (ORCPT + 93 others); Mon, 7 Nov 2022 05:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231243AbiKGKWm (ORCPT ); Mon, 7 Nov 2022 05:22:42 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01D4183BD; Mon, 7 Nov 2022 02:22:41 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 53678225CC; Mon, 7 Nov 2022 10:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667816560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jCn4MseqJcnTtCYiGPVCPesbMSniSjoMzrXJhKB4vOo=; b=XaQBv0h9JvOYe7ohJxNKojp4Gtl5Alz8BCNE73/RUsBKadqlIIfNqd7q4NI0AFPJ/SDHDs mEKdVd97gJJo2+CmnHBqB9rq/ePUz3+wytLxKPYfcWdtSLCVMvYV6FdGmJJtDYrp4GYdYF jMWdzsuBq9Zz30AOd1MfRbQGuukHvmk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667816560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jCn4MseqJcnTtCYiGPVCPesbMSniSjoMzrXJhKB4vOo=; b=g7JjvHSdfn1Wj9M/78AHzwkucfxbJUA4DRoLNUT68gTUjyaBkgq+AKVKY8vbi7Wv6/9aDf ZBlnYrFLauvWwmCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EE47C13AC7; Mon, 7 Nov 2022 10:22:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yXU8N2/caGMibQAAMHmgww (envelope-from ); Mon, 07 Nov 2022 10:22:39 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 6389e19a; Mon, 7 Nov 2022 10:23:41 +0000 (UTC) Date: Mon, 7 Nov 2022 10:23:41 +0000 From: =?iso-8859-1?Q?Lu=EDs?= Henriques To: Xiubo Li Cc: Ilya Dryomov , Jeff Layton , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ceph: fix memory leak in mount error path when using test_dummy_encryption Message-ID: References: <20221103153619.11068-1-lhenriques@suse.de> <700018a6-aff7-6e7a-98df-2fc8cca39acb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <700018a6-aff7-6e7a-98df-2fc8cca39acb@redhat.com> 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_PASS 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 Mon, Nov 07, 2022 at 03:47:23PM +0800, Xiubo Li wrote: > > On 03/11/2022 23:36, Lu?s Henriques wrote: > > Because ceph_init_fs_context() will never be invoced in case we get a > > mount error, destroy_mount_options() won't be releasing fscrypt resources > > with fscrypt_free_dummy_policy(). This will result in a memory leak. Add > > an invocation to this function in the mount error path. > > > > Signed-off-by: Lu?s Henriques > > --- > > fs/ceph/super.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/fs/ceph/super.c b/fs/ceph/super.c > > index 2224d44d21c0..6b9fd04b25cd 100644 > > --- a/fs/ceph/super.c > > +++ b/fs/ceph/super.c > > @@ -1362,6 +1362,7 @@ static int ceph_get_tree(struct fs_context *fc) > > ceph_mdsc_close_sessions(fsc->mdsc); > > deactivate_locked_super(sb); > > + fscrypt_free_dummy_policy(&fsc->fsc_dummy_enc_policy); > > Hi Luis, > > BTW, any reason the following code won't be triggered ? > > deactivate_locked_super(sb); > > ? --> fs->kill_sb(s); > > ??????? --> ceph_kill_sb() > > ????????????? --> kill_anon_super() > > ??????????????????? --> generic_shutdown_super() > > ????????????????????????? --> sop->put_super() > > ??????????????????????????????? --> ceph_put_super() > > ????????????????????????????????????? --> ceph_fscrypt_free_dummy_policy() > > ?????????????????????????????????????????? --> fscrypt_free_dummy_policy( > Here's what I'm seeing here: sys_mount->path_mount->do_new_mount->vfs_get_tree->ceph_get_tree ceph_get_tree() fails due to ceph_real_mount() returning an error. My understanding is that that, since fc->root is never set, that code path will never be triggered. Does that make sense? An easy way to reproduce is by running fstest ceph/005 with the 'test_dummy_encryption' option. (I'll probably need to send a patch to disable this test when this option is present.) Cheers, -- Lu?s