inotify11: Fix race condition between fork() and inotify init
PATCH 1/1 inotify11: Fix race condition between fork() and inotify init
When the child process runs a few churn cycles before the parent completes inotify initialization, the parent will get stuck reading the inotify file descriptor until it eventually times out. Create inotify watch befory fork()ing to prevent this race condition.
Signed-off-by Martin Doucha <[email protected]>
--- testcases/kernel/syscalls/inotify/inotify11.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/inotify/inotify11.c +4 -3
@@ -61,15 +61,16 @@ static void verify_inotify(void)struct inotify_event *event;int inotify_fd; + inotify_fd =SAFE_MYINOTIFY_INIT (); +SAFE_MYINOTIFY_ADD_WATCH (inotify_fd,"." ,IN_DELETE ); + pid =SAFE_FORK ();if (pid ==0 ) { +SAFE_CLOSE (inotify_fd);churn ();return ; } - inotify_fd =SAFE_MYINOTIFY_INIT (); -SAFE_MYINOTIFY_ADD_WATCH (inotify_fd,"." ,IN_DELETE ); -while (!opened && nevents <CHURN_FILES ) {int i, fd, len;
Signature · 5 lines
2.37.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Martin Doucha
When the child process runs a few churn cycles before the parent completes inotify initialization, the parent will get stuck reading the inotify file descriptor until it eventually times out. Create inotify watch befory fork()ing to prevent this race condition.
Signed-off-by Martin Doucha <[email protected]>
LGTM
Reviewed-by Amir Goldstein <[email protected]>
Quoted 34 lines
--- testcases/kernel/syscalls/inotify/inotify11.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)testcases/kernel/syscalls/inotify/inotify11.c +4
-4@@ -61,15 +61,16 @@ static void verify_inotify(void)struct inotify_event *event;int inotify_fd; + inotify_fd =SAFE_MYINOTIFY_INIT (); +SAFE_MYINOTIFY_ADD_WATCH (inotify_fd,"." ,IN_DELETE ); + pid =SAFE_FORK ();if (pid ==0 ) { +SAFE_CLOSE (inotify_fd);churn ();return ; } - inotify_fd =SAFE_MYINOTIFY_INIT (); -SAFE_MYINOTIFY_ADD_WATCH (inotify_fd,"." ,IN_DELETE ); -while (!opened && nevents <CHURN_FILES ) {int i, fd, len; --2.37.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
thanks, merged!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp