From patchwork Wed Dec 2 15:40:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7748601 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 0E718BEEE1 for ; Wed, 2 Dec 2015 16:32:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6ACF3205DF for ; Wed, 2 Dec 2015 16:31:59 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8BBE620549 for ; Wed, 2 Dec 2015 16:31:58 +0000 (UTC) X-TM-IMSS-Message-ID: <2382b13f00017c93@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 2382b13f00017c93 ; Wed, 2 Dec 2015 11:30:37 -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 tB2GUOdJ011732; Wed, 2 Dec 2015 11:30:25 -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 tB2FgYr1185598 for ; Wed, 2 Dec 2015 10:42:34 -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 tB2FgWlG006648 for ; Wed, 2 Dec 2015 10:42:34 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1ChAAA0EF9Wm7LfVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBASoKAwEPUTQBBQEcBgESIogNoRWBMT4xileFVAEFjCMBAQEBAQEBAwIBGgYKhDqCEI42jSp2iEGWTIYhi2s2gReCZw0WB4F1UwGFbgEBAQ X-IPAS-Result: A1ChAAA0EF9Wm7LfVdFeGQEBAQEPAQEBAYRMu3CEFoYOAoIYAQEBAQEBEgEBAQEBBgsLCSGEYwEBAQMSFRkBASoKAwEPUTQBBQEcBgESIogNoRWBMT4xileFVAEFjCMBAQEBAQEBAwIBGgYKhDqCEI42jSp2iEGWTIYhi2s2gReCZw0WB4F1UwGFbgEBAQ X-IronPort-AV: E=Sophos;i="5.20,373,1444708800"; d="scan'208";a="4986129" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 02 Dec 2015 10:42:34 -0500 X-TM-IMSS-Message-ID: <2356d4b500015efb@nsa.gov> Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 2356d4b500015efb ; Wed, 2 Dec 2015 10:42:42 -0500 Received: by ioir85 with SMTP id r85so49517486ioi.1 for ; Wed, 02 Dec 2015 07:42:33 -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=X0iT0v8cGvWIxbEeA0y3dSrVz8woiGTcdwoggH9IEks=; b=i2GvAfeG0mf2Er014p3ZXiHusODM+8EpTNUbMha43ijusWdLNMxDOcniKv/idPift8 fpMcNwTlySs0gSn6e8WFYzfh4WfVOuVNeAyJCksIK3GN728NwyUq+p/TuC+Yu5WAl2Xm tPk69SzYHm/mDSnqYcsHUGyXMt7OlvzdjKIyRJxI/LuplLMBHxqetnI3G3xPVZGj6x2d uDxmunNVobJ8Nr6ETtBROH8rPPbg5z89PIBtYb4eeOeuoUlsSwcN0/hIyVPLZwjP+FlH xaPN3CKC0oSJP3oBiRxeaojjmjh4EZU0hCDtIdmnkNOvS+FPm+a6/B/atPEJ8G+Owv68 HCeA== 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=X0iT0v8cGvWIxbEeA0y3dSrVz8woiGTcdwoggH9IEks=; b=HC6hsCrCiOlUl5IW5xHvkGV8/x6ydFlCulJmtSuSK48fahRD4AwA0ZO7f5gQnGSsEF Y4tjEkkKGPtfsH0Jd0t5bDpwED98/sQFXLb9W9nUR0JvkyHCu8336K3/pzJlisITGHe2 FVwUNgbVkPVfsg3QesHTI5mHuPUBnILvluuAb0OfQ/naFnat1bKvt2IBolE/ICPG3Atd txVhYuC2i3+B7EKPmkqb/Gt/06jHiLOxAjJ1RIrTjXoqc/Trud4IhMiICME5skxjOlGU SjbhmaAxOl36ZsKzrG6Gy0FEfE1UzLfcGiraFOUw4rghQAyNHCThTU+6vIYVQz8JdZy5 eA8g== X-Gm-Message-State: ALoCoQkvqxFtFMbjEVxa8HvUIItkBMvRnTE2Nx2U4kqteWgmnWYdivkCC2MAk+HU1EGj3mWVf8r8 X-Received: by 10.107.159.199 with SMTP id i190mr3927118ioe.29.1449070953115; Wed, 02 Dec 2015 07:42:33 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id uf7sm1334545igb.11.2015.12.02.07.42.32 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:32 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH 15/19] capabilities: Allow privileged user in s_user_ns to set file caps Date: Wed, 2 Dec 2015 09:40:15 -0600 Message-Id: <1449070821-73820-16-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, Alexander Viro , 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 A privileged user in a super block's s_user_ns is privileged towards that file system and thus should be allowed to set file capabilities. The file capabilities will not be trusted outside of s_user_ns, so an unprivileged user cannot use this to gain privileges in a user namespace where they are not already privileged. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- security/commoncap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/security/commoncap.c b/security/commoncap.c index 2119421613f6..d6c80c19c449 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -653,15 +653,17 @@ int cap_bprm_secureexec(struct linux_binprm *bprm) int cap_inode_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) { + struct user_namespace *user_ns = dentry->d_sb->s_user_ns; + if (!strcmp(name, XATTR_NAME_CAPS)) { - if (!capable(CAP_SETFCAP)) + if (!ns_capable(user_ns, CAP_SETFCAP)) return -EPERM; return 0; } if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) && - !capable(CAP_SYS_ADMIN)) + !ns_capable(user_ns, CAP_SYS_ADMIN)) return -EPERM; return 0; } @@ -679,15 +681,17 @@ int cap_inode_setxattr(struct dentry *dentry, const char *name, */ int cap_inode_removexattr(struct dentry *dentry, const char *name) { + struct user_namespace *user_ns = dentry->d_sb->s_user_ns; + if (!strcmp(name, XATTR_NAME_CAPS)) { - if (!capable(CAP_SETFCAP)) + if (!ns_capable(user_ns, CAP_SETFCAP)) return -EPERM; return 0; } if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) && - !capable(CAP_SYS_ADMIN)) + !ns_capable(user_ns, CAP_SYS_ADMIN)) return -EPERM; return 0; }