lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGXu5jKKuXoUm5jghC7X382C658ayouYuxswYJi6n3nNvmzPaQ@mail.gmail.com>
Date:	Wed, 2 Dec 2015 15:55:01 -0800
From:	Kees Cook <keescook@...omium.org>
To:	Jan Kara <jack@...e.cz>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Dave Chinner <david@...morbit.com>,
	Andy Lutomirski <luto@...capital.net>,
	"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
	Mel Gorman <mgorman@...e.de>,
	Johannes Weiner <hannes@...xchg.org>,
	Rik van Riel <riel@...hat.com>,
	Matthew Wilcox <willy@...ux.intel.com>,
	Shachar Raindel <raindel@...lanox.com>,
	Boaz Harrosh <boaz@...xistor.com>,
	Michal Hocko <mhocko@...e.cz>,
	Haggai Eran <haggaie@...lanox.com>,
	Theodore Tso <tytso@...gle.com>, Willy Tarreau <w@....eu>,
	Dirk Steinmetz <public@...tdrjgfuzkfg.com>,
	Michael Kerrisk-manpages <mtk.manpages@...il.com>,
	Serge Hallyn <serge.hallyn@...ntu.com>,
	Seth Forshee <seth.forshee@...onical.com>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	Linux FS Devel <linux-fsdevel@...r.kernel.org>,
	"Eric W . Biederman" <ebiederm@...ssion.com>,
	Serge Hallyn <serge.hallyn@...onical.com>,
	Linux-MM <linux-mm@...ck.org>
Subject: Re: [PATCH] fs: clear file set[ug]id when writing via mmap

On Mon, Nov 23, 2015 at 4:26 AM, Jan Kara <jack@...e.cz> wrote:
> On Thu 19-11-15 16:10:43, 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() 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@...omium.org>
>> Cc: stable@...r.kernel.org
>
> So I had another look at this and now I understand why we didn't do it from
> the start:
>
> To call file_remove_privs() safely, we need to hold inode->i_mutex since
> that operations is going to modify file mode / extended attributes and
> i_mutex protects those. However we cannot get i_mutex in the page fault
> path as that ranks above mmap_sem which we hold during the whole page
> fault.

Ah, I see the notation in __generic_file_write_iter about i_mutex.
Should file_remove_privs() get some debug annotation to catch callers
that don't hold that mutex? (That would have alerted me much earlier.)

> So calling file_remove_privs() when opening the file is probably as good as
> it can get. It doesn't catch the case when suid bits / IMA attrs are set
> while the file is already open but I don't see easy way around this.

I agree with Eric: mmap time seems like the right place.

> BTW: This is another example where page fault locking is constraining us
> and life would be simpler for filesystems we they get called without
> mmap_sem held...
>
>                                                                 Honza
> --
> Jan Kara <jack@...e.com>
> SUSE Labs, CR

-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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ