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: 7747761 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 2EA779F387 for ; Wed, 2 Dec 2015 15:42:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68686204A7 for ; Wed, 2 Dec 2015 15:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BFC720481 for ; Wed, 2 Dec 2015 15:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932917AbbLBPmo (ORCPT ); Wed, 2 Dec 2015 10:42:44 -0500 Received: from mail-io0-f171.google.com ([209.85.223.171]:36642 "EHLO mail-io0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932891AbbLBPmd (ORCPT ); Wed, 2 Dec 2015 10:42:33 -0500 Received: by iofh3 with SMTP id h3so49564817iof.3 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=PycWe4OBYIiNV0Tp6iy9gMt1ELtSNkBtxIcX34P5+ewjPtGpfZQPDJ/ll7Ygow38oy WL9idQajU/GXKQVltvj1lPKVbnxygu7F+NnwaUUFygosLSrqOfagJpaIsCcEqJO+7gze aIog+fWi0CDMKx7THWLjLxb3i4n0iqHXvUcYZHm4NXK1gB4X7SmX3NO4DdFo+s2BiJjD eInzKqQ6iHmLa/e07zC+42wojValRzlD4aurXWSCO61OUp/W9O5RoU2poJORLVt8PANj QmSc1bBezKhhfAquoBOG6HQvTMIJ8bEEp7RmyDioray6LfvMX/yCY1QvDnaHg+NfYZsK 1RTg== X-Gm-Message-State: ALoCoQnqrlOD/YryspPDiBM6z0VWw+p9qWM/UwZCUvCcxLvZjVhTSQWffTxCO9xZptsl3wseu2r1 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" Cc: Alexander Viro , 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 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> 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=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; }