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: 7747911 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 783D29F387 for ; Wed, 2 Dec 2015 15:46:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A167E204E7 for ; Wed, 2 Dec 2015 15:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C19D1204E0 for ; Wed, 2 Dec 2015 15:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758730AbbLBPqZ (ORCPT ); Wed, 2 Dec 2015 10:46:25 -0500 Received: from mail-ig0-f173.google.com ([209.85.213.173]:38800 "EHLO mail-ig0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932849AbbLBPm2 (ORCPT ); Wed, 2 Dec 2015 10:42:28 -0500 Received: by igbxm8 with SMTP id xm8so35035048igb.1 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=RogJ51SjDQu9CNelCz+KAlFVAaG8Xonaju6OSLyYpvYRLiY32wdJz67aqesq+k2ZgI x7WYPhEwysKD4tOSHk+IT1O5JFAxlGwpnmjq7zC2lq0WqNYBMVXFw4cwCZbD7fTvR4Tj mC1t/3cueBCwf5OZrET5qPe6M4X/om3yhQufxx3ae01kVR9SEvv1K642DvTe4QxkSYv9 sBH/Vj4pRFw9lfXXW2YWGJiKVjW9Tx3yS/OgQkO2NyToqY829VQCNII1fbB2RcM5K8hJ NLOBWstosH6JttPFxpJpfLtbduEc6q0ZmHOVYHz0eMSH9reWkXPmyulqunPt1w3o1ypf xGuw== X-Gm-Message-State: ALoCoQlHKzoYl3UV8kRT+1N2tzkiDRO6ZKkK5d247aB7/kiejZp8fUBEoDT/nqPanu3Nwwthu6It 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 Cc: Richard Weinberger , Austin S Hemmelgarn , Miklos Szeredi , linux-bcache@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, Seth Forshee 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> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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=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 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);