From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033988AbbKGAss (ORCPT ); Fri, 6 Nov 2015 19:48:48 -0500 Received: from mail-ob0-f181.google.com ([209.85.214.181]:34417 "EHLO mail-ob0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753358AbbKGAsq (ORCPT ); Fri, 6 Nov 2015 19:48:46 -0500 MIME-Version: 1.0 In-Reply-To: References: <1446511187-9131-1-git-send-email-public@rsjtdrjgfuzkfg.com> <20151104002132.010ccd1d@rsjtdrjgfuzkfg.com> <20151104065820.GF21740@1wt.eu> From: Andy Lutomirski Date: Fri, 6 Nov 2015 16:48:26 -0800 Message-ID: Subject: Re: [RFC] namei: prevent sgid-hardlinks for unmapped gids To: Kees Cook Cc: Theodore Tso , Willy Tarreau , Dirk Steinmetz , Michael Kerrisk-manpages , Serge Hallyn , Seth Forshee , Alexander Viro , Linux FS Devel , LKML , "Eric W . Biederman" , Serge Hallyn , "security@kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 6, 2015 at 4:16 PM, Kees Cook wrote: > On Fri, Nov 6, 2015 at 4:11 PM, Kees Cook wrote: >> On Fri, Nov 6, 2015 at 2:30 PM, Andy Lutomirski wrote: >>> On Fri, Nov 6, 2015 at 1:59 PM, Kees Cook 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 wrote: >>>>> On Tue, Nov 3, 2015 at 10:58 PM, Willy Tarreau 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(). > > I take it back. Hooking wp_page_shared looks expensive. :) Maybe we do > need to hook the mmap? But file_update_time already pokes at the same (or nearby) cachelines, I think -- why would it be expensive? The whole thing could be guarded by if (unlikely(is setuid)), right? --Andy