ceph: fix race in concurrent __ceph_remove_cap invocations
PATCH 1/1 ceph: fix race in concurrent __ceph_remove_cap invocations
A NULL pointer dereference may occur in __ceph_remove_cap with some of the callbacks used in ceph_iterate_session_caps, namely trim_caps_cb and remove_session_caps_cb. These aren't protected against the concurrent execution of __ceph_remove_cap.
Since the callers of this function hold the i_ceph_lock, the fix is simply a matter of returning immediately if caps->ci is NULL.
Based on a patch from Jeff Layton.
Cc: [email protected]
URL: https://tracker.ceph.com/issues/43272
--- fs/ceph/caps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
fs/ceph/caps.c +9 -2
@@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) {struct ceph_mds_session *session = cap->session;struct ceph_inode_info *ci = cap->ci; -struct ceph_mds_client *mdsc = -ceph_sb_to_client (ci->vfs_inode.i_sb)->mdsc; +struct ceph_mds_client *mdsc;int removed =0 ; +/* 'ci' being NULL means he remove have already occurred */ +if (!ci) { +dout ("%s: cap inode is NULL\n" , __func__); +return ; + } +dout ("__ceph_remove_cap %p from %p\n" , cap, &ci->vfs_inode); + mdsc =ceph_inode_to_client (&ci->vfs_inode)->mdsc; +/* remove from inode's cap rbtree, and clear auth cap */ rb_erase (&cap->ci_node, &ci->i_caps);if (ci->i_auth_cap == cap) {
Quoted 43 lines · Luis Henriques
A NULL pointer dereference may occur in
__ceph_remove_capwith some of the callbacks used inceph_iterate_session_caps, namelytrim_caps_cbandremove_session_caps_cb. These aren't protected against the concurrent execution of__ceph_remove_cap.Since the callers of this function hold the
i_ceph_lock, the fix is simply a matter of returning immediately ifcaps->ciis NULL.Based on a patch from Jeff Layton.
Cc: [email protected]
URL: https://tracker.ceph.com/issues/43272Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/caps.c | 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)fs/ceph/caps.c +1
-2@@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) { struct ceph_mds_session *session = cap->session; struct ceph_inode_info *ci = cap->ci; -struct ceph_mds_client *mdsc = -ceph_sb_to_client (ci->vfs_inode.i_sb)->mdsc; +struct ceph_mds_client *mdsc; int removed = 0;fs/ceph/caps.c +6
-0+/* 'ci' being NULL means he remove have already occurred */ +if (!ci) { +dout ("%s: cap inode is NULL\n" , __func__); +return ; + } +
dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode);fs/ceph/caps.c +2
-0+ mdsc =ceph_inode_to_client (&ci->vfs_inode)->mdsc; +
Quoted 3 lines
/* remove from inode's cap rbtree, and clear auth cap */
rb_erase(&cap->ci_node, &ci->i_caps);
if (ci->i_auth_cap== cap) {
Merged into testing branch (with a minor fix to the comment).
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 6 lines · Luis Henriques
A NULL pointer dereference may occur in
__ceph_remove_capwith some of the callbacks used inceph_iterate_session_caps, namelytrim_caps_cbandremove_session_caps_cb. These aren't protected against the concurrent execution of__ceph_remove_cap.
they are protected by session mutex, never get executed concurrently
Quoted 39 lines
Since the callers of this function hold the
i_ceph_lock, the fix is simply a matter of returning immediately ifcaps->ciis NULL.Based on a patch from Jeff Layton.
Cc: [email protected]
URL: https://tracker.ceph.com/issues/43272Signed-off-by Luis Henriques <[email protected]>--- fs/ceph/caps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)fs/ceph/caps.c +9
-2@@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) {struct ceph_mds_session *session = cap->session;struct ceph_inode_info *ci = cap->ci; -struct ceph_mds_client *mdsc = -ceph_sb_to_client (ci->vfs_inode.i_sb)->mdsc; +struct ceph_mds_client *mdsc;int removed =0 ; +/* 'ci' being NULL means he remove have already occurred */ +if (!ci) { +dout ("%s: cap inode is NULL\n" , __func__); +return ; + } +dout ("__ceph_remove_cap %p from %p\n" , cap, &ci->vfs_inode); + mdsc =ceph_inode_to_client (&ci->vfs_inode)->mdsc; +/* remove from inode's cap rbtree, and clear auth cap */ rb_erase (&cap->ci_node, &ci->i_caps);if (ci->i_auth_cap == cap) {
Quoted 10 lines · Zheng
Quoted 6 lines · Luis Henriques
A NULL pointer dereference may occur in
__ceph_remove_capwith some of the callbacks used inceph_iterate_session_caps, namelytrim_caps_cbandremove_session_caps_cb. These aren't protected against the concurrent execution of__ceph_remove_cap.they are protected by session mutex, never get executed concurrently
Maybe not concurrently with one another, but the s_mutex is _not_ held when __ceph_remove_caps is called from ceph_evict_inode. We can't rely on it to protect this.
Quoted 39 lines
Quoted 39 lines
Since the callers of this function hold the
i_ceph_lock, the fix is simply a matter of returning immediately ifcaps->ciis NULL.Based on a patch from Jeff Layton.
Cc: [email protected]
URL: https://tracker.ceph.com/issues/43272Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/caps.c | 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)fs/ceph/caps.c +9
-2@@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) { struct ceph_mds_session *session = cap->session; struct ceph_inode_info *ci = cap->ci; -struct ceph_mds_client *mdsc = -ceph_sb_to_client (ci->vfs_inode.i_sb)->mdsc; +struct ceph_mds_client *mdsc; int removed = 0; +/* 'ci' being NULL means he remove have already occurred */ +if (!ci) { +dout ("%s: cap inode is NULL\n" , __func__); +return ; + } + dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); + mdsc =ceph_inode_to_client (&ci->vfs_inode)->mdsc; + /* remove from inode's cap rbtree, and clear auth cap */ rb_erase(&cap->ci_node, &ci->i_caps); if (ci->i_auth_cap == cap) {
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 9 lines · Jeff Layton
Quoted 8 lines · Zheng
Quoted 6 lines · Luis Henriques
A NULL pointer dereference may occur in
__ceph_remove_capwith some of the callbacks used inceph_iterate_session_caps, namelytrim_caps_cbandremove_session_caps_cb. These aren't protected against the concurrent execution of__ceph_remove_cap.
Quoted 6 lines
Quoted 2 lines
they are protected by session mutex, never get executed concurrently
Maybe not concurrently with one another, but the
s_mutexis _not_ held when__ceph_remove_capsis called fromceph_evict_inode. We can't rely on it to protect this.
Hmm, yeah. I guess the changelog could mention that. Thanks, Jeff.
Cheers,
Signature · 1 line
Luis
Quoted 43 lines
Quoted 39 lines
Quoted 39 lines
Since the callers of this function hold the
i_ceph_lock, the fix is simply a matter of returning immediately ifcaps->ciis NULL.Based on a patch from Jeff Layton.
Cc: [email protected]
URL: https://tracker.ceph.com/issues/43272Signed-off-by Luis Henriques <[email protected]>---
fs/ceph/caps.c | 11 +++++++++--1 file changed, 9 insertions(+), 2 deletions(-)fs/ceph/caps.c +9
-2@@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release) { struct ceph_mds_session *session = cap->session; struct ceph_inode_info *ci = cap->ci; -struct ceph_mds_client *mdsc = -ceph_sb_to_client (ci->vfs_inode.i_sb)->mdsc; +struct ceph_mds_client *mdsc; int removed = 0; +/* 'ci' being NULL means he remove have already occurred */ +if (!ci) { +dout ("%s: cap inode is NULL\n" , __func__); +return ; + } + dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); + mdsc =ceph_inode_to_client (&ci->vfs_inode)->mdsc; + /* remove from inode's cap rbtree, and clear auth cap */ rb_erase(&cap->ci_node, &ci->i_caps); if (ci->i_auth_cap == cap) {Signature · 1 line
Jeff Layton <[email protected]>