[lkml]   [2014]   [Jul]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Procfs race condition bug
> 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:
> (*)


as was correctly notes on SO, what's happening is that original thread exits
before spawned thread does open().

nsproxy = NULL <== thread is dead

This was probably broken when /proc/net became symlink:

commit e9720acd728a46cb40daa52c99a979f7c4ff195c
Author: Pavel Emelyanov <>
Date: Fri Mar 7 11:08:40 2008 -0800

[NET]: Make /proc/net a symlink on /proc/self/net (v3)

So, userspace has two solutions:
1) original thread doesn't exit too early
2) spawned thread uses /proc/$TID

we definitely broke /proc/net/tcp somewhere after netns concept was introduced.

you'd have very same problem with other /proc files (anything under


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *f(void *_)
int fd;


fd = open("/proc/net/tcp", O_RDONLY);
if (fd == -1) {
fprintf(stderr, "FAIL\n");
return NULL;
fprintf(stderr, "OK\n");
return NULL;

int main(void)
pthread_t thread;

pthread_create(&thread, NULL, f, NULL);
return 0;

 \ /
  Last update: 2014-07-09 15:21    [W:0.085 / U:2.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site