[PATCH] ceph: Fix xattr buffer leak in __send_cap()

Wentao Liang posted 1 patch 1 week ago
fs/ceph/caps.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] ceph: Fix xattr buffer leak in __send_cap()
Posted by Wentao Liang 1 week ago
__prep_cap() takes a reference on the xattr blob via ceph_buffer_get()
and also grabs a reference to the old xattr blob returned by
__ceph_build_xattrs_blob(). These references are normally dropped in
__send_cap() after the cap message has been sent, but when ceph_msg_new()
fails, __send_cap() requeues the cap and returns early without dropping
them, leaking both buffers on every allocation failure.

Release arg->old_xattr_buf and arg->xattr_buf on the ceph_msg_new()
failure path before returning.

Fixes: 16d68903f56a ("ceph: break up send_cap_msg")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 fs/ceph/caps.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index d51454e995a8..41eb52b4673a 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1535,6 +1535,8 @@ static void __send_cap(struct cap_msg_args *arg, struct ceph_inode_info *ci)
 		spin_lock(&ci->i_ceph_lock);
 		__cap_delay_requeue(arg->session->s_mdsc, ci);
 		spin_unlock(&ci->i_ceph_lock);
+		ceph_buffer_put(arg->old_xattr_buf);
+		ceph_buffer_put(arg->xattr_buf);
 		return;
 	}
 
-- 
2.34.1