Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3532810pxb; Mon, 4 Apr 2022 20:11:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwruR953q7RaSZgjeFHmZbwUzZZRtB2LmiAmwdtcCodHn7mgEHgZe0WaKsdr2iHTC8lh0kY X-Received: by 2002:a65:6e88:0:b0:382:3851:50c8 with SMTP id bm8-20020a656e88000000b00382385150c8mr1148261pgb.270.1649128307278; Mon, 04 Apr 2022 20:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649128307; cv=none; d=google.com; s=arc-20160816; b=PpanvbDKXanv/bO/7v70DpfS3wLK79qY0HZcGAIDXk+owIUm3WGpjWYD8NRIixa6eA mxu4+VsYY7cEFGkNbZHwyCwylwpoKrdi8a+qgW1ApEfDNKc3iAq6Ivii+izFYOhVA/JR nRzj3Y7Nbv6hYjXasZvbXBf7CBtygrmObkScvPAhRAkGMWJv7s5UNPUBJAjpnTLAW1GG RktjDJ2NsCEfAeKRKRw5IV3mWMqLCb4rDDYk2SMoo2djIRwwJ578p36AYv3gfVsPbltV yrfDNEOUig0UA7hsDeHwUKywJNYIq6d/jPFWAVQ5NvbmQPP4L7ICBVNDPQaN0ndBi5DL CQMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8e9m+2tuHVymxy+eRVyhtEAl/CjkmVCqdkvU7H47dv0=; b=qX0iEJ0dKeKgyvBogN10oAYO6A29m75EvgnkMH1WR57EjaaVUZSfBTz45w0Rkb+MeS Jxc8DmE0lsPVGcYA50YV/RwtSACbqpeGT5VxoBSD8wF4R64I8Rtc+IdFRCjBgzIuCuhe C/t0txg+1r98XKRtT1wdDNerpUFt0L09n1O42DdMas/uSn8tN6VSmU1st5IAZ3Jo2Sw8 BGJuTrvKFWthRDxfZ/ZJGPDf2ravyzNDnSN3QA6/nINQSw3GclP78pWEBhIQWSImkFuJ kXrSEskrDnK6fGKNGjr2JGBp9AkGkwAFIRMQRaQALJHohqEM1yjBGwThkusATVadqVmB FlqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OnKje7S9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f15-20020a170902ce8f00b00153b2d16440si1545505plg.72.2022.04.04.20.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:11:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OnKje7S9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 764D13FC879; Mon, 4 Apr 2022 18:12:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348441AbiDAOnS (ORCPT + 99 others); Fri, 1 Apr 2022 10:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348491AbiDAOed (ORCPT ); Fri, 1 Apr 2022 10:34:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80585BC7; Fri, 1 Apr 2022 07:32:44 -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 ams.source.kernel.org (Postfix) with ESMTPS id 36D09B82507; Fri, 1 Apr 2022 14:32:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B5B6C340EE; Fri, 1 Apr 2022 14:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648823562; bh=WK7tB+5PUmSKJ5UKAfBqMVxWt6Hj85EBkF01L8UeFSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OnKje7S9eL2O81Kb0vuErwJTzqd6wJsAwETNx8+Hvt71tF6hC9qdYDBbDD+EO0lha sq5Sq7c11UBiAVlorNdE9WWdfMgus+qoa2d9kgFw5YA1iIaOuXZLoRMtCWO+GPGeUN ul3B7nFNPLHgq/GRco0EZk2YEBMhpliYbL8R5OFEUmD9r7FddowHHkkGO/m+2hdnCh BteWmKSXajCpI3ml++WmLPqFo/+3AMF8ee0h5hBe7I1s8Lb7E1Uo5LoIm6o1l1/ngP TVhQXWH+ojsak6nLEQj70nIVpromwnlIswh5nfUwPSFV38GkR/t0AWlwdj3hi/qs7h /Yhk7sRKsxKwQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiubo Li , Jeff Layton , Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.17 146/149] ceph: fix memory leak in ceph_readdir when note_last_dentry returns error Date: Fri, 1 Apr 2022 10:25:33 -0400 Message-Id: <20220401142536.1948161-146-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401142536.1948161-1-sashal@kernel.org> References: <20220401142536.1948161-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Xiubo Li [ Upstream commit f639d9867eea647005dc824e0e24f39ffc50d4e4 ] Reset the last_readdir at the same time, and add a comment explaining why we don't free last_readdir when dir_emit returns false. Signed-off-by: Xiubo Li Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/dir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 133dbd9338e7..d91fa53e12b3 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -478,8 +478,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx) 2 : (fpos_off(rde->offset) + 1); err = note_last_dentry(dfi, rde->name, rde->name_len, next_offset); - if (err) + if (err) { + ceph_mdsc_put_request(dfi->last_readdir); + dfi->last_readdir = NULL; return err; + } } else if (req->r_reply_info.dir_end) { dfi->next_offset = 2; /* keep last name */ @@ -520,6 +523,12 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit(ctx, rde->name, rde->name_len, ceph_present_ino(inode->i_sb, le64_to_cpu(rde->inode.in->ino)), le32_to_cpu(rde->inode.in->mode) >> 12)) { + /* + * NOTE: Here no need to put the 'dfi->last_readdir', + * because when dir_emit stops us it's most likely + * doesn't have enough memory, etc. So for next readdir + * it will continue. + */ dout("filldir stopping us...\n"); return 0; } -- 2.34.1