From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033919AbbKFV7x (ORCPT ); Fri, 6 Nov 2015 16:59:53 -0500 Received: from mail-ig0-f176.google.com ([209.85.213.176]:36259 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030287AbbKFV7v (ORCPT ); Fri, 6 Nov 2015 16:59:51 -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> Date: Fri, 6 Nov 2015 13:59:50 -0800 X-Google-Sender-Auth: 5zqMqx3Q92tQBv_DZYwVpfkNTy0 Message-ID: Subject: Re: [RFC] namei: prevent sgid-hardlinks for unmapped gids From: Kees Cook To: Andy Lutomirski , Theodore Tso Cc: 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 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? >> >>> 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? -Kees -- Kees Cook Chrome OS Security