From: Kees Cook <keescook@chromium.org>
To: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
yalin wang <yalin.wang2010@gmail.com>, Willy Tarreau <w@1wt.eu>,
"Eric W. Biederman" <ebiederm@xmission.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Oleg Nesterov <oleg@redhat.com>, Rik van Riel <riel@redhat.com>,
Chen Gang <gang.chen.5i5j@gmail.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Andrea Arcangeli <aarcange@redhat.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4] fs: clear file privilege bits when mmap writing
Date: Wed, 9 Dec 2015 09:53:36 -0800 [thread overview]
Message-ID: <CAGXu5jKAKUdPq3LNydmMkgzqD4fC3TftX4SQ6HdPX6pyUbMFeg@mail.gmail.com> (raw)
In-Reply-To: <20151209124918.GG3137@quack.suse.cz>
On Wed, Dec 9, 2015 at 4:49 AM, Jan Kara <jack@suse.cz> wrote:
> On Tue 08-12-15 15:28:18, Kees Cook wrote:
>> Normally, when a user can modify a file that has setuid or setgid bits,
>> those bits are cleared when they are not the file owner or a member
>> of the group. This is enforced when using write and truncate but not
>> when writing to a shared mmap on the file. This could allow the file
>> writer to gain privileges by changing a binary without losing the
>> setuid/setgid/caps bits.
>>
>> Changing the bits requires holding inode->i_mutex, so it cannot be done
>> during the page fault (due to mmap_sem being held during the fault). We
>> could do this during vm_mmap_pgoff, but that would need coverage in
>> mprotect as well, but to check for MAP_SHARED, we'd need to hold mmap_sem
>> again.
>>
>> Instead, detect the need to clear the bits during the page fault, and
>> actually remove the bits during final fput. Since the file was open for
>> writing, it wouldn't have been possible to execute it yet.
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> Here's another way? I wonder which of these will actually work. I
>> wish we could reject writes if file_remove_privs() fails.
>
> Yeah, the fact that we cannot do anything with file_remove_privs() failure
> is rather unfortunate. So open for writing may be the best choice for
> file_remove_privs() in the end? It's not perfect but it looks like the
> least problematic solution.
Yeah, back to just the open itself. I can't even delay this to the mmap. :(
I will do a v5. :)
-Kees
>
> Frankly writeable files that have SUID / SGID bits set are IMHO problems on
> its own, with IMA attrs which are handled by file_remove_privs() as well
> things may be somewhat different.
>
>> diff --git a/fs/file_table.c b/fs/file_table.c
>> index ad17e05ebf95..abb537ef4344 100644
>> --- a/fs/file_table.c
>> +++ b/fs/file_table.c
>> @@ -191,6 +191,14 @@ static void __fput(struct file *file)
>>
>> might_sleep();
>>
>> + /*
>> + * XXX: While avoiding mmap_sem, we've already been written to.
>> + * We must ignore the return value, since we can't reject the
>> + * write.
>> + */
>> + if (unlikely(file->f_remove_privs))
>> + file_remove_privs(file);
>> +
>
> You're missing i_mutex locking again ;).
>
> Honza
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
--
Kees Cook
Chrome OS & Brillo Security
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-12-09 17:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-08 23:28 Kees Cook
2015-12-09 12:49 ` Jan Kara
2015-12-09 17:53 ` Kees Cook [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-12-04 5:24 Kees Cook
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=CAGXu5jKAKUdPq3LNydmMkgzqD4fC3TftX4SQ6HdPX6pyUbMFeg@mail.gmail.com \
--to=keescook@chromium.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=ebiederm@xmission.com \
--cc=gang.chen.5i5j@gmail.com \
--cc=jack@suse.cz \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
--cc=riel@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=w@1wt.eu \
--cc=yalin.wang2010@gmail.com \
/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