ceph: fix possible NULL pointer dereference for req->r_session
PATCH v2 1/1 ceph: fix possible NULL pointer dereference for req->r_session
The request will be inserted into the ci->i_unsafe_dirops before assigning the req->r_session, so it's possible that we will hit NULL pointer dereference bug here.
URL: https://tracker.ceph.com/issues/55327
--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ceph/caps.c +4 -0
@@ -2333,6 +2333,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {
@@ -2353,6 +2355,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {
Signature · 1 line
2.36.0.rc1
Quoted 24 lines · Xiubo Li
The request will be inserted into the
ci->i_unsafe_diropsbefore assigning thereq->r_session, so it's possible that we will hit NULL pointer dereference bug here.URL: https://tracker.ceph.com/issues/55327
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)fs/ceph/caps.c +2
-0@@ -2333,6 +2333,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {
fs/ceph/caps.c static int unsafe_request_wait(struct inode *inode) · line 2362
Quoted 8 lines
fs/ceph/caps.c +2
-0@@ -2353,6 +2355,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {
Quoted 34 lines · Xiubo Li
The request will be inserted into the
ci->i_unsafe_diropsbefore assigning thereq->r_session, so it's possible that we will hit NULL pointer dereference bug here.URL: https://tracker.ceph.com/issues/55327
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)fs/ceph/caps.c +4
-0@@ -2333,6 +2333,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {@@ -2353,6 +2355,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {Signature · 1 line
2.36.0.rc1
Thanks Xiubo!
Signature · 1 line
Aaron Tomlin
Quoted 34 lines · Xiubo Li
The request will be inserted into the
ci->i_unsafe_diropsbefore assigning thereq->r_session, so it's possible that we will hit NULL pointer dereference bug here.URL: https://tracker.ceph.com/issues/55327
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)fs/ceph/caps.c +4
-0@@ -2333,6 +2333,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {@@ -2353,6 +2355,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {Signature · 1 line
2.36.0.rc1
Signature · 1 line
Aaron Tomlin
Quoted 28 lines · Aaron Tomlin
Quoted 27 lines · Xiubo Li
The request will be inserted into the
ci->i_unsafe_diropsbefore assigning thereq->r_session, so it's possible that we will hit NULL pointer dereference bug here.URL: https://tracker.ceph.com/issues/55327
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 4 ++++ 1 file changed, 4 insertions(+)fs/ceph/caps.c +2
-0@@ -2333,6 +2333,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; +if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {@@ -2353,6 +2355,8 @@ static int unsafe_request_wait(struct inode *inode)list_for_each_entry (req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session;
Quoted 9 lines
Quoted 7 lines
fs/ceph/caps.c +2
-0+if (!s) +continue ;if (unlikely (s->s_mds >= max_sessions)) {spin_unlock (&ci->i_unsafe_lock);for (i =0 ; i < max_sessions; i++) {Signature · 1 line
2.36.0.rc1Tested-by Aaron Tomlin <[email protected]>
Hi Aaron,
Thanks very much for you testing.
BTW, did you test this by using Livepatch or something else ?
-- Xiubo
Quoted 1 line · Xiubo Li
Hi Aaron,
Hi Xiubo,
Quoted 1 line
Thanks very much for you testing.
No problem!
Quoted 1 line
BTW, did you test this by using Livepatch or something else ?
I mostly followed your suggestion here [1] by modifying/or patching the kernel to increase the race window so that unsafe_request_wait() may more reliably see a newly registered request with an unprepared session pointer i.e. 'req->r_session == NULL'.
Indeed, with this patch we simply skip such a request while traversing the Ceph inode's unsafe directory list in the context of unsafe_request_wait().
[1]: https://tracker.ceph.com/issues/55329
Kind regards,
Signature · 1 line
Aaron Tomlin
Quoted 7 lines · Aaron Tomlin
Quoted 1 line · Xiubo Li
Hi Aaron,
Hi Xiubo,
Quoted 1 line
Thanks very much for you testing.
No problem!
Quoted 8 lines
Quoted 1 line
BTW, did you test this by using Livepatch or something else ?
I mostly followed your suggestion here [1] by modifying/or patching the kernel to increase the race window so that
unsafe_request_wait()may more reliably see a newly registered request with an unprepared session pointer i.e. 'req->r_session== NULL'.Indeed, with this patch we simply skip such a request while traversing the Ceph inode's unsafe directory list in the context of
unsafe_request_wait().
Okay, cool.
Thanks again for your help Aaron :-)
-- Xiubo
Quoted 4 lines
[1]: https://tracker.ceph.com/issues/55329
Kind regards,
Ilya Dryomov
maintainerQuoted 16 lines · Xiubo Li
Quoted 13 lines · Aaron Tomlin
Quoted 1 line · Xiubo Li
Hi Aaron,
Hi Xiubo,
Quoted 1 line
Thanks very much for you testing.
No problem!
Quoted 1 line
BTW, did you test this by using Livepatch or something else ?
I mostly followed your suggestion here [1] by modifying/or patching the kernel to increase the race window so that
unsafe_request_wait()may more reliably see a newly registered request with an unprepared session pointer i.e. 'req->r_session== NULL'.
Quoted 15 lines
Quoted 2 lines
Indeed, with this patch we simply skip such a request while traversing the Ceph inode's unsafe directory list in the context of
unsafe_request_wait().Okay, cool.
Thanks again for your help Aaron :-)
-- Xiubo
Quoted 4 lines
[1]: https://tracker.ceph.com/issues/55329
Kind regards,
I went ahead and marked this for stable (it's already queued for -rc5).
Thanks,
Ilya
Quoted 22 lines · Ilya Dryomov
Quoted 21 lines · Xiubo Li
Quoted 7 lines · Aaron Tomlin
Quoted 1 line · Xiubo Li
Hi Aaron,
Hi Xiubo,
Quoted 1 line
Thanks very much for you testing.
No problem!
Quoted 8 lines
Quoted 1 line
BTW, did you test this by using Livepatch or something else ?
I mostly followed your suggestion here [1] by modifying/or patching the kernel to increase the race window so that
unsafe_request_wait()may more reliably see a newly registered request with an unprepared session pointer i.e. 'req->r_session== NULL'.Indeed, with this patch we simply skip such a request while traversing the Ceph inode's unsafe directory list in the context of
unsafe_request_wait().Okay, cool.
Thanks again for your help Aaron :-)
Quoted 8 lines
Quoted 7 lines
-- Xiubo
Quoted 4 lines
[1]: https://tracker.ceph.com/issues/55329
Kind regards,
I went ahead and marked this for stable (it's already queued for -rc5).
Sure, thanks Ilya.
-- Xiubo
Quoted 4 lines
Thanks,
Ilya