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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 6 Nov 2015 16:11:31 -0800
From:	Kees Cook <keescook@...omium.org>
To:	Andy Lutomirski <luto@...capital.net>
Cc:	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>,
	LKML <linux-kernel@...r.kernel.org>,
	"Eric W . Biederman" <ebiederm@...ssion.com>,
	Serge Hallyn <serge.hallyn@...onical.com>,
	"security@...nel.org" <security@...nel.org>
Subject: Re: [RFC] namei: prevent sgid-hardlinks for unmapped gids

On Fri, Nov 6, 2015 at 2:30 PM, Andy Lutomirski <luto@...capital.net> wrote:
> On Fri, Nov 6, 2015 at 1:59 PM, Kees Cook <keescook@...omium.org> wrote:
>> Adding Ted, who might know how this all hooks together. (The context
>> is that a write() or truncate() on a setgid file clears the setgid,
>> but mmap writes don't.)
>>
>> On Wed, Nov 4, 2015 at 9:59 AM, Andy Lutomirski <luto@...capital.net> wrote:
>>> On Tue, Nov 3, 2015 at 10:58 PM, Willy Tarreau <w@....eu> wrote:
>>>> On Tue, Nov 03, 2015 at 03:29:55PM -0800, Kees Cook wrote:
>>>>> Using "write" does kill the set-gid bit. I haven't looked at
>>>>> why.
>>>>> Al or anyone else, is there a meaningful distinction here?
>>>>
>>>> I remember this one, I got caught once while trying to put a shell into
>>>> a suid-writable file to get some privileges someone forgot to offer me :-)
>>>>
>>>> It's done by should_remove_suid() which is called upon write() and truncate().
>>
>> file_remove_privs() seems to be the right entry point.
>> __generic_file_write_iter in mm/filemap.c calls it, though. Are these
>> callbacks not used for mmap writes?
>
> They're certainly not used early enough -- we need to remove suid when
> the page becomes writable via mmap (wp_page_shared), not when
> writeback happens, or at least not only when writeback happens.

Well, I'm shy about the change there. For example, we don't strip in
on open(RDWR), just on write().

> But IIRC mmaped writes go through a different path -- they go through
> the address_space ops with names like writepages.

Ah-ha.

>>>>> Should the
>>>>> mmap MAP_SHARED-write trigger the loss of the set-gid bit too? While
>>>>> holding the file open with either open or mmap, I get a Text-in-use
>>>>> error, so I would kind of expect the same behavior between either
>>>>> close() and munmap(). I wonder if this is a bug, and if so, then your
>>>>> link patch is indeed useful again. :)
>>>>
>>>> I don't see how this could be done with mmap(). Maybe we have a way to know
>>>> when the first write is performed via this path, I have no idea.
>>>
>>> do_wp_page might be a decent bet.
>>
>> Or wp_page_shared? Can we get back to a file from the mm at that point?
>
> vma->vm_file, presumably (after checking whether it's null).
> wp_page_shared AFAIK only happens from process context, and the vma
> and its file should be valid.
>
> We could also get to an inode via page->address_space->mapping, but
> I'm guessing that vma->vm_file would be more appropriate here.

Yeah. Let me give it a try...

-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@...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