fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc()
PATCH 3/3 fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc()
In ocfs2_info_scan_inode_alloc(), there is an if statement on line 283 to check whether inode_alloc is NULL:
if (inode_alloc)
When inode_alloc is NULL, it is used on line 287:
ocfs2_inode_lock(inode_alloc, &bh, 0);
ocfs2_inode_lock_full_nested(inode, ...)
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);Thus, a possible null-pointer dereference may occur.
To fix this bug, inode_alloc is checked on line 286.
This bug is found by a static analysis tool STCheck written by us.
--- fs/ocfs2/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/ioctl.c +1 -1
@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,if (inode_alloc)inode_lock (inode_alloc); -if (o2info_coherent (&fi->ifi_req)) { +if (inode_alloc &&o2info_coherent (&fi->ifi_req)) { status =ocfs2_inode_lock (inode_alloc, &bh,0 );if (status <0 ) {mlog_errno (status);
Signature · 1 line
2.17.0
Quoted 9 lines · Jia-Ju Bai
In
ocfs2_info_scan_inode_alloc(), there is an if statement on line 283 to check whetherinode_allocis NULL:
if (inode_alloc)When
inode_allocis NULL, it is used on line 287:ocfs2_inode_lock(inode_alloc, &bh, 0); ocfs2_inode_lock_full_nested(inode, ...) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
Quoted 7 lines
Thus, a possible null-pointer dereference may occur.
To fix this bug,
inode_allocis checked on line 286.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>
Looks good.
Quoted 18 lines
--- fs/ocfs2/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ocfs2/ioctl.c +1
-1@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,if (inode_alloc)inode_lock (inode_alloc); -if (o2info_coherent (&fi->ifi_req)) { +if (inode_alloc &&o2info_coherent (&fi->ifi_req)) { status =ocfs2_inode_lock (inode_alloc, &bh,0 );if (status <0 ) {mlog_errno (status);
PATCH 3/3 fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc()
Hi Jia-Ju and Joseph,
Busy with a training session last week, so late for reviewing this patch.
I think this patch might not be necessary and a little violates original logic.
Please check out my comments inline.
Quoted 32 lines · Joseph Qi
Quoted 9 lines · Jia-Ju Bai
In
ocfs2_info_scan_inode_alloc(), there is an if statement on line 283 to check whetherinode_allocis NULL:
if (inode_alloc)When
inode_allocis NULL, it is used on line 287:ocfs2_inode_lock(inode_alloc, &bh, 0); ocfs2_inode_lock_full_nested(inode, ...) struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);Quoted 7 lines
Thus, a possible null-pointer dereference may occur.
To fix this bug,
inode_allocis checked on line 286.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>Looks good.
Reviewed-by Joseph Qi <[email protected]>Quoted 12 lines
--- fs/ocfs2/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ocfs2/ioctl.c +0
-0@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,if (inode_alloc)inode_lock (inode_alloc);
Quoted 2 lines
fs/ocfs2/ioctl.c static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, · line 286
Quoted 2 lines
fs/ocfs2/ioctl.c +1
-1-if (o2info_coherent (&fi->ifi_req)) { +if (inode_alloc &&o2info_coherent (&fi->ifi_req)) {
If caller is asking for strict coherency but *inode_alloc* is NULL, we fallback to non-coherency branch?
I think this is destroying the file semantics. Returning error to caller is better?
On the other hand, from the code path:
ocfs2_info_handle_freeinode()
??? if o2info_coherent() then inode_alloc =ocfs2_get_system_file_inode() ---> here we can ensure that being passed *inode_alloc* can't be NULL
??? ocfs2_info_scan_inode_alloc()
Thanks,
Changwei
Quoted 8 lines
fs/ocfs2/ioctl.c static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, · line 289
Quoted 4 lines
fs/ocfs2/ioctl.c +0
-0status =ocfs2_inode_lock (inode_alloc, &bh,0 );if (status <0 ) {mlog_errno (status);_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Joseph Qi
maintainerPATCH 3/3 fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc()
Quoted 51 lines · Changwei Ge
Hi Jia-Ju and Joseph,
Busy with a training session last week, so late for reviewing this patch.
I think this patch might not be necessary and a little violates original logic.
Please check out my comments inline.
Quoted 24 lines · Joseph Qi
Quoted 9 lines · Jia-Ju Bai
In
ocfs2_info_scan_inode_alloc(), there is an if statement on line 283 to check whetherinode_allocis NULL:
???? if (inode_alloc)When
inode_allocis NULL, it is used on line 287:
????ocfs2_inode_lock(inode_alloc, &bh, 0); ????????ocfs2_inode_lock_full_nested(inode, ...)???????????? structocfs2_super*osb =OCFS2_SB(inode->i_sb);Quoted 7 lines
Thus, a possible null-pointer dereference may occur.
To fix this bug,
inode_allocis checked on line 286.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>Looks good.
Reviewed-by Joseph Qi <[email protected]>Quoted 4 lines
---
?fs/ocfs2/ioctl.c| 2 +-
? 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 9 lines
fs/ocfs2/ioctl.c static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, · line 286
Quoted 9 lines
fs/ocfs2/ioctl.c +1
-0@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, ????? if (inode_alloc) ????????? inode_lock(inode_alloc); ? -??? if (o2info_coherent(&fi->ifi_req)) { +??? if (inode_alloc && o2info_coherent(&fi->ifi_req)) {If caller is asking for strict coherency but *inode_alloc* is NULL, we fallback to non-coherency branch?
I think this is destroying the file semantics. Returning error to caller is better?
Quoted 8 lines
On the other hand, from the code path:
ocfs2_info_handle_freeinode()??? if
o2info_coherent()theninode_alloc=ocfs2_get_system_file_inode()---> here we can ensure that being passed *inode_alloc* can't be NULL???
ocfs2_info_scan_inode_alloc()
You are right, the caller make sure inode_alloc won't be NULL if o2info_coherent(). So adding this check just make it more explicitly, right?
I don't get how it breaks the original logic.
Thanks,
Joseph
PATCH 3/3 fs: ocfs2: Fix a possible null-pointer dereference in ocfs2_info_scan_inode_alloc()
Morning,
Quoted 55 lines · Joseph Qi
Quoted 53 lines · Changwei Ge
Hi Jia-Ju and Joseph,
Busy with a training session last week, so late for reviewing this patch.
I think this patch might not be necessary and a little violates original logic.
Please check out my comments inline.
Quoted 23 lines · Joseph Qi
Quoted 9 lines · Jia-Ju Bai
In
ocfs2_info_scan_inode_alloc(), there is an if statement on line 283 to check whetherinode_allocis NULL:
???? if (inode_alloc)When
inode_allocis NULL, it is used on line 287:
????ocfs2_inode_lock(inode_alloc, &bh, 0); ????????ocfs2_inode_lock_full_nested(inode, ...)???????????? structocfs2_super*osb =OCFS2_SB(inode->i_sb);Quoted 7 lines
Thus, a possible null-pointer dereference may occur.
To fix this bug,
inode_allocis checked on line 286.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>Looks good.
Reviewed-by Joseph Qi <[email protected]>Quoted 4 lines
--- ? fs/ocfs2/ioctl.c | 2 +-? 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines
fs/ocfs2/ioctl.c static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, · line 286
Quoted 9 lines
fs/ocfs2/ioctl.c +1
-0@@ -283,7 +283,7 @@ static int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb, ????? if (inode_alloc) ????????? inode_lock(inode_alloc); ? -??? if (o2info_coherent(&fi->ifi_req)) { +??? if (inode_alloc && o2info_coherent(&fi->ifi_req)) {If caller is asking for strict coherency but *inode_alloc* is NULL, we fallback to non-coherency branch?
I think this is destroying the file semantics. Returning error to caller is better?
On the other hand, from the code path:
ocfs2_info_handle_freeinode()
Quoted 7 lines
Quoted 4 lines
??? if
o2info_coherent()theninode_alloc=ocfs2_get_system_file_inode()---> here we can ensure that being passed *inode_alloc* can't be NULL???
ocfs2_info_scan_inode_alloc()You are right, the caller make sure
inode_allocwon't be NULL ifo2info_coherent(). So adding this check just make it more explicitly, right?
I don't get how it breaks the original logic.
As user? is asking for a strict coherent filesystem info with OCFS2_INFO_FL_NON_COHERENT cleared, we have to lock the inode cluster-wide via DLM.
If somehow, *inode_alloc* is NULL(actually it can't be), I think, we should still comply above strict coherency sentiments and can't just jump to the non-coherency branch.
Perhaps, return error to caller is better under above situation(can't exist)?
Thanks,
Changwei
Quoted 3 lines
Thanks,
Joseph