From patchwork Mon Jan 4 18:03:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7950251 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 1DB0DBEEE5 for ; Mon, 4 Jan 2016 18:47:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7483420306 for ; Mon, 4 Jan 2016 18:47:24 +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 9815520304 for ; Mon, 4 Jan 2016 18:47:23 +0000 (UTC) X-TM-IMSS-Message-ID: <518312d000022861@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 518312d000022861 ; Mon, 4 Jan 2016 13:47:43 -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 u04IiEU1017644; Mon, 4 Jan 2016 13:44:16 -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 u04I4iej225786 for ; Mon, 4 Jan 2016 13:04:44 -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 u04I4gpI013588 for ; Mon, 4 Jan 2016 13:04:44 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CeBAAys4pW/7TVVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iToExPjGKV4VUAQWMHgEBAQEBAQEDAgEaBgqEO4IRjjuONYhWlmqFYoxuNYEXZIIEDRwdgV9TAYUPAQEB X-IPAS-Result: A1CeBAAys4pW/7TVVdFeGQEBAQEPAQEBAYRJiFm1aIYPAoFoAQEBAQEBhUABAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iToExPjGKV4VUAQWMHgEBAQEBAQEDAgEaBgqEO4IRjjuONYhWlmqFYoxuNYEXZIIEDRwdgV9TAYUPAQEB X-IronPort-AV: E=Sophos;i="5.20,521,1444708800"; d="scan'208";a="5070757" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 04 Jan 2016 13:04:38 -0500 X-TM-IMSS-Message-ID: <75b6a7ec0010349b@nsa.gov> Received: from mail-ig0-f180.google.com (mail-ig0-f180.google.com [209.85.213.180]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 75b6a7ec0010349b ; Mon, 4 Jan 2016 13:04:13 -0500 Received: by mail-ig0-f180.google.com with SMTP id ph11so250379325igc.1 for ; Mon, 04 Jan 2016 10:04:37 -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=T8+t0121OLh6dehfejZjxFR209o5iR0aqzYKDqpYcDshU5SuPpEww5l/pF37yWKaMY MoNKXC8kvB0qII371QhUtBF4k/+/WlJWFF3jAqJfcdpVQgnkEU6MNeT1hJMf+C8srOu3 VRsoxjUj0nxuBOfZuq4UngBzgdPiOF8tA9fwBvyISbqTQ2bXhbCfFPYO3euTmhEN22Ph UgVD+LDluOurYpQE+mIBg6JoOKT2qhTGKmhH506nrJvZpEpHTqJdnmasn7cZrwYFcxf5 eRn+knfAgYJ5XfJVgQQuFXnVmvJseD/Mj2bgqO7aZTJuXdizOKBot5p854CwPGyjXadW PHTg== 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=hZTRHhv3hiIflPMvVR3V1ijDqfRwXRC1+pW4Y/5qga+Kndi90otQauTEgo6ijr4kUU m/XDofATYDy8HbMdB4XoG1uxFuGf1c+TOR0H2I9IWZTI85Bq4W/4uunDaKDx1aBvFl/1 KeJ6Y3fkvMzldXBKWYbYi/cSEKPrgAj41oAk4m0X2UOGdz5KDX+k0dRNAXRsW2YF1Sra AYt37me9Ri0A/nKgFCv2KmScjII2MDBeKBlfkMbamSE+Sg03bkJQv+tlz4KJ1CGiKIL4 qfWuLtK/3uq/QVd/xdMsgscVpHvjY33Nq8djUjw3IsdEabHgnPU/OyllqBrGwk6BWpZs 0sJA== X-Gm-Message-State: ALoCoQmeAJgW3nLnZNinIdSXjBjet9Ph5yfc4WlfvtbOZgFfylrcVZJ8EKT1zIHcdBNbcntLHbuWUs/UHwXytVBwoNPTvzDjGA== X-Received: by 10.50.142.105 with SMTP id rv9mr77939627igb.72.1451930676924; Mon, 04 Jan 2016 10:04:36 -0800 (PST) Received: from localhost ([66.64.121.229]) by smtp.gmail.com with ESMTPSA id c143sm10378774ioe.21.2016.01.04.10.04.29 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 04 Jan 2016 10:04:29 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn Subject: [PATCH RESEND v2 11/18] fs: Ensure the mounter of a filesystem is privileged towards its inodes Date: Mon, 4 Jan 2016 12:03:50 -0600 Message-Id: <1451930639-94331-12-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> References: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 04 Jan 2016 13:14:22 -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,RP_MATCHES_RCVD,T_DKIM_INVALID,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);