ceph: misc fixes
cover ceph: misc fixes
From: Xiubo Li <[email protected]>
Based the testing branch.
Xiubo Li (2):
ceph: fix inode reference leakage in ceph_get_snapdir()
ceph: fix a NULL pointer dereference in ceph_handle_caps()
fs/ceph/caps.c | 2 +- fs/ceph/inode.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/2 ceph: fix inode reference leakage in ceph_get_snapdir()
From: Xiubo Li <[email protected]>
The ceph_get_inode() will search for or insert a new inode into the hash for the given vino, and return a reference to it. If new is non-NULL, its reference is consumed.
We should release the reference when in error handing cases.
--- fs/ceph/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/ceph/inode.c +8 -2
@@ -164,13 +164,13 @@ struct inode *ceph_get_snapdir(struct inode *parent)if (!S_ISDIR (parent->i_mode)) {pr_warn_once ("bad snapdir parent type (mode=0%o)\n" , parent->i_mode); -return ERR_PTR (-ENOTDIR ); + goto err; }if (!(inode->i_state &I_NEW ) && !S_ISDIR (inode->i_mode)) {pr_warn_once ("bad snapdir inode type (mode=0%o)\n" , inode->i_mode); -return ERR_PTR (-ENOTDIR ); + goto err; } inode->i_mode = parent->i_mode;
@@ -190,6 +190,12 @@ struct inode *ceph_get_snapdir(struct inode *parent) }return inode; +err: +if ((inode->i_state &I_NEW )) +discard_new_inode (inode); +else +iput (inode); +return ERR_PTR (-ENOTDIR ); }const struct inode_operations ceph_file_iops = {
Signature · 1 line
2.27.0
Re: [PATCH 1/2] ceph: fix inode reference leakage in ceph_get_snapdir()
Quoted 36 lines · On Wed, 2022-03-02 at 16:54 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
The
ceph_get_inode()will search for or insert a new inode into the hash for the given vino, and return a reference to it. If new is non-NULL, its reference is consumed.We should release the reference when in error handing cases.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/ceph/inode.c +2
-2@@ -164,13 +164,13 @@ struct inode *ceph_get_snapdir(struct inode *parent)if (!S_ISDIR (parent->i_mode)) {pr_warn_once ("bad snapdir parent type (mode=0%o)\n" , parent->i_mode); -return ERR_PTR (-ENOTDIR ); + goto err; }if (!(inode->i_state &I_NEW ) && !S_ISDIR (inode->i_mode)) {pr_warn_once ("bad snapdir inode type (mode=0%o)\n" , inode->i_mode); -return ERR_PTR (-ENOTDIR ); + goto err; } inode->i_mode = parent->i_mode;@@ -190,6 +190,12 @@ struct inode *ceph_get_snapdir(struct inode *parent) }
fs/ceph/inode.c struct inode *ceph_get_snapdir(struct inode *parent) · line 201
Quoted 10 lines
fs/ceph/inode.c +6
-0return inode; +err: +if ((inode->i_state &I_NEW )) +discard_new_inode (inode); +else +iput (inode); +return ERR_PTR (-ENOTDIR ); }const struct inode_operations ceph_file_iops = {
Good catch!
PATCH 2/2 ceph: fix a NULL pointer dereference in ceph_handle_caps()
In reply to [email protected]From: Xiubo Li <[email protected]>
The ceph_find_inode() may will fail and return NULL.
--- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/caps.c +1 -1
@@ -4303,7 +4303,6 @@ void ceph_handle_caps(struct ceph_mds_session *session,/* lookup ino */ inode =ceph_find_inode (mdsc->fsc->sb, vino); - ci =ceph_inode (inode);dout (" op %s ino %llx.%llx inode %p\n" ,ceph_cap_op_name (op), vino.ino, vino.snap, inode);
@@ -4333,6 +4332,7 @@ void ceph_handle_caps(struct ceph_mds_session *session, } goto flush_cap_releases; } + ci =ceph_inode (inode);/* these will work even if we don't have a cap yet */ switch (op) {
Signature · 1 line
2.27.0
Re: [PATCH 2/2] ceph: fix a NULL pointer dereference in ceph_handle_caps()
Quoted 22 lines · On Wed, 2022-03-02 at 16:54 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
The
ceph_find_inode()may will fail and return NULL.Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ceph/caps.c +0
-1@@ -4303,7 +4303,6 @@ void ceph_handle_caps(struct ceph_mds_session *session,/* lookup ino */ inode =ceph_find_inode (mdsc->fsc->sb, vino); - ci =ceph_inode (inode);dout (" op %s ino %llx.%llx inode %p\n" ,ceph_cap_op_name (op), vino.ino, vino.snap, inode);
fs/ceph/caps.c void ceph_handle_caps(struct ceph_mds_session *session, · line 4338
Quoted 7 lines
fs/ceph/caps.c +1
-0@@ -4333,6 +4332,7 @@ void ceph_handle_caps(struct ceph_mds_session *session, } goto flush_cap_releases; } + ci =ceph_inode (inode);/* these will work even if we don't have a cap yet */ switch (op) {
I don't think this is an actual bug. We're just assigning "ci" here and that doesn't involve a dereference of inode. If "inode" is NULL, then ci will be close to NULL, but it doesn't get used in that case.
Assigning this lower in the function is fine though, and it discourages anyone trying to use ci when they shouldn't, so you can add my ack, but maybe fix the patch description since there is no dereference here.
Re: [PATCH 2/2] ceph: fix a NULL pointer dereference in ceph_handle_caps()
Quoted 28 lines · Jeff Layton
Quoted 27 lines · On Wed, 2022-03-02 at 16:54 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
The
ceph_find_inode()may will fail and return NULL.Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ceph/caps.c +1
-1@@ -4303,7 +4303,6 @@ void ceph_handle_caps(struct ceph_mds_session *session,/* lookup ino */ inode =ceph_find_inode (mdsc->fsc->sb, vino); - ci =ceph_inode (inode);dout (" op %s ino %llx.%llx inode %p\n" ,ceph_cap_op_name (op), vino.ino, vino.snap, inode);@@ -4333,6 +4332,7 @@ void ceph_handle_caps(struct ceph_mds_session *session, } goto flush_cap_releases; } + ci =ceph_inode (inode);
Quoted 5 lines
fs/ceph/caps.c void ceph_handle_caps(struct ceph_mds_session *session, · line 4338
Quoted 2 lines
fs/ceph/caps.c +0
-0/* these will work even if we don't have a cap yet */ switch (op) {I don't think this is an actual bug. We're just assigning "ci" here and that doesn't involve a dereference of inode. If "inode" is NULL, then ci will be close to NULL, but it doesn't get used in that case.
Right, I misread the code.
Quoted 5 lines
Assigning this lower in the function is fine though, and it discourages anyone trying to use ci when they shouldn't, so you can add my ack, but maybe fix the patch description since there is no dereference here.
Acked-by Jeff Layton <[email protected]>
Sure, thanks.