From patchwork Wed Dec 2 15:40:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7748431 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E0B709F387 for ; Wed, 2 Dec 2015 16:26:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D85720549 for ; Wed, 2 Dec 2015 16:26:04 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [63.239.67.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E8CE20503 for ; Wed, 2 Dec 2015 16:26:03 +0000 (UTC) X-TM-IMSS-Message-ID: <2376917f0000689b@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1) id 2376917f0000689b ; Wed, 2 Dec 2015 11:25:52 -0500 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB2GNxZT010756; Wed, 2 Dec 2015 11:24:00 -0500 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id tB2FgHOs185554 for ; Wed, 2 Dec 2015 10:42:17 -0500 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id tB2Fg5ot006458 for ; Wed, 2 Dec 2015 10:42:17 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1ChAAA0EF9WnLbVVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBg0JCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEBBAIBGgYKhDqCEIklhRGOIIhBlkyGIYtrNoEXgmcNFgeBdVMBhCQCHgeBIwEBAQ X-IPAS-Result: A1ChAAA0EF9WnLbVVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBg0JCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEBBAIBGgYKhDqCEIklhRGOIIhBlkyGIYtrNoEXgmcNFgeBdVMBhCQCHgeBIwEBAQ X-IronPort-AV: E=Sophos;i="5.20,373,1444708800"; d="scan'208";a="4986118" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 02 Dec 2015 10:42:15 -0500 X-TM-IMSS-Message-ID: <235686c500015ebd@nsa.gov> Received: from mail-ig0-f182.google.com (mail-ig0-f182.google.com [209.85.213.182]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 235686c500015ebd ; Wed, 2 Dec 2015 10:42:23 -0500 Received: by igcph11 with SMTP id ph11so112809889igc.1 for ; Wed, 02 Dec 2015 07:42:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P/V+TuYvUZHwMrH9QwFdxuL/meXzNN5DpP9+9NpTJqU=; b=1jjO/N87Ds8THq7VsDpuy3kLtLI/w8B4Nlyqbk0S58qRPPvJOluApqAie3AfF/E4rB bTXj8mKjjcdt5vKKSy8g9VzLAoLqF7t9DJPeNZv9TX10bESEZJGC7Na5iLGv6L3hm1lI u0WUPkRX2G8M9nzPSgOzmPD+hztWCjF44Sd2OkGJ6FaVwM1Az0bHfpD3G+8KiSahch9i KLG7krNAMQZ9Ls9S7Zd6gHhqTAkL8ud7IcN3piXu5B7SYj2B9NC2+sh12WoOkQk2vBuc B9/sOVRNISIK6w5Jgw23X/MBeMQeUtlJGM7yHX+68x4EX6oU9kd+CB2CZkfdIAiB7m+Y LdRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P/V+TuYvUZHwMrH9QwFdxuL/meXzNN5DpP9+9NpTJqU=; b=ePNlcfL6OYJ1z3YFprmyQOdjCGKexeIfi8FSHWU05q0BEqYnWzMDpuG0QSJmkxOJ3z l54PRXsHYV5uWZZIVyoyRsN7NtOh4EH+jukfev0i8JmlvugFxtLHQnIw3TWxE4JAPVGE qIKQlZlsHwmMEsUP+N5u2SUmBcnDlib+ogMZeBIua6Mn7W7RkoOd0c0JmDCS0ScgQOYx QNNTIN5wWqclKnaqoMdUGhnviIjrl+Y/Cv1NyKHZvcAT+m9m4xwC/+Dx2c+9PiuT+C8X RoZf5a/WSdHoHAc1qtr3NX3xaiSxkD3SzH0sjB4DTKivJ/1tcuIFSD1nc9qydhCyKEiq MZDg== X-Gm-Message-State: ALoCoQmAsQjqLIpfJ2dbAt/IrAIUus08ojClLOfM7RzRxagYbAEfqccXo62pWrxW/sAtg1NRAsKo X-Received: by 10.50.61.145 with SMTP id p17mr8474895igr.65.1449070933183; Wed, 02 Dec 2015 07:42:13 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id o86sm1341124ioi.36.2015.12.02.07.42.12 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:12 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH 07/19] fs: Check for invalid i_uid in may_follow_link() Date: Wed, 2 Dec 2015 09:40:07 -0600 Message-Id: <1449070821-73820-8-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> References: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Wed, 02 Dec 2015 11:15:49 -0500 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, fuse-devel@lists.sourceforge.net, Austin S Hemmelgarn , linux-mtd@lists.infradead.org, selinux@tycho.nsa.gov, linux-fsdevel@vger.kernel.org MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Filesystem uids which don't map into a user namespace may result in inode->i_uid being INVALID_UID. A symlink and its parent could have different owners in the filesystem can both get mapped to INVALID_UID, which may result in following a symlink when this would not have otherwise been permitted when protected symlinks are enabled. Add a new helper function, uid_valid_eq(), and use this to validate that the ids in may_follow_link() are both equal and valid. Also add an equivalent helper for gids, which is currently unused. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- fs/namei.c | 2 +- include/linux/uidgid.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/namei.c b/fs/namei.c index 288e8a74bf88..4ccafd391697 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -902,7 +902,7 @@ static inline int may_follow_link(struct nameidata *nd) return 0; /* Allowed if parent directory and link owner match. */ - if (uid_eq(parent->i_uid, inode->i_uid)) + if (uid_valid_eq(parent->i_uid, inode->i_uid)) return 0; if (nd->flags & LOOKUP_RCU) diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h index 03835522dfcb..e09529fe2668 100644 --- a/include/linux/uidgid.h +++ b/include/linux/uidgid.h @@ -117,6 +117,16 @@ static inline bool gid_valid(kgid_t gid) return __kgid_val(gid) != (gid_t) -1; } +static inline bool uid_valid_eq(kuid_t left, kuid_t right) +{ + return uid_eq(left, right) && uid_valid(left); +} + +static inline bool gid_valid_eq(kgid_t left, kgid_t right) +{ + return gid_eq(left, right) && gid_valid(left); +} + #ifdef CONFIG_USER_NS extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);