From patchwork Tue Apr 26 19:30:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8943421 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 2118A9F1D3 for ; Tue, 26 Apr 2016 19:35:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4D172013D for ; Tue, 26 Apr 2016 19:35:54 +0000 (UTC) Received: from emsm-gh1-uea11.nsa.gov (smtp.nsa.gov [8.44.101.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AEB8920166 for ; Tue, 26 Apr 2016 19:35:52 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="15642514" IronPort-PHdr: =?us-ascii?q?9a23=3AZ7TCXBV227poo4DCydj73T9317vV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZxeDt8tkgFKBZ4jH8fUM07OQ6PCwHzNRqs/a6DgrS99laVwssY?= =?us-ascii?q?0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfTR8?= =?us-ascii?q?Kum9IIPOlcP/j7n0oM2DJVoZz2PmOftbF1afk0b4joEum4xsK6I8mFPig0BjXK?= =?us-ascii?q?Bo/15uPk+ZhB3m5829r9ZJ+iVUvO89pYYbCf2pN4xxd7FTDSwnPmYp/4Wr8ECb?= =?us-ascii?q?FUrcrkcbBy87iBtDSzeDpDv7U5v8qC7zsKA1jCSQPMD6QKoxcSSn7rxwSRjuzi?= =?us-ascii?q?wAMmh9uEjTh9x5iq5WulqfpgZ4i9rKYZuSHOhzeKLDO9cbQ3dRGMFLWGpcAdXv?= =?us-ascii?q?QZEICr86MPpY56f6vUAOoBb2URKhGOOpxDhSnX/70IUx2uImFwDN1QhmFNUL5i?= =?us-ascii?q?eH5O7pPbsfBLjmhJLDyi/OOrYPgW/w?= X-IPAS-Result: =?us-ascii?q?A2EEBQD9wR9X/wHyM5BeHAGDG4FQu3chhzpMAQEBAQEBAgJ?= =?us-ascii?q?iJ4ItghUBAQQBAiQTFCALAwMJAQEXKQgIAwEoBRURBgEHCwUYBIgJxD4BCwEdh?= =?us-ascii?q?iGIWAIRAYV0BY5IiUiBVYxEiU+FQEWOa2KCBRuBaU6HcAIHFweBFwEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2016 19:35:50 +0000 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 u3QJYUdM011240; Tue, 26 Apr 2016 15:34:59 -0400 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 u3QJUq9r172214 for ; Tue, 26 Apr 2016 15:30:52 -0400 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 u3QJUoHL010214 for ; Tue, 26 Apr 2016 15:30:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BABQAQwR9X/yUp0ApegziBUIJztH2LYkwBAQEBAQFmJ4RCAQUnUhAISSwrBgESiCrEZ4YhiFiGCAWOSIlIgVWMRIlPhUBFjmtigTYBThuBaR4wh3ACHgeBFwEBAQ X-IPAS-Result: A0BABQAQwR9X/yUp0ApegziBUIJztH2LYkwBAQEBAQFmJ4RCAQUnUhAISSwrBgESiCrEZ4YhiFiGCAWOSIlIgVWMRIlPhUBFjmtigTYBThuBaR4wh3ACHgeBFwEBAQ X-IronPort-AV: E=Sophos;i="5.24,537,1454994000"; d="scan'208";a="5410354" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 26 Apr 2016 15:30:52 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AvREY6xQ9v2AjYFeAZhbdX1yP29psv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa65ZxCN2/xhgRfzUJnB7Loc0qyN4/CmBj1LuM3Z+Fk5M7VyFDY9wf?= =?us-ascii?q?0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5?= =?us-ascii?q?K6zPF5LIiIzvjqbpq82VPFQD3WHlKZpJbzyI7izp/vEMhoVjLqtjgjDomVBvP9?= =?us-ascii?q?ps+GVzOFiIlAz97MrjtLRq8iBXpu5zv5UYCfayV+0CQLdZFDUrNXwurI2u7EGb?= =?us-ascii?q?DFjH2nxJGEgMkxEAPE6NxhD3UprrtyL8/KIp1SObMMH7V7UcSTGj9LxqTxmugy?= =?us-ascii?q?ACYXpx2WXamsV2gK9B6CygvRs3l5DVeoa9Jvd4f72bedIcWHoHWdxeETFCVNCS?= =?us-ascii?q?dYwKWtEMIeYQgY7nvFsDoFPqHgSwBKXhzSVThnL79aYz1eMnEArP2EorGNdY4y?= =?us-ascii?q?ecl8n8KKpHCbP996LP1ziWKqoOgTo=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FPBQDdwB9X/3/oP4hegziBUIJztH2LY?= =?us-ascii?q?kwBAQEBAQECAmIngi2CFQEFJ1IQCBA5LCsGARKIKsRnhiGIWIYIBY5IiUiBVYx?= =?us-ascii?q?EiU+FQEWOa2KBNgFOG4FpHjCHcAIeB4EXAQEB?= X-IPAS-Result: =?us-ascii?q?A0FPBQDdwB9X/3/oP4hegziBUIJztH2LYkwBAQEBAQECAmI?= =?us-ascii?q?ngi2CFQEFJ1IQCBA5LCsGARKIKsRnhiGIWIYIBY5IiUiBVYxEiU+FQEWOa2KBN?= =?us-ascii?q?gFOG4FpHjCHcAIeB4EXAQEB?= X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="15642331" Received: from unknown (HELO ubuntu-hedt) ([136.63.232.127]) by emsm-gh1-uea11.nsa.gov with ESMTP; 26 Apr 2016 19:30:51 +0000 Received: by ubuntu-hedt (Postfix, from userid 1000) id EDDC030239C; Tue, 26 Apr 2016 14:30:50 -0500 (CDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v4 10/21] fs: Check for invalid i_uid in may_follow_link() Date: Tue, 26 Apr 2016 14:30:33 -0500 Message-Id: <1461699046-30485-11-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461699046-30485-1-git-send-email-seth.forshee@canonical.com> References: <1461699046-30485-1-git-send-email-seth.forshee@canonical.com> X-Mailman-Approved-At: Tue, 26 Apr 2016 15:34:29 -0400 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: linux-bcache@vger.kernel.org, Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@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, cgroups@vger.kernel.org, Pavel Tikhomirov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,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 a29094c6f4a1..6fe8b0d8ca90 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -915,7 +915,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);