From patchwork Fri Apr 22 15:38:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8913661 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9DD6EBF29F for ; Fri, 22 Apr 2016 15:54:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E0BF72014A for ; Fri, 22 Apr 2016 15:54:54 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [8.44.101.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D12CA20149 for ; Fri, 22 Apr 2016 15:54:53 +0000 (UTC) X-TM-IMSS-Message-ID: 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 ad9fabaa00000a34 ; Fri, 22 Apr 2016 11:51:03 -0400 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 u3MFpSjJ008819; Fri, 22 Apr 2016 11:51:28 -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 u3MFdmfX105321 for ; Fri, 22 Apr 2016 11:39:48 -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 u3MFdlDZ004476 for ; Fri, 22 Apr 2016 11:39:48 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CqBABlRRpX/yQp0ApeHYJwgXu3d4QQhg4CgXQBAQEBAQFmJ4RCAQEBAxIVGQEBNwEPUTQBBQEcBgESIogIAaBwgTE+MYpPhSgBBIxcAQEBAQEBBAIBFwYKhA2CCohYhggBjkuJSIFVjEGJKYVlRY0sMIEOYoF4DRuBaU4BhzwCHgeBFwEBAQ X-IPAS-Result: A0CqBABlRRpX/yQp0ApeHYJwgXu3d4QQhg4CgXQBAQEBAQFmJ4RCAQEBAxIVGQEBNwEPUTQBBQEcBgESIogIAaBwgTE+MYpPhSgBBIxcAQEBAQEBBAIBFwYKhA2CCohYhggBjkuJSIFVjEGJKYVlRY0sMIEOYoF4DRuBaU4BhzwCHgeBFwEBAQ X-IronPort-AV: E=Sophos;i="5.24,517,1454994000"; d="scan'208";a="5402619" Received: from emsm-gh1-uea10.corp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) ([10.208.41.36]) by goalie.tycho.ncsc.mil with ESMTP; 22 Apr 2016 11:39:15 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AbCtUwBB28uT450R1XdSjUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP/4pcbcNUDSrc9gkEXOFd2CrakU26yJ6+uwBSQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3Dwdp?= =?us-ascii?q?POO9QteU1JTnkb/qsM2PKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6W?= =?us-ascii?q?ByaV53BUbSNeuBtFDwXf6Rj8FN+lvyH7u+ZwwiyyLcj3Vqs1XjLk5KBuHlugoS?= =?us-ascii?q?MKJzc//GzNwvJxlqUT9AygvRtX0YPSYZ/TMPt4Y7ObeskVA3dCCJV/TStEV7ix?= =?us-ascii?q?c4tHIe0bJuZVosGpvFYSrV2wAhO3BO7i4jRBgHjw3KYz16IqFgSQj19oJM4HrH?= =?us-ascii?q?mB9Ia9D6wVS+3gifCQlTg=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A1EiAQCfQhpXj6nWVdFeHYJwgXu3d4QQg?= =?us-ascii?q?g2EAQKBdAEBAQEBAQICDwEBAQEHCwsJIYJcfVs9AQEBAxIVGQEBNwEPUTQBBQE?= =?us-ascii?q?cBgESIogIAaBsgTE+MYpPhSgBBIxdAQEBAQEBBAIBFwYKhA2CCohYhgiOTIlIg?= =?us-ascii?q?VWMQYkphWVFjSwwgQ6CWg0RCoFpTgGHPAIeB4EXAQEB?= X-IPAS-Result: =?us-ascii?q?A1EiAQCfQhpXj6nWVdFeHYJwgXu3d4QQgg2EAQKBdAEBAQE?= =?us-ascii?q?BAQICDwEBAQEHCwsJIYJcfVs9AQEBAxIVGQEBNwEPUTQBBQEcBgESIogIAaBsg?= =?us-ascii?q?TE+MYpPhSgBBIxdAQEBAQEBBAIBFwYKhA2CCohYhgiOTIlIgVWMQYkphWVFjSw?= =?us-ascii?q?wgQ6CWg0RCoFpTgGHPAIeB4EXAQEB?= X-IronPort-AV: E=Sophos;i="5.24,517,1454976000"; d="scan'208";a="12934444" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by emsm-gh1-uea10.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Apr 2016 15:39:14 +0000 X-TM-IMSS-Message-ID: Received: from mail-ob0-f169.google.com (mail-ob0-f169.google.com [209.85.214.169]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id ad946e3c00000630 ; Fri, 22 Apr 2016 11:38:47 -0400 Received: by mail-ob0-f169.google.com with SMTP id bg3so50698382obb.1 for ; Fri, 22 Apr 2016 08:39:13 -0700 (PDT) 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=cHzLO5ldTwQi7vPuujsFaw7+pWwJPWoDGR5HKUXf5FY=; b=S/wgNmbFCgz4DPf2xeMphEVQa4NoDYf9PntXMvbQY8See7Oz443uON+gNvJ7UuYa1P vWzn+twTOsOF1zQKlaMG1sCMMHciGR1qrbrGVkNsHObKrrvot7aMe01IS9mLY9+i9KO5 fl1ds2fBRKHRjQr4fjWOx8bPHkgO586kqwp99i/fOpLnhPg1QpNX6zKtVeS/hpim5hZl kzrWjisiqOsh6uq963/rbymCpaZN7GjKSao+f1a8QGWVmppa7R2sLuqFKrG4jvTchL1o EU34XYQWI2jVw0Rb1YiJe8IqOhHunPztHCnXEFuoPG6Aq8PcOKAH3mwj4b4WGLdl1UXu eFnw== 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=cHzLO5ldTwQi7vPuujsFaw7+pWwJPWoDGR5HKUXf5FY=; b=XuUSXF/YzwxVBZjUgFQS3ChrlbmF4R1fjfCU+6BbCXLuHskFRE1reiQIZO1rmFIZCQ 2u/+qmt1qTfpQMOdhBF0pwgYN4TcDtK1pZ7OGieLBgZsaLz23hIQ+cpFvU7b5bM3sXWd 6bF4/BMAFMWsC24SuWJiDe/XCCkQhc7yUL+64piB1U5AroWLsHustM9kEIMrIv87bQD5 Uu7IZPWON/8U6APmiXljIdT1ZXc113OjEmutu2RJmfDh1sczKztILdz9u8aITU+FJKPh Y5OXA2aqcB9flPoKl0W3+lUR6Dfy77pSmpqg9fo2NAApwSyX8F6b+qri+SpUJpo3H3zU sjKg== X-Gm-Message-State: AOPr4FUfJQeOCCoGyriBG8oRP3mrGeBclxjmXpemnvo3U9iJw9ZF7Rni/Ct5TAfmnlkJr8X0 X-Received: by 10.182.104.194 with SMTP id gg2mr8863611obb.5.1461339552683; Fri, 22 Apr 2016 08:39:12 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:ad1c:41df:dcb1:a4a0]) by smtp.gmail.com with ESMTPSA id g44sm2118855otg.25.2016.04.22.08.39.12 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 22 Apr 2016 08:39:12 -0700 (PDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro Subject: [PATCH v3 10/21] fs: Check for invalid i_uid in may_follow_link() Date: Fri, 22 Apr 2016 10:38:27 -0500 Message-Id: <1461339521-123191-11-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461339521-123191-1-git-send-email-seth.forshee@canonical.com> References: <1461339521-123191-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Fri, 22 Apr 2016 11:40:27 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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);