From patchwork Mon Dec 7 21:21:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7791701 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 3DA899F349 for ; Mon, 7 Dec 2015 22:25:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87D752055B for ; Mon, 7 Dec 2015 22:25:29 +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 80F6520555 for ; Mon, 7 Dec 2015 22:25:28 +0000 (UTC) X-TM-IMSS-Message-ID: <3e7f6fda00007c71@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 3e7f6fda00007c71 ; Mon, 7 Dec 2015 17:25:20 -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 tB7MNNBA007062; Mon, 7 Dec 2015 17:23:28 -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 tB7LQWxa263190 for ; Mon, 7 Dec 2015 16:26:32 -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 tB7LNOq7001405 for ; Mon, 7 Dec 2015 16:26:32 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBABD9WVW/7PfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBAQQCARoGCoQ6ghCJJYUTjiSIQpZNhiGLbjaBF2OCBA0dgXVTAYQkAh4HgSMBAQE X-IPAS-Result: A1CeBABD9WVW/7PfVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBAQQCARoGCoQ6ghCJJYUTjiSIQpZNhiGLbjaBF2OCBA0dgXVTAYQkAh4HgSMBAQE X-IronPort-AV: E=Sophos;i="5.20,396,1444708800"; d="scan'208";a="5004902" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 07 Dec 2015 16:23:28 -0500 X-TM-IMSS-Message-ID: <3e4e8f890002801e@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 3e4e8f890002801e ; Mon, 7 Dec 2015 16:23:25 -0500 Received: by ioir85 with SMTP id r85so4064261ioi.1 for ; Mon, 07 Dec 2015 13:23:26 -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=uu18XDFy545UWolejWoE0SsYL/4CyWyiYnXg2WgRtGoozyIVpzq/4UnDD0w6Z+Qnbp MKdn1yx3hucLT7fHO1TSQmG3Na8MX+BQXrS//jLmPTcIOku67N8yo7v8CmJR5M/VmMBk o+AKqVBO7Yf1lrqu+ZVIhpeB4J8le1I7OJunDHLlqYM8GpQ9wFUAni3xT3QPGt9IV8Sw SQYAJB0lNd6nHDRH9ic1FgkApR6jLqOwN2qY5FdJA8VsjeklMOrQNfwfcjI5QAaATWo8 niYR7Ao141Jktf2tuZ73GVsX2qDJFiqHmizuhy+sQIExmvniyHNoV4v16dDggLIdJKCk p2FQ== 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=Zp08hYG2fjGHU9f2E3v/VJg4hsax6Pb6udoJ/kfEQGXepxbvO8DKXimhwgFBzxCE5m Nc/J2wdcMCPjEpCoyYU9nFu7LrLukfqDyl5jdSDUN+fIEfUBbY1vxzMiJTqooUXsQUAB X1BDlTDSB24KwkXWjyuiS/k62myBmYqIV59vxOp9KUvO/xOLoERJydP5vv+28cPl1liJ /U0hDm1TolBoTJRzSvNCL8fSlB3UhYquw5ROPlGIpW6zOwLMbAYZsq2Hd8J3LdHE3NgJ QPUkE9FMmNWiw28C6CuuQEa828e++/4Mo/L5arRfI7jBezq9Q8Uhokm323vQMt0L23kl wOaA== X-Gm-Message-State: ALoCoQlfPTDJdcuD85NyCpFkiRLSPj6Hz233lblJv7iwdCV+v12q2CtSXCzTlhPzI4x2g2tGqiTz86HTO4lIa/KlIMDgzVSUyA== X-Received: by 10.107.14.147 with SMTP id 141mr562304ioo.137.1449523406771; Mon, 07 Dec 2015 13:23:26 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id eb1sm205794igc.17.2015.12.07.13.23.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Dec 2015 13:23:26 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v2 07/18] fs: Check for invalid i_uid in may_follow_link() Date: Mon, 7 Dec 2015 15:21:16 -0600 Message-Id: <1449523289-144238-8-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> References: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 07 Dec 2015 16:44:28 -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=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);