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


Groups > linux.kernel > #1283156

Re: [PATCH v2] fs: clear file privilege bits when mmap writing

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2] fs: clear file privilege bits when mmap writing
Date Thu, 03 Dec 2015 17:10:01 +0100
Message-ID <qBECd-7oz-1@gated-at.bofh.it> (permalink)
References <qBpDb-5UD-1@gated-at.bofh.it> <qBpMS-5Y5-21@gated-at.bofh.it>
X-Original-To Andrew Morton <akpm@linux-foundation.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=RyZTuFvr0MC9WFpD4sO7c+86wuYkkxiHtmHn9YhylSo=; b=JMNDiq1f4PQiOjzJ16bzKvkF4X+IdjLawDB0I1A6V9qrXrF6va7mSHYBdKLGHyS+Ti 8n6McncXlDQU+oGiSM6gSkagtP61LqNezjnkd1Ss4Z6CiiLn1bArhOuI5qrVZi5NITJC zYN4BO8DKd++nIL9vzVTSsTbbhMAUvQ8kj4xF/NRv6V1Leyqa/W8QkOD1D+bVNkbdMMy hxX0sUqOrIhi8RJ7pm0WcwAjMTuHb6glRbs1GODHgVmIAtTHpVKiC0nFAuxahx+SL+Yw 0ZQVIIBWnbiFy5XWI9KAFGlEAxdSQQNlmUULSjLSXZJfS5NVp+bh2gxbIVvks2cftL0g zPTw==
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=RyZTuFvr0MC9WFpD4sO7c+86wuYkkxiHtmHn9YhylSo=; b=JuEtUW3s1QN8NQDPBWadtVwOdSAZv8XwoUFqjqK0r2N/r3uuHsA06sin5a3IQ9iU9S eSiYwN1e1vHTDeURZjTB5vdVvcxzhHu3LiX7jlhFU5kK468PKu4zqIaCI5V+XEYBIrnW bbKUAmJdc6N+nlDjmY0eVgmn/LhbAcNtImCHA=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=RyZTuFvr0MC9WFpD4sO7c+86wuYkkxiHtmHn9YhylSo=; b=drJivyj/fzz+3FoIU3V7E28t97zgr5klpIimM/YObgUUcMoYfXYQhtlLN1QvgHxtek PwmnW03GfK3YyHqnPCc96xzKXhXKTcpMjBN45T++expa+hsKlql9LfxWibqO8zjsZkCO t51m7BqwuU+iNhDTzG1FlmsdySS8ss6lwrg9bBk5qryrnPWPNM7SS+WdkNfSCKndEgUW 8BjW30pUbOKqonLlI0WvFQtyjTuJPr1qv997DUb9JEQQimgIgUWgjS/IsZGNXcw3LMgw L3q26v6Do9cTZHoC9ZqqWdcyO6i/1O+6vYm8aqItNS9U9Zxw5855lPRqG3DzbLYmK0jg DpyA==
X-Gm-Message-State ALoCoQleKn6PnUgQ3UNtRIg7uYSM9BsyvfMLKBl5+ipN176KvJXR/3KDIw6BX0ntuMlhodUJYtOI
MIME-Version 1.0
X-Received by 10.50.36.69 with SMTP id o5mr10360785igj.3.1449158828679; Thu, 03 Dec 2015 08:07:08 -0800 (PST)
X-Google-Sender-Auth eagwq2ih_Zj2NfjeT9SRC086avs
Content-Type text/plain; charset=UTF-8
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 49
Organization linux.* mail to news gateway
X-Original-Cc Jan Kara <jack@suse.cz>, 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>, Linux-MM <linux-mm@kvack.org>, LKML <linux-kernel@vger.kernel.org>
X-Original-Date Thu, 3 Dec 2015 08:07:08 -0800
X-Original-Message-ID <CAGXu5jJCzjiFJG+q76GeYnb5vz3nxZ8EFUAGm=GPOfYmT=OqUA@mail.gmail.com>
X-Original-References <20151203000342.GA30015@www.outflux.net> <20151202161851.95d8fe811705c038e3fe2d33@linux-foundation.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1283156

Show key headers only | View raw


On Wed, Dec 2, 2015 at 4:18 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Wed, 2 Dec 2015 16:03:42 -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 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).
>> Instead, clear the bits if PROT_WRITE is being used at mmap time.
>>
>> ...
>>
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -1340,6 +1340,17 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
>>                       if (locks_verify_locked(file))
>>                               return -EAGAIN;
>>
>> +                     /*
>> +                      * If we must remove privs, we do it here since
>> +                      * doing it during page COW is expensive and
>> +                      * cannot hold inode->i_mutex.
>> +                      */
>> +                     if (prot & PROT_WRITE && !IS_NOSEC(inode)) {
>> +                             mutex_lock(&inode->i_mutex);
>> +                             file_remove_privs(file);
>> +                             mutex_unlock(&inode->i_mutex);
>> +                     }
>> +
>
> Still ignoring the file_remove_privs() return value.  If this is
> deliberate then a description of the reasons should be included?

Argh, yes, sorry. I will send a v3.

-Kees

-- 
Kees Cook
Chrome OS & Brillo 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 v2] fs: clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-03 01:10 +0100
  Re: [PATCH v2] fs: clear file privilege bits when mmap writing Andrew Morton <akpm@linux-foundation.org> - 2015-12-03 01:20 +0100
    Re: [PATCH v2] fs: clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-03 17:10 +0100
    Re: [PATCH v2] fs: clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-03 19:20 +0100
  Re: [PATCH v2] clear file privilege bits when mmap writing yalin wang <yalin.wang2010@gmail.com> - 2015-12-04 02:50 +0100
    Re: [PATCH v2] clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-07 23:50 +0100
      Re: [PATCH v2] clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-08 01:50 +0100
        Re: [PATCH v2] clear file privilege bits when mmap writing Jan Kara <jack@suse.cz> - 2015-12-09 09:30 +0100
          Re: [PATCH v2] clear file privilege bits when mmap writing Kees Cook <keescook@chromium.org> - 2015-12-10 00:00 +0100

csiph-web