From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19D3B79C0 for ; Wed, 30 Nov 2022 18:33:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62D21C433C1; Wed, 30 Nov 2022 18:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669833206; bh=Ht+mTh03eCXV89tmVLGxPNHo0irBxFtXjiwHIFAxXl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mGy73u7oCwP5K0yZSpKmVBvTW8emB9r8u6D31xfsyeS4LDglDts657B9a//xHwCTP zsLOErL/WSFo7ZYXGNnEbiDzS0jOHKKKQrw4XZMCJoyaHU9pAlO2gKS77deGQbWPFt /BpqrgIcxZZ0p45Q7H5eQdmne9HOUQ3sy9EyDjwI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiubo Li , Ilya Dryomov , Sasha Levin Subject: [PATCH 5.15 025/206] ceph: avoid putting the realm twice when decoding snaps fails Date: Wed, 30 Nov 2022 19:21:17 +0100 Message-Id: <20221130180533.635753254@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130180532.974348590@linuxfoundation.org> References: <20221130180532.974348590@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Xiubo Li [ Upstream commit 51884d153f7ec85e18d607b2467820a90e0f4359 ] When decoding the snaps fails it maybe leaving the 'first_realm' and 'realm' pointing to the same snaprealm memory. And then it'll put it twice and could cause random use-after-free, BUG_ON, etc issues. Cc: stable@vger.kernel.org Link: https://tracker.ceph.com/issues/57686 Signed-off-by: Xiubo Li Reviewed-by: Ilya Dryomov Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/snap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index ae9cf37374e3..b512c82f9ccd 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -705,7 +705,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, struct ceph_mds_snap_realm *ri; /* encoded */ __le64 *snaps; /* encoded */ __le64 *prior_parent_snaps; /* encoded */ - struct ceph_snap_realm *realm = NULL; + struct ceph_snap_realm *realm; struct ceph_snap_realm *first_realm = NULL; struct ceph_snap_realm *realm_to_rebuild = NULL; int rebuild_snapcs; @@ -716,6 +716,7 @@ int ceph_update_snap_trace(struct ceph_mds_client *mdsc, dout("update_snap_trace deletion=%d\n", deletion); more: + realm = NULL; rebuild_snapcs = 0; ceph_decode_need(&p, e, sizeof(*ri), bad); ri = p; -- 2.35.1