From patchwork Wed Dec 2 15:40:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7748741 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 775CF9F350 for ; Wed, 2 Dec 2015 16:41:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C94052053F for ; Wed, 2 Dec 2015 16:41:50 +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 8E18A20503 for ; Wed, 2 Dec 2015 16:41:49 +0000 (UTC) X-TM-IMSS-Message-ID: <23849d8100006a6d@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 23849d8100006a6d ; Wed, 2 Dec 2015 11:41:13 -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 tB2Gd9ml012649; Wed, 2 Dec 2015 11:39:10 -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 tB2FgjLT185643 for ; Wed, 2 Dec 2015 10:42:45 -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 tB2FgWlQ006648 for ; Wed, 2 Dec 2015 10:42:45 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CnAAA0EF9WlK/VVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEHCwsJH4RlAQEBAxIVGQEBNwEPUTQBBQEcBgESIogNoRWBMT4xileFVAEFjCMBAQEBAQEBAwIBGgYKhDqCEI42jiCIQZZMkgw2gReCZw0WBxaBX1MBhW4BAQE X-IPAS-Result: A1CnAAA0EF9WlK/VVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEHCwsJH4RlAQEBAxIVGQEBNwEPUTQBBQEcBgESIogNoRWBMT4xileFVAEFjCMBAQEBAQEBAwIBGgYKhDqCEI42jiCIQZZMkgw2gReCZw0WBxaBX1MBhW4BAQE X-IronPort-AV: E=Sophos;i="5.20,373,1444708800"; d="scan'208";a="4986125" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 02 Dec 2015 10:42:29 -0500 X-TM-IMSS-Message-ID: <2356bdbc00015eec@nsa.gov> Received: from mail-ig0-f175.google.com (mail-ig0-f175.google.com [209.85.213.175]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 2356bdbc00015eec ; Wed, 2 Dec 2015 10:42:37 -0500 Received: by igcto18 with SMTP id to18so34147084igc.0 for ; Wed, 02 Dec 2015 07:42:27 -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=2VntfpmmJwTFjQzDZSd7UQsjizdQRqc52zI35pXqbg4=; b=tRlfcpsdyMjFjcRme33UGOIEQza0oEXspncxjlSMuhJTnILAmY3RGdSO7+f5ZeHVJI NiDCm0g+VuYEet04Zt09ffh+Mrx9lpfkOEB09IjIvM/iH+qjRC7wGuJyqFc4/OwJg95T F271Nf+slIUYfnqakeBLYM6UN7lojhTZmauWmqaUH0h4ag5gQ2cy5T6Y3IfdLHzzsYXQ Ds/0ZnfUmm7UxDC/h9WcWxnzp/FyGNWNUAH5kxYF+WXQSJwDkYQFN9OhZz2Pj3/37DPa zP2K746FvB49yVp41vFMPHcF7pJHPKWPu6T9vsoNQnsxOleKdUpC3HIkqlb9Vs94Ss7g RzXg== 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=2VntfpmmJwTFjQzDZSd7UQsjizdQRqc52zI35pXqbg4=; b=bBbKw9b2LScAvuDoxN35Nw9i7nlQ80Sxla/zvSe69ErR5DG20XJZDwHdDoN5rRgCr9 4oiGucHm4UzJACJ3ttVG3c2XJXYO1y6ilt7x9ZWFhzMjFg+ftmwZzKaRzXgjgA+6PL85 l1eVMap7Hd4e+/lnVJBS0wBNFGGeqF7ZrUzzTmEUsvYDHPfXUcUj+VAEKA5i16J0BXLY FRmdoC8hPatbQvPfaa9XTeno2f83Qxyvu1jko6oQg9oJLM/ycxmu/dX0ftRJfNsSt1E2 S60jRZkuBPVxzodO6TDymLWV2RJWmA7K1HuIBygu6OkyyZytFKAr52dAmi7dnFX15UKB d8VA== X-Gm-Message-State: ALoCoQloBU1zuXHFSB0eRuWNK4Hh5Faz8bfbs2oKo4YXS3tJIylbcKbHvFHIDdi274FYq/OSonD3 X-Received: by 10.50.57.84 with SMTP id g20mr30957836igq.44.1449070947319; Wed, 02 Dec 2015 07:42:27 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id 75sm1342030ios.35.2015.12.02.07.42.26 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:26 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn Subject: [PATCH 11/19] fs: Ensure the mounter of a filesystem is privileged towards its inodes Date: Wed, 2 Dec 2015 09:40:11 -0600 Message-Id: <1449070821-73820-12-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: linux-security-module@vger.kernel.org, Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , 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 The mounter of a filesystem should be privileged towards the inodes of that filesystem. Extend the checks in inode_owner_or_capable() and capable_wrt_inode_uidgid() to permit access by users priviliged in the user namespace of the inode's superblock. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- fs/inode.c | 3 +++ kernel/capability.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1be5f9003eb3..01c036fe1950 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1962,6 +1962,9 @@ bool inode_owner_or_capable(const struct inode *inode) ns = current_user_ns(); if (ns_capable(ns, CAP_FOWNER) && kuid_has_mapping(ns, inode->i_uid)) return true; + + if (ns_capable(inode->i_sb->s_user_ns, CAP_FOWNER)) + return true; return false; } EXPORT_SYMBOL(inode_owner_or_capable); diff --git a/kernel/capability.c b/kernel/capability.c index 45432b54d5c6..5137a38a5670 100644 --- a/kernel/capability.c +++ b/kernel/capability.c @@ -437,13 +437,18 @@ EXPORT_SYMBOL(file_ns_capable); * * Return true if the current task has the given capability targeted at * its own user namespace and that the given inode's uid and gid are - * mapped into the current user namespace. + * mapped into the current user namespace, or if the current task has + * the capability towards the user namespace of the inode's superblock. */ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap) { - struct user_namespace *ns = current_user_ns(); + struct user_namespace *ns; - return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) && - kgid_has_mapping(ns, inode->i_gid); + ns = current_user_ns(); + if (ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid) && + kgid_has_mapping(ns, inode->i_gid)) + return true; + + return ns_capable(inode->i_sb->s_user_ns, cap); } EXPORT_SYMBOL(capable_wrt_inode_uidgid);