[Top][All Lists]

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


From: Emilio Pozuelo Monfort
Date: Wed, 28 Jul 2010 22:33:34 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100619 Icedove/3.0.5


cp has some issues with O_NOFOLLOW meaning O_NOTRANS (per
__hurd_file_name_lookup). One of them is when opening pipes with O_NOFOLLOW (or
when opening them with O_NOTRANS, which is the problem here). Then the
permissions are checked in libdiskfs (if the pipe is in an ext2fs partition for
example), which has the following in libdiskfs/dir-lookup.c:

      if (((type == S_IFSOCK || type == S_IFBLK || type == S_IFCHR ||
           type == S_IFIFO)
           && (flags & (O_READ|O_WRITE|O_EXEC)))
          || (type == S_IFLNK && (flags & (O_WRITE|O_EXEC))))
        error = EACCES;

So opening a named pipe with open(pipe, O_RDONLY | O_NOTRANS, 0) will cause
EACCES. I wonder what is the reason for not allowing access to those kind of
files if they are opened with O_READ, O_WRITE or O_EXEC. Why can't they be
allowed, as long as the opener has the appropriate permissions (which will be
checked later)?

The attached eacces.c program reproduces this issue.

The other problem is that an stat on a named pipe like

fd = open (pipe, O_RDONLY | O_NOFOLLOW, 0);
fstat (fd, &sb);

Doesn't match this:

lstat (pipe, &sb);

In particular, sb.st_dev will be different. The problem is that lstat uses
O_NOLINK internally, and since the named pipe is not a symlink, it will get the
underlying node, and the io_stat call will be handled by the fifo translator,
which will return its PID in st_dev. However the open call has O_NOFOLLOW, which
implies O_NOTRANS and thus it doesn't get the underlying node, returning the
correct st_dev. Would it be possible to make these kind of translators return
the device id of its parent?

The attached stat.c testcase reproduces this issue (you can remove the
O_NOFOLLOW flag to see the devices matching, but being the PID of the fifo


Attachment: eacces.c
Description: Text Data

Attachment: stat.c
Description: Text Data

reply via email to

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