Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1861325rwb; Mon, 7 Nov 2022 06:39:40 -0800 (PST) X-Google-Smtp-Source: AMsMyM5DqMQ31SBSM9MlvPqKFzl+f+T6hrW7OY5ver/MKaq6kA9M69ar/zkBLD4fjyJOEcvpXiiA X-Received: by 2002:a17:906:d550:b0:7ad:d2f1:dba5 with SMTP id cr16-20020a170906d55000b007add2f1dba5mr39858238ejc.52.1667831980613; Mon, 07 Nov 2022 06:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667831980; cv=none; d=google.com; s=arc-20160816; b=nhXiD9HT8uW0oZzkEqLj1Jxv5dwMnhYF9G+28sA9WufM0LnI0tR+4/twbO0G7qsuof ZOSjUg3Wkl56WhUmgO62xjqyUw4t4NYX1F88TdjCdjhBEak6uhRGtcaNr/iRzCCw/zg9 uiKsVasd8QEbpHSy1VhOTAqiWDleu8OlfaEZtKjs+vapcRQWbw7xMCXRQTunV5d5Cffm l5aWMORDRKhKryx/Yl6wzuuNiMQ/U2Qbtq9H8rNWgZBNfm5pxQ2UGN5Tg1qpQJQXpllU r8SRafJ05fTFTu1MNcz1wTKC30LXEWH0UO+AMkcsYtg8Rvv8bPuT9GcM5b1ZKpqA6EMI L0Gw== 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=BzbeyYPbtBw8LVTX64f3cWA5jLyoWj4oXaSt5h5zwWc=; b=Z2VIr63ZlLF3kLlB2wUVCELAGy1eXT2n0Qig1O1m7o61MKPDc7+K1zUADEGBAeuM1c RLH09ANzMDmzojOqz/F6SgTLm8TxwTlznaXIlOUHcVXnJEizhiE5Rwf3fV+idaioHW+Q drqSQgtpBwDEilj9C34HqAmp212dP+qEzKCs/6Z0dPClBLj4wDiByRNsarkEx+f0hmlm OX6u/QdOtrjX4p8iV/98xgywRHYgPDyI5yljb0+kM6Ua2HEMTBIx1XzBPQqvqP7RNqbq 0CpvLIPb+wd52cJlyVYS5xVw3cBfxgm/MysKShs2e3sO77CISpgc3Mki96lHofKS0fR5 UllA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=GGD109BA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=PkwPW0+0; 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 i5-20020a50fc05000000b00458cdba7a90si8774369edr.471.2022.11.07.06.39.17; Mon, 07 Nov 2022 06:39:40 -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=GGD109BA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=PkwPW0+0; 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 S232365AbiKGOX5 (ORCPT + 93 others); Mon, 7 Nov 2022 09:23:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbiKGOXa (ORCPT ); Mon, 7 Nov 2022 09:23:30 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC71921E07; Mon, 7 Nov 2022 06:19:03 -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 7EB932256B; Mon, 7 Nov 2022 14:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667830720; 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=BzbeyYPbtBw8LVTX64f3cWA5jLyoWj4oXaSt5h5zwWc=; b=GGD109BAu6OPXIylnJAjbchYTdSb5/0beisb6lxThAAnNti1QO3qkt8uBlbhKeShdC9tH7 tBBw4D3isD77FFDtdYZgHyOVfRnQ18tUbAr57x6C2t5GQrSBMLmLTUBJ46ktaQdgmRHqGF xDybEVAvRirNa2r5s+CWy9F026ezivQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667830720; 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=BzbeyYPbtBw8LVTX64f3cWA5jLyoWj4oXaSt5h5zwWc=; b=PkwPW0+0++nnnZahIa84De2rCz+dKr3Ei4VB7qHOlGk5Ntc8wDcPJHEjAppN+CgQ6t1g7G J6pUUqWuXABz1uAw== 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 18B6F13AC7; Mon, 7 Nov 2022 14:18:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WHSvAsATaWPbeAAAMHmgww (envelope-from ); Mon, 07 Nov 2022 14:18:40 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id c4a3af34; Mon, 7 Nov 2022 14:19:41 +0000 (UTC) Date: Mon, 7 Nov 2022 14:19: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: 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 07:06:40PM +0800, Xiubo Li wrote: > > On 07/11/2022 18:23, Lu?s Henriques wrote: > > 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? > > Okay, you are right! > > How about fixing it in ceph_real_mount() instead ? Sure, I can send a patch for doing that instead. However, my opinion is that it makes more sense to do it, mostly because ceph_get_tree() is already doing clean-up work on the error path (ceph_mdsc_close_sessions() and deactivate_locked_super()). But let me know if you really prefer doing in ceph_read_mount() and I'll send v2. > > > > 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.) > > Anyway this should be fixed in kceph. Yes, agreed. Cheers, -- Lu?s