Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1273650

Re: [PATCH] fs: clear file set[ug]id when writing via mmap

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH] fs: clear file set[ug]id when writing via mmap
Date 2015-11-20 02:00 +0100
Message-ID <qwIds-8pt-15@gated-at.bofh.it> (permalink)
References <qwHAK-8bE-19@gated-at.bofh.it> <qwI3L-8m5-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Nov 19, 2015 at 4:41 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Thu, 19 Nov 2015 16:10:43 -0800 Kees Cook <keescook@chromium.org> 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() directly but not when writing
>> to a shared mmap on the file. This could allow the file writer to gain
>> privileges by changing the binary without losing the setuid/setgid bits.
>>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> Cc: stable@vger.kernel.org
>> ---
>>  mm/memory.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index deb679c31f2a..4c970a4e0057 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -2036,6 +2036,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
>>
>>               if (!page_mkwrite)
>>                       file_update_time(vma->vm_file);
>> +             file_remove_privs(vma->vm_file);
>>       }
>>
>>       return VM_FAULT_WRITE;
>
> file_remove_privs() is depressingly heavyweight.  You'd think there was
> some more lightweight way of caching the fact that we've already done
> this.

In theory, the IS_NOSEC(inode) should be fast. Perhaps track it in the
vma or file struct?

> Dumb question: can we run file_remove_privs() once, when the file is
> opened writably, rather than for each and every write into each page?

This got discussed briefly, but I can't remember why it got shot down.

> Also, the proposed patch drops the file_remove_privs() return value on
> the floor and we just go ahead with the modification.  How come?

Oh, excellent catch. If it can't drop it, it shouldn't be writable.
I'm not sure what the right abort scenario is in wp_page_reuse. Maybe
move this to start of wp_page_shared instead?

-Kees

-- 
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] fs: clear file set[ug]id when writing via mmap Kees Cook <keescook@chromium.org> - 2015-11-20 01:20 +0100
  Re: [PATCH] fs: clear file set[ug]id when writing via mmap Andrew Morton <akpm@linux-foundation.org> - 2015-11-20 01:50 +0100
    Re: [PATCH] fs: clear file set[ug]id when writing via mmap Kees Cook <keescook@chromium.org> - 2015-11-20 02:00 +0100
  Re: [PATCH] fs: clear file set[ug]id when writing via mmap Willy Tarreau <w@1wt.eu> - 2015-11-20 02:10 +0100
    Re: [PATCH] fs: clear file set[ug]id when writing via mmap Willy Tarreau <w@1wt.eu> - 2015-11-20 02:10 +0100
    Re: [PATCH] fs: clear file set[ug]id when writing via mmap Willy Tarreau <w@1wt.eu> - 2015-11-20 02:10 +0100
    Re: [PATCH] fs: clear file set[ug]id when writing via mmap Kees Cook <keescook@chromium.org> - 2015-11-20 02:10 +0100
  Re: [PATCH] fs: clear file set[ug]id when writing via mmap Jan Kara <jack@suse.cz> - 2015-11-23 13:30 +0100
    Re: [PATCH] fs: clear file set[ug]id when writing via mmap ebiederm@xmission.com (Eric W. Biederman) - 2015-11-23 14:00 +0100

csiph-web