I try to set O_CLOEXEC flag using open() and have no sucess.
Consider the following microtest:
#include <stdio.h>
#include <fcntl.h>
int main() {
int fd = open("test.c", O_RDONLY | O_CLOEXEC);
int ret = fcntl(fd, F_GETFL);
if(ret & O_CLOEXEC) {
printf("OK!\n");
} else {
printf("FAIL!\n");
}
printf("fd = %d\n", fd);
printf("ret = %x, O_CLOEXEC = %x\n", ret, O_CLOEXEC);
return 0;
}
When running on linux with kernel version 2.6 the test succeeds and prints "OK!", but fails with 3.8 or 3.9 kernels.
What's wrong? Thanks!
It was decided that exposing O_CLOEXEC
flag to fcntl(fd, F_GETFL)
is security leak. Change was made by this commit in kernel 3.6-rc7:
commit c6f3d81115989e274c42a852222b80d2e14ced6f
Author: Al Viro <[email protected]>
Date: Sun Aug 26 11:01:04 2012 -0400
don't leak O_CLOEXEC into ->f_flags
Signed-off-by: Al Viro <[email protected]>
In other words, you should not have relied on O_CLOEXEC
being visible in first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With