Skip to contentSkip to conversation

ceph: fix NULL pointer dereference for req->r_session

PATCH Superseded [email protected] 2 participants 3 messages Oct 27, 2022 – Nov 8, 2022

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: fix NULL pointer dereference for req->r_session

From: Xiubo Li <[email protected]>

The request's r_session maybe changed when it was forwarded or resent.

---
 fs/ceph/caps.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ceph/caps.c +4 -0
index 894adfb4a092..d34ac716d7fe 100644
@@ -2341,6 +2341,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
 			goto out;
 		}
 
+		mutex_lock(&mdsc->mutex);
 		spin_lock(&ci->i_unsafe_lock);
 		if (req1) {
 			list_for_each_entry(req, &ci->i_unsafe_dirops,
@@ -2350,6 +2351,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
 					continue;
 				if (unlikely(s->s_mds >= max_sessions)) {
 					spin_unlock(&ci->i_unsafe_lock);
+					mutex_unlock(&mdsc->mutex);
 					for (i = 0; i < max_sessions; i++) {
 						s = sessions[i];
 						if (s)
@@ -2372,6 +2374,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
 					continue;
 				if (unlikely(s->s_mds >= max_sessions)) {
 					spin_unlock(&ci->i_unsafe_lock);
+					mutex_unlock(&mdsc->mutex);
 					for (i = 0; i < max_sessions; i++) {
 						s = sessions[i];
 						if (s)
@@ -2387,6 +2390,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
 			}
 		}
 		spin_unlock(&ci->i_unsafe_lock);
+		mutex_unlock(&mdsc->mutex);
 
 		/* the auth MDS */
 		spin_lock(&ci->i_ceph_lock);
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 17 lines · On Thu, Oct 27, 2022 at 11:12 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

The request's r_session maybe changed when it was forwarded or resent.

---
 fs/ceph/caps.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ceph/caps.c +0 -0
index 894adfb4a092..d34ac716d7fe 100644

fs/ceph/caps.c static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode) · line 2344

Quoted 4 lines
fs/ceph/caps.c +1 -0
@@ -2341,6 +2341,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
                        goto out;
                }
 
+               mutex_lock(&mdsc->mutex);

Hi Xiubo,

A few lines above, there is the following comment:

/*
* The mdsc->max_sessions is unlikely to be changed
* mostly, here we will retry it by reallocating the
* sessions array memory to get rid of the mdsc->mutex
* lock.
*/

Does retry label and gotos still make sense if mdsc->mutex is introduced? Would it make sense to move it up and get rid of retry code?

Thanks,

Ilya

author
#2 lore raw
Quoted 32 lines · Ilya Dryomov
Quoted 16 lines · On Thu, Oct 27, 2022 at 11:12 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

The request's r_session maybe changed when it was forwarded or resent.

---
  fs/ceph/caps.c | 4 ++++
  1 file changed, 4 insertions(+)
fs/ceph/caps.c +0 -0
index 894adfb4a092..d34ac716d7fe 100644

fs/ceph/caps.c static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode) · line 2344

Quoted 4 lines
fs/ceph/caps.c +1 -0
@@ -2341,6 +2341,7 @@ static int flush_mdlog_and_wait_inode_unsafe_requests(struct inode *inode)
                         goto out;
                 }
 
+               mutex_lock(&mdsc->mutex);

Hi Xiubo,

A few lines above, there is the following comment:

/*
* The mdsc->max_sessions is unlikely to be changed
* mostly, here we will retry it by reallocating the
* sessions array memory to get rid of the mdsc->mutex
* lock.
*/

Quoted 3 lines

Does retry label and gotos still make sense if mdsc->mutex is introduced? Would it make sense to move it up and get rid of retry code?

I'm okay to remove the label since we will introduce the mdsc->mutex.

Thanks!

- Xiubo

Quoted 4 lines

Thanks,

Ilya