Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4815037yba; Tue, 30 Apr 2019 04:59:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0RSbfvGHmujh3UW9N8PMElIAN+lKjrn9UCDFVQEd1AykqYgyrYJWSTuv48gff/AwQQWi5 X-Received: by 2002:aa7:86ce:: with SMTP id h14mr23023762pfo.84.1556625554362; Tue, 30 Apr 2019 04:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625554; cv=none; d=google.com; s=arc-20160816; b=VVUk5edYbL2SFbsn78DMCASxhuBnkgW1joQxi8Q/VS5y0s5WrtDwM4ZNQZYl5c3gTh pTmdjDVOXqJvADxOt4lzzio0wkONbNVNBrKmwlrNyMFGTJ/Q43egP1G45wqB0eKwBdYw jnBRExFFk96jCG6PdIrmn+HCw/OlN6F4VKKMK+dV3uVUSMExb7lsQV/n6CLRtWhC+jhv mKwFCd4Glih/hAQmplMpicv2XPD20Xa1wsY4uehnJxrwskdCvdWHPIGBLIvntBAcXzGl zMHTjsRMKyDLpRhICe5ap6lZeBm9H0DEN7srWuq77uU1XLiI2rIMBz922VoOZQLdkDUT Zaaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L6DPU/9+C+tJjKMPfb4g55yfiRKUfcRKc07YoXuNoXI=; b=sWLMhEjEvUW3AIRyavoaBTGUkwbzJWE1aMYuBQ0SbuXYgOcgQfslVaRvru7m3eUzTJ MYAywsx+u4bJmqckl5UwCABqF+dqRhevQLirfyTdOl9xcDsdYuFsxU/hdl1JkQkxovoV Qn8ZPZZOqcfbI1RCG8ujHDsnpz1r5bNMPJYMy4Svr5efXGMNcHL/gTfjKo4LdHTZt9U7 /iebPFz3yMlQZiQyiweGn2EwOBPiElvDlLtZTFtvASi9JaxCXu5ITapLoSA66bYtOuZv KLZXWXHkc+/8n6slCRMPxB9c81Pd8MRuIQHCn6eumrIrJtlgOGMj9peuu/19yHcI+zsx 5sgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dMUoMc/T"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si23450534pgb.401.2019.04.30.04.58.59; Tue, 30 Apr 2019 04:59:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dMUoMc/T"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727163AbfD3L4O (ORCPT + 99 others); Tue, 30 Apr 2019 07:56:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:35292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfD3Ls5 (ORCPT ); Tue, 30 Apr 2019 07:48:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 261EA20449; Tue, 30 Apr 2019 11:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624936; bh=fNU+POHS0F6DCbGOR6/viQQKgNCjWVnUZmiRFkNT+Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dMUoMc/TwwQKaBuE14O6/tqU8UD/J8PNoWMBRUKYxvz4Ejtequ4hHrfaaAsUvktf0 qv6SmhCACz+eiXyRNeKZuSKLdCz5+KMpGX5nooEFMhJZnCHChxNyUpqcdo9q1af9Rx V2LKHQumdhH1hSOfBzF0BJZ/LIWjOU3WuXK0zA+U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Yan, Zheng" , Ilya Dryomov , Luis Henriques Subject: [PATCH 5.0 29/89] ceph: fix ci->i_head_snapc leak Date: Tue, 30 Apr 2019 13:38:20 +0200 Message-Id: <20190430113611.316091671@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yan, Zheng commit 37659182bff1eeaaeadcfc8f853c6d2b6dbc3f47 upstream. We missed two places that i_wrbuffer_ref_head, i_wr_ref, i_dirty_caps and i_flushing_caps may change. When they are all zeros, we should free i_head_snapc. Cc: stable@vger.kernel.org Link: https://tracker.ceph.com/issues/38224 Reported-and-tested-by: Luis Henriques Signed-off-by: "Yan, Zheng" Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/mds_client.c | 9 +++++++++ fs/ceph/snap.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1286,6 +1286,15 @@ static int remove_session_caps_cb(struct list_add(&ci->i_prealloc_cap_flush->i_list, &to_remove); ci->i_prealloc_cap_flush = NULL; } + + if (drop && + ci->i_wrbuffer_ref_head == 0 && + ci->i_wr_ref == 0 && + ci->i_dirty_caps == 0 && + ci->i_flushing_caps == 0) { + ceph_put_snap_context(ci->i_head_snapc); + ci->i_head_snapc = NULL; + } } spin_unlock(&ci->i_ceph_lock); while (!list_empty(&to_remove)) { --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -568,7 +568,12 @@ void ceph_queue_cap_snap(struct ceph_ino old_snapc = NULL; update_snapc: - if (ci->i_head_snapc) { + if (ci->i_wrbuffer_ref_head == 0 && + ci->i_wr_ref == 0 && + ci->i_dirty_caps == 0 && + ci->i_flushing_caps == 0) { + ci->i_head_snapc = NULL; + } else { ci->i_head_snapc = ceph_get_snap_context(new_snapc); dout(" new snapc is %p\n", new_snapc); }