[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Race condition between 'stat64' and 'openat' call

From: Bram
Subject: [PATCH] Race condition between 'stat64' and 'openat' call
Date: Mon, 30 Sep 2013 15:09:42 +0200
User-agent: Internet Messaging Program (IMP) H3 (4.3.7)


There appears to be a race condition between the 'stat64' call and the 'openat' call.
This race condition is not ignored via the '-ignore_readdir_race' switch.

The command that is being used looks like:
        $ find . -ignore_readdir_race -type f -print0 | xargs --no-run-if-empty 
-0 rm
The directory in which this runs gets updated (subdirs created and removed).

The easiest way to reproduce is to run the command:
        $ mkdir foodir ; find . -ignore_readdir_race -iname foodir  -exec rmdir 
{} \;
        find: './foodir': No such file or directory

Stracing this shows: (relevant lines only)
fstatat64(5, "foodir", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
        fcntl64(5, F_DUPFD_CLOEXEC, 0)          = 4
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb75c7000
        rt_sigaction(SIGCHLD, {SIG_DFL, [CHLD], SA_RESTART}, {SIG_DFL, [], 0}, 
8) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb75e8728) = 591
        waitpid(591, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 591
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=591, si_status=0, si_utime=0, si_stime=1} --- openat(5, "foodir", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = -1 ENOENT (No such file or directory)

* the 'fstat64' call succeeds,
* a process is forked to execute 'rmdir'
* 'openat' call fails with errno ENOENT

Running with gdb and breaking in error:
        Breakpoint 1, 0xb7ef2b60 in error () from /ub/lib/libc.so.6
        (gdb) bt
        #0  0xb7ef2b60 in error () from /ub/lib/libc.so.6
#1 0x08051800 in report_file_err (exitval=0, errno_value=2, is_target_file=true, name=0x8098430 "./foodir") at util.c:1112 #2 0x08051843 in nonfatal_target_file_error (errno_value=2, name=0x8098430 "./foodir") at util.c:1126 #3 0x0804aba6 in consider_visiting (p=0x80983d0, ent=0x80a18e8) at ftsfind.c:366
        #4  0x0804b154 in find (arg=0xbffffcd4 ".") at ftsfind.c:590
#5 0x0804b264 in process_all_startpoints (argc=8, argv=0xbffffb48) at ftsfind.c:629
        #6  0x0804b402 in main (argc=9, argv=0xbffffb44) at ftsfind.c:735

A possible patch for this is attached.
I'm not fully convinced tho that the code is in the proper place..
Perhaps there is a better place to put it? (possibly in 'nonfatal_target_file_error' or in 'report_file_err')

With the patch:
        $ mkdir foodir ; find . -iname foodir  -exec rmdir {} \;
        find: './foodir': No such file or directory

        $ mkdir foodir ; find . -ignore_readdir_race -iname foodir  -exec rmdir 
{} \;

Best regards,


This message was sent using IMP, the Internet Messaging Program.

Attachment: findutils-4.5.12-race.patch
Description: application/aegis-patch

reply via email to

[Prev in Thread] Current Thread [Next in Thread]