From: "Michael Kerrisk" <mtk.manpages@googlemail.com>
To: "Miklos Szeredi" <miklos@szeredi.hu>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
hch@lst.de, viro@zeniv.linux.org.uk, jamie@shareable.org,
drepper@redhat.com, linux-fsdevel@vger.kernel.org,
subrata@linux.vnet.ibm.com
Subject: Re: [parch 4/4] vfs: utimensat(): fix write access check for futimens()
Date: Wed, 4 Jun 2008 10:40:11 +0200 [thread overview]
Message-ID: <cfd18e0f0806040140g15524e5w3f464f3da9dbd3de@mail.gmail.com> (raw)
In-Reply-To: <E1K3kot-0007gz-U7@pomaz-ex.szeredi.hu>
On Wed, Jun 4, 2008 at 6:41 AM, Miklos Szeredi <miklos@szeredi.hu> wrote:
>> The POSIX.1 draft spec for futimens()/utimensat() says:
>>
>> Only a process with the effective user ID equal to the
>> user ID of the file, *or with write access to the file*,
>> or with appropriate privileges may use futimens() or
>> utimensat() with a null pointer as the times argument
>> or with both tv_nsec fields set to the special value
>> UTIME_NOW.
>>
>> The important piece here is "with write access to the file", and
>> this matters for futimens(), which deals with an argument that
>> is a file descriptor referring to the file whose timestamps are
>> being updated, The standard is saying that the "writability"
>> check is based on the file permissions, not the access mode with
>> which the file is opened. (This behavior is consistent with the
>> semantics of FreeBSD's futimes().) However, Linux is currently
>> doing the latter -- futimens(fd, times) is a library
>> function implemented as
>>
>> utimensat(fd, NULL, times, 0)
>>
>> and within the utimensat() implementation we have the code:
>>
>> f = fget(dfd); // dfd is 'fd'
>> ...
>> if (f) {
>> if (!(f->f_mode & FMODE_WRITE))
>> goto mnt_drop_write_and_out;
>>
>> The check should instead be based on the file permissions.
>>
>> Thanks to Miklos for pointing out how to do this check.
>>
>> CC: Miklos Szeredi <miklos@szeredi.hu>
>> CC: Al Viro <viro@zeniv.linux.org.uk>
>> CC: Ulrich Drepper <drepper@redhat.com>
>> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
>>
>> --- linux-2.6.26-rc4/fs/utimes.c 2008-06-03 23:13:31.000000000 +0200
>> +++ linux-2.6.26-rc4-utimensat-fix-v4/fs/utimes.c 2008-06-03 23:15:12.000000000 +0200
>> @@ -137,7 +137,8 @@
>>
>> if (!is_owner_or_cap(inode)) {
>> if (f) {
>> - if (!(f->f_mode & FMODE_WRITE))
>> + error = permission(inode, MAY_WRITE, NULL);
>> + if (error)
>> goto mnt_drop_write_and_out;
>> } else {
>> error = vfs_permission(&nd, MAY_WRITE);
>
> At which point the "if (f)" and the "else" branches become equivalent
> (the nameidata isn't interesting in the other case either). So that
> could be written as:
>
> if (!is_owner_or_cap(inode)) {
> error = permission(inode, MAY_WRITE, NULL);
> if (error)
> goto mnt_drop_write_and_out;
> }
Okay -- thanks Miklos. I'll change that, and test.
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
prev parent reply other threads:[~2008-06-04 8:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-03 22:25 [parch 4/4] vfs: utimensat(): fix write access check for futimens() Michael Kerrisk
2008-06-04 4:41 ` Miklos Szeredi
2008-06-04 5:54 ` Miklos Szeredi
2008-06-04 8:43 ` Michael Kerrisk
2008-06-04 8:44 ` Miklos Szeredi
2008-06-04 8:40 ` Michael Kerrisk [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfd18e0f0806040140g15524e5w3f464f3da9dbd3de@mail.gmail.com \
--to=mtk.manpages@googlemail.com \
--cc=akpm@linux-foundation.org \
--cc=drepper@redhat.com \
--cc=hch@lst.de \
--cc=jamie@shareable.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=subrata@linux.vnet.ibm.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).