From patchwork Mon Jan 4 18:03:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7950191 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 84D979F1CC for ; Mon, 4 Jan 2016 18:34:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 400B720303 for ; Mon, 4 Jan 2016 18:34:39 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79931201C7 for ; Mon, 4 Jan 2016 18:34:37 +0000 (UTC) X-TM-IMSS-Message-ID: <75d0c61700104094@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 75d0c61700104094 ; Mon, 4 Jan 2016 13:32:45 -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 u04IVmGm016545; Mon, 4 Jan 2016 13:31:50 -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 u04I4VSj225759 for ; Mon, 4 Jan 2016 13:04:31 -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 u04I4Bej013312 for ; Mon, 4 Jan 2016 13:04:31 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CSAAAys4pWm7PfVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJOgTE+MYpXhVQBBYweAQEBAQEBBAIBGgYKhDuCEYkjhRiONYhWlmqFYkSMKjWBF4JoDRUHgXxTAYNEAh4HgSQBAQE X-IPAS-Result: A1CSAAAys4pWm7PfVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJOgTE+MYpXhVQBBYweAQEBAQEBBAIBGgYKhDuCEYkjhRiONYhWlmqFYkSMKjWBF4JoDRUHgXxTAYNEAh4HgSQBAQE X-IronPort-AV: E=Sophos;i="5.20,521,1444708800"; d="scan'208";a="5070752" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 04 Jan 2016 13:04:22 -0500 X-TM-IMSS-Message-ID: <75b66a7f0010347a@nsa.gov> Received: from mail-io0-f179.google.com (mail-io0-f179.google.com [209.85.223.179]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 75b66a7f0010347a ; Mon, 4 Jan 2016 13:03:57 -0500 Received: by mail-io0-f179.google.com with SMTP id 77so132124004ioc.2 for ; Mon, 04 Jan 2016 10:04:21 -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=G2Q7xIQ3odueB00+XspkhmGDsS98sQvOoyQMjzYVGcg=; b=C4F85H4HQxQaS3MmXGUAbjWjJHwqhuv91KtqB3S3o5lXDUI0+6ml6mBgM9/S1z8XVO OM7dETtuwxxm6EpiaMBZStCZCuglKAMv+qLlVttn2nAyrgJ+ShbovLKmeeDT/dnZn1sb 4lNWxsa1VP1aDnigZCggjANzNaaLWivdoGDRsnjvgkq7Af9JPwikgGeOp0XGYanAGHfL HO5E4P9NIEGYq7W852aPgkvVSs7nvrp9H0pVeIcF092MWk6dCCb4lJBh1r5EsarOD/JU k8TlO3gBNu6IE739kAeJbqwqg9MJXg/Q9Ez0bZoYPXKmyWgTM36BtiujpUnwvIqw7n83 dtLQ== 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=G2Q7xIQ3odueB00+XspkhmGDsS98sQvOoyQMjzYVGcg=; b=IqNAzLM/KJxPZ8NzvKdOA7/g9ND12zdr2ZaOwQReaEKgtffKgCldeTk/ayUy0zdzdz OgmK8ARkuQv1c9GvgEp9w07MQ44gcYRPaab03e9v82mbQ1Yth93ChX8ZN9sifBJ916/O kwgJ8zj5Q0xCMmA8hxouEqALp3Ga0Cylyp0BM8p6F7NiuLdtDIzzokDbfE3PWNpZBUeW 5IDzqIByZFtxwl5s7ClIE6D/lsKjXFtxU2Npj8RNUdMn3hnkcKQZ54YrIAPeg7+AQsOt /aRS2Lzz+/EobKEY4uKEVM7UXsncSsHhRyenp6CCXQPYgOxte6TmLgaeuEs16+oxrEgN erpQ== X-Gm-Message-State: ALoCoQm5ZB0AxhHhRWBTUX/cXBZwVAZJQ4ha52BnNHYqiffQ2a0NvLWSKFFhGiINRUSyK7Iqx6/YP0n2fhwI5RP1FWiM/32m4w== X-Received: by 10.107.185.6 with SMTP id j6mr76632274iof.111.1451930661194; Mon, 04 Jan 2016 10:04:21 -0800 (PST) Received: from localhost ([66.64.121.229]) by smtp.gmail.com with ESMTPSA id p5sm30412007igj.10.2016.01.04.10.04.20 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 04 Jan 2016 10:04:20 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH RESEND v2 07/18] fs: Check for invalid i_uid in may_follow_link() Date: Mon, 4 Jan 2016 12:03:46 -0600 Message-Id: <1451930639-94331-8-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> References: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 04 Jan 2016 13:14:22 -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,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable 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);