From patchwork Mon Dec 7 21:21:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7791661 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 D4A0BBEEE1 for ; Mon, 7 Dec 2015 22:21:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 384A92055B for ; Mon, 7 Dec 2015 22:21:11 +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 3D42A20555 for ; Mon, 7 Dec 2015 22:21:10 +0000 (UTC) X-TM-IMSS-Message-ID: <3e7bc02b00007c31@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 3e7bc02b00007c31 ; Mon, 7 Dec 2015 17:21:19 -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 tB7MJXWO006592; Mon, 7 Dec 2015 17:19:35 -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 tB7LQXYa263197 for ; Mon, 7 Dec 2015 16:26:33 -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 tB7LNOqE001405 for ; Mon, 7 Dec 2015 16:26:33 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBABD9WVW/7HVVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBAQEDAgEaBgqEOoIQjjiOJIhClk2SDzaBF2OCBA0dFoFfUwGFbgEBAQ X-IPAS-Result: A1CeBABD9WVW/7HVVdFeGQEBAQEPAQEBAYRLuxeEFoYOAoITAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iR4ExPjGKV4VUAQWLdQEBAQEBAQEDAgEaBgqEOoIQjjiOJIhClk2SDzaBF2OCBA0dFoFfUwGFbgEBAQ X-IronPort-AV: E=Sophos;i="5.20,396,1444708800"; d="scan'208";a="5004907" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 07 Dec 2015 16:23:36 -0500 X-TM-IMSS-Message-ID: <3e4eae8d00028025@nsa.gov> Received: from mail-ig0-f177.google.com (mail-ig0-f177.google.com [209.85.213.177]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 3e4eae8d00028025 ; Mon, 7 Dec 2015 16:23:32 -0500 Received: by igvg19 with SMTP id g19so88190455igv.1 for ; Mon, 07 Dec 2015 13:23:34 -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=C9p+x1XFgR0FGnA++nX9HhU0U8hu5NONrOe2vgJAFg8=; b=knJjHslpiLUFZSrs4JE+C0bvxAeLdv+trmYAELx1FHEMKVEysfaKnuHv+PWK4Dv49L yz4OM2L8pNw5PqALdSOcuqVXAB1lHr8KHaHVrsb1rhD6b1D8kAraQlZDnrT1UeN93ICF bdV705eoo56WBdhc0FdYTl6ZJZlMEoT2pkK92f+LNjVKSAgBukQTG6TBiaXuSuqy6Rgi 3bvgn9UIjnvhitNYt0RTEXSyfqprYFmPBrYLyJ0OB73ztPLPWHHTAgcEg/TnTnkRD0aK uKnEb+Qs9io4xHIVOoppmRi77DMJOdWg6RIDv02G69vy6SdmWZ0a8xsCPw386Syz8WNo liKg== 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=C9p+x1XFgR0FGnA++nX9HhU0U8hu5NONrOe2vgJAFg8=; b=K2n/dtJcTbY2+MXPSF4n3Wy+WHSnL0vueqAip8gC+5pXwPcQQbszUSKd0AeiLiyUjQ n4RWrpcK2dNluVD8tnLp/hpYqU5e2ef5ftXLG88S9F7fd5/tOKFabqS8whlRiS334VSH LlWQdq/+PxO40b9p5q9ia+P/pWFtugOupkiiWVcoLjgj2mAL37MrxtpC1+OLYgn78AYJ LNunfnncUTwCeviKWKj/RTkryJWcCpE//h789pTSLi07cpMb6pgq1Uh1S5+u4cXKXTmd hsl2RAz749GELctk7ck2sTgcmcWdUZW0RD8hWZPjDrFO5ktarQJT6+ktdUbSkeCHFPRo UHNA== X-Gm-Message-State: ALoCoQmhkr9QbNVPR/j/uMBtl5WAJCeAjQ1mAXWy6+1xAOrKR+JaiWIVeyb660JHVAzcO6VCYwnl1469MR3PuYDvu4X7vDj0Ig== X-Received: by 10.50.79.196 with SMTP id l4mr509367igx.77.1449523414647; Mon, 07 Dec 2015 13:23:34 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id l5sm218764ioa.17.2015.12.07.13.23.34 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Dec 2015 13:23:34 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn Subject: [PATCH v2 11/18] fs: Ensure the mounter of a filesystem is privileged towards its inodes Date: Mon, 7 Dec 2015 15:21:20 -0600 Message-Id: <1449523289-144238-12-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: 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);