Skip to contentSkip to conversation

Procfs race condition bug

DISCUSSION Mike Cardwell 2 participants 2 messages Jul 4, 2014 – Jul 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I originally posted this two years ago (*) but received no response. I just had a look and the problem still exists on the 3.14 kernel I am currently running.

I *think* I've uncovered a race condition bug in procfs. If I attempt to open a file in /proc/net, eg "/proc/net/tcp" it works fine, but if I spawn a POSIX thread and attempt to do it from there, it *usually* fails with a "No such file or directory", but some times succeeds. If I do a system call inside the thread to look up the thread ID and then open "/proc/THREADID/net/tcp" instead, it works fine.

There are more details and some example code so you can replicate the problem on a stack overflow question I asked previously here:
http://stackoverflow.com/questions/11580020/opening-proc-net-tcp-in-c-from-a-posix-thread-fails-most-of-the-time

(*) https://lkml.org/lkml/2012/7/20/331

Signature · 3 lines
Mike Cardwell  https://grepular.com https://emailprivacytester.com
OpenPGP Key    35BC AF1D 3AA2 1F84 3DC3   B0CF 70A5 F512 0018 461F
XMPP OTR Key   8924 B06A 7917 AAF3 DBB1   BF1B 295C 3C78 3EF1 46B4
#1 lore raw

/proc/net/ symlink interacts badly with threads (Re: Procfs race condition bug)

Quoted 5 lines · On Fri, 4 Jul 2014 11:13:11 +0100 Mike Cardwell <[email protected]>…

I originally posted this two years ago (*) but received no response. I just had a look and the problem still exists on the 3.14 kernel I am currently running.

I *think* I've uncovered a race condition bug in procfs. If I attempt to

I don't think you have found a race condition.

/proc/net/tcp is a symbolic link to /proc/self/net/tcp

Your thread does an open of /proc/net/tcp, which is a symlink to /proc/self/net/tcp. If your thread id matches your process id then all will be as you expect, if not then all will be pear shaped.

As far as I can see the code is doing precisely what it should do. It's just that the use of the symlink when namespaces were added produces some rather odd effects.

It's certainly a bug. It used to work, it's sensible it should work.

Added netdev

Alan