]> git.apps.os.sepia.ceph.com Git - ceph-client.git/commit
ceph: fix potential race condition of i_cap_delay_list access
authorViacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Tue, 10 Jun 2025 19:02:40 +0000 (12:02 -0700)
committerViacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Tue, 17 Jun 2025 19:20:21 +0000 (12:20 -0700)
commit01232c8b99f68879981bb27ef4262772de4b7dcd
tree7a15ff49d316737977885de26ffc315aee6f169f
parent421d30756ca87f808feee0837526fae274146b71
ceph: fix potential race condition of i_cap_delay_list access

The Coverity Scan service has detected potential
race condition of i_cap_delay_list access [1].
The CID 1596363 contains explanation: "Accessing
ci->i_cap_delay_list without holding lock
ceph_mds_client.cap_delay_lock. Elsewhere,
ceph_inode_info.i_cap_delay_list is written to with
ceph_mds_client.cap_delay_lock held 9 out of 9 times.
The value of the shared data will be determined
by the interleaving of thread execution. In ceph_check_caps:
Thread shared data is accessed without holding an appropriate
lock, possibly causing a race condition (CWE-366)".

The patch reworks __cap_delay_cancel() logic by means
moving list_empty(&ci->i_cap_delay_list) under
mdsc->cap_delay_lock protection. Patch introduces
is_cap_delay_list_empty_safe() function that checks
the emptiness of i_cap_delay_list under
mdsc->cap_delay_lock protection. This function is used
in ceph_check_caps() and __ceph_touch_fmode() methods
to resolve the race condition issue.

[1] https://scan5.scan.coverity.com/#/project-view/64304/10063?selectedIssue=1596363

Signed-off-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
fs/ceph/caps.c