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

Re: /proc/pid/fd/ shows strange mode when executed via sudo.



Serge Hallyn wrote:
> Note that if you do
> 
> sudo strace -f -e open tail -f /tmp/{1,2,3,4}
> 
> then the fds are not opened with write perms.  But if you do as you did,
> 
> strace -f -e open sudo tail -f /tmp/1 /tmp/2 /tmp/3
> 
> they are.  Interesting.
> 
They are not opened with write perms, for vfs_write() rejects write requests
with -EBADF.

----- test.c start -----
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define O_LARGEFILE 00100000

int main(int argc, char *argv[])
{
	int fd1 = open("/tmp/1", O_RDONLY | O_LARGEFILE);
	int fd2 = open("/tmp/2", O_RDONLY | O_LARGEFILE);
	int fd3 = open("/tmp/3", O_RDONLY | O_LARGEFILE);
	int fd4 = open("/tmp/4", O_RDONLY | O_LARGEFILE);
	printf("fd1=%d fd2=%d fd3=%d fd4=%d\n", fd1, fd2, fd3, fd4);
	printf("write(fd1)=%d write(fd2)=%d write(fd3)=%d write(fd4)=%d\n",
	       write(fd1, "", 1), write(fd2, "", 1),
	       write(fd3, "", 1), write(fd4, "", 1));
	getchar();
	return 0;
}
----- test.c end -----

# sudo ./a.out
fd1=3 fd2=4 fd3=5 fd4=6
write(fd1)=-1 write(fd2)=-1 write(fd3)=-1 write(fd4)=-1

Also, /proc/pid/fdinfo/ shows correct info.
So, the problem is nothing but that the /proc/pid/fd/ is showing strange mode.
But I can't imagine what can make /proc/pid/fd/ wrong when /proc/pid/fdinfo/ is
correct...

> The same thing also happens for me with tmpfs, and with a debian sid ec2
> instance running 2.6.32-5-xen-amd64.

2.6.32-220.13.1.el6 has this problem but
2.6.18-308.4.1.el5 does not have this problem.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]

Powered by Linux