From patchwork Fri Aug 10 16:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10562941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57E8414E2 for ; Fri, 10 Aug 2018 16:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4808F2BC6E for ; Fri, 10 Aug 2018 16:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C8AA2BDC0; Fri, 10 Aug 2018 16:14:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6F102BC6E for ; Fri, 10 Aug 2018 16:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728066AbeHJSod (ORCPT ); Fri, 10 Aug 2018 14:44:33 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:39654 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729201AbeHJSoc (ORCPT ); Fri, 10 Aug 2018 14:44:32 -0400 Received: by mail-wm0-f49.google.com with SMTP id q8-v6so2476439wmq.4 for ; Fri, 10 Aug 2018 09:14:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5aT6bK3HStGldXoEBJCiy+2H6qBy1y2RG4MupsJ1cX4=; b=QIIqCTrOwDHYuKmz/ezKnjvbcBKxPq83RDOgWS8juDuN0FeV1hwfSd6L8Bh0Ma3ir2 35Qs2PleBcvFM1kGc/YiEFbST45eY9GZFbSRRGlXHUUFXPBuE+9hsqqGsp5o2Xm69Xm0 uzzJxPDzKRy52ilVl/+CTxsh5JeZoJT0d1mLzFsVhp2oZbEvknjU5KaId85cPleFt7sa QRYGaYBMXCtqZBsJX2PvV3GlUor/Wp1oySppdUdr0XB2tenaTgGnUJF/LTKstUeig3h8 B2Ev1lNZ6+gRyvwKIhXNLGy7AFzL+lOEi0w+nxRmx8PZShIsnFQeXmjmNLMabtlYKPgl 8OAQ== X-Gm-Message-State: AOUpUlE7KyJbr7d76y273c9bGCrpLavAr+4yNQUK7ycllZvBWoMQoz1Q Dot93kSU3TAbUvS/G8Uu0RvmVoqThdE= X-Google-Smtp-Source: AA+uWPwL8eRDuXZuIWlW4L0y9ATLFcPHi+vckcGQJZj/wkoxZePJ4wCE/Lv0lVD8npRBit/GsnP6hQ== X-Received: by 2002:a1c:2094:: with SMTP id g142-v6mr1801828wmg.144.1533917641491; Fri, 10 Aug 2018 09:14:01 -0700 (PDT) Received: from localhost.localdomain (u-082-c008.eap.uni-tuebingen.de. [134.2.82.8]) by smtp.gmail.com with ESMTPSA id m13-v6sm9987615wru.93.2018.08.10.09.14.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 09:14:00 -0700 (PDT) From: Christian Brauner To: linux-security-module@vger.kernel.org, containers@lists.linux-foundation.org Cc: serge@hallyn.com, morgan@kernel.org, Christian Brauner Subject: [PATCH 9/9] capability: add cap_set_nsowner() Date: Fri, 10 Aug 2018 18:13:35 +0200 Message-Id: <20180810161335.27036-10-christian@brauner.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180810161335.27036-1-christian@brauner.io> References: <20180810161335.27036-1-christian@brauner.io> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP cap_set_nsowner() allows to set the rootid of file capability sets. It can be used to set the rootid of a target user namespace as seen in the current user namespace. This allows a user namespace to set file capabilities in lieu of another user namespace. Signed-off-by: Christian Brauner Reviewed-by: Serge Hallyn --- libcap/cap_file.c | 16 ++++++++++++++++ libcap/include/sys/capability.h | 1 + 2 files changed, 17 insertions(+) diff --git a/libcap/cap_file.c b/libcap/cap_file.c index a1f3891..9a1643c 100644 --- a/libcap/cap_file.c +++ b/libcap/cap_file.c @@ -384,6 +384,16 @@ int cap_set_file(const char *filename, cap_t cap_d) return setxattr(filename, XATTR_NAME_CAPS, &rawvfscap, sizeofcaps, 0); } +/* + * Set rootid for the file capability sets. + */ + +int cap_set_nsowner(cap_t cap_d, uid_t rootid) +{ + cap_d->rootid = rootid; + return 0; +} + #else /* ie. ndef VFS_CAP_U32 */ cap_t cap_get_fd(int fildes) @@ -416,4 +426,10 @@ int cap_set_file(const char *filename, cap_t cap_d) return -1; } +void cap_set_nsowner(cap_t cap_d, uid_t rootid) +{ + errno = EINVAL; + return -1; +} + #endif /* def VFS_CAP_U32 */ diff --git a/libcap/include/sys/capability.h b/libcap/include/sys/capability.h index 42d8154..a9515b6 100644 --- a/libcap/include/sys/capability.h +++ b/libcap/include/sys/capability.h @@ -85,6 +85,7 @@ extern cap_t cap_get_file(const char *); extern uid_t cap_get_nsowner(cap_t); extern int cap_set_fd(int, cap_t); extern int cap_set_file(const char *, cap_t); +extern int cap_set_nsowner(cap_t, uid_t); /* libcap/cap_proc.c */ extern cap_t cap_get_proc(void);