Skip to content

Commit 98a2850

Browse files
dubeykoidryomov
authored andcommitted
ceph: fix potential NULL dereference issue in ceph_fill_trace()
The Coverity Scan service has detected a potential dereference of an explicit NULL value in ceph_fill_trace() [1]. The variable in is declared in the beggining of ceph_fill_trace() [2]: struct inode *in = NULL; However, the initialization of the variable is happening under condition [3]: if (rinfo->head->is_target) { <skipped> in = req->r_target_inode; <skipped> } Potentially, if rinfo->head->is_target == FALSE, then in variable continues to be NULL and later the dereference of NULL value could happen in ceph_fill_trace() logic [4,5]: else if ((req->r_op == CEPH_MDS_OP_LOOKUPSNAP || req->r_op == CEPH_MDS_OP_MKSNAP) && test_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags) && !test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) { <skipped> ihold(in); err = splice_dentry(&req->r_dentry, in); if (err < 0) goto done; } This patch adds the checking of in variable for NULL value and it returns -EINVAL error code if it has NULL value. v2 Alex Markuze suggested to add unlikely macro in the checking condition. [1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1141197 [2] https://elixir.bootlin.com/linux/v6.17-rc3/source/fs/ceph/inode.c#L1522 [3] https://elixir.bootlin.com/linux/v6.17-rc3/source/fs/ceph/inode.c#L1629 [4] https://elixir.bootlin.com/linux/v6.17-rc3/source/fs/ceph/inode.c#L1745 [5] https://elixir.bootlin.com/linux/v6.17-rc3/source/fs/ceph/inode.c#L1777 Signed-off-by: Viacheslav Dubeyko <[email protected]> Reviewed-by: Alex Markuze <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 6140f1d commit 98a2850

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/ceph/inode.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,11 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
17931793
goto done;
17941794
}
17951795

1796+
if (unlikely(!in)) {
1797+
err = -EINVAL;
1798+
goto done;
1799+
}
1800+
17961801
/* attach proper inode */
17971802
if (d_really_is_negative(dn)) {
17981803
ceph_dir_clear_ordered(dir);
@@ -1828,6 +1833,12 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req)
18281833
doutc(cl, " linking snapped dir %p to dn %p\n", in,
18291834
req->r_dentry);
18301835
ceph_dir_clear_ordered(dir);
1836+
1837+
if (unlikely(!in)) {
1838+
err = -EINVAL;
1839+
goto done;
1840+
}
1841+
18311842
ihold(in);
18321843
err = splice_dentry(&req->r_dentry, in);
18331844
if (err < 0)

0 commit comments

Comments
 (0)