From patchwork Fri Aug 10 16:13:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10562935 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 817C214E2 for ; Fri, 10 Aug 2018 16:14:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718B02BC30 for ; Fri, 10 Aug 2018 16:14:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65D4E2BDBA; Fri, 10 Aug 2018 16:14:01 +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 15D382BC30 for ; Fri, 10 Aug 2018 16:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728317AbeHJSo3 (ORCPT ); Fri, 10 Aug 2018 14:44:29 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33088 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727698AbeHJSo2 (ORCPT ); Fri, 10 Aug 2018 14:44:28 -0400 Received: by mail-wr1-f65.google.com with SMTP id g6-v6so8799480wrp.0 for ; Fri, 10 Aug 2018 09:13:59 -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=kTkE68RjSPWmr1zwAEbmluNorPCRRAlE1WzSyB96EnU=; b=Nk89/HCQK+rtYwg/92r/1jbTWlM0EU8I49dP4pIFS+xCeh5FrHm8Yjdutr7l4qoMB0 AMajnKAxKSL2ASZID82Kkwio0nCMWTI9XEPYD2PcrDlBBhDb3jP9fyeK7YMHV4S1S8XF ACEqbhH8VTPGMid7QzuklLVFwhVk180zXK4A0XEtHCT7W6PFCBG26t1NNrpEaPdLTuAr hi7bSTKoULdOrIofO3JibAP7aGxfEaBERRHuT5SBmsO2BG90gNsBTGM7a/bl1MaCYTte 6qonoDHlb5MJp5Ww5gXkN0+rAHD2Cl/vOhjq9VPBUTOs9aW6tKRMT6w7GZuyxDSvHRSv PfVg== X-Gm-Message-State: AOUpUlGPW2tHHy10dCRvqHdPx5GFiDo8Jhu6wBrrqXTGizJUZpfBwy0I BQteOmXCj5DMS3uC/XBf4qKe4V9DPCw= X-Google-Smtp-Source: AA+uWPyR6Ok47l57OvuzN1mQh5Yon5bN30MpiSxCjVLqh+zm4ZtOVvTizvh3jcbEZ4CEpT6rwcqFSA== X-Received: by 2002:adf:a197:: with SMTP id u23-v6mr4922191wru.50.1533917638404; Fri, 10 Aug 2018 09:13:58 -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.13.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 09:13:57 -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 6/9] capability: add cap_get_nsowner() Date: Fri, 10 Aug 2018 18:13:32 +0200 Message-Id: <20180810161335.27036-7-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_get_nsowner() allows to retrieve the rootid of the file capability sets in the current 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 eb98bf7..7acd60c 100644 --- a/libcap/cap_file.c +++ b/libcap/cap_file.c @@ -277,6 +277,16 @@ cap_t cap_get_file(const char *filename) return result; } +/* + * Get rootid as seen in the current user namespace for the file capability + * sets. + */ + +uid_t cap_get_nsowner(cap_t cap_d) +{ + return cap_d->rootid; +} + /* * Set the capabilities of an open file, as specified by its file * descriptor. @@ -363,6 +373,12 @@ cap_t cap_get_file(const char *filename) return NULL; } +uid_t cap_get_nsowner(cap_t cap_d) +{ + errno = EINVAL; + return -1; +} + int cap_set_fd(int fildes, cap_t cap_d) { errno = EINVAL; diff --git a/libcap/include/sys/capability.h b/libcap/include/sys/capability.h index 0976fa7..42d8154 100644 --- a/libcap/include/sys/capability.h +++ b/libcap/include/sys/capability.h @@ -82,6 +82,7 @@ extern int cap_clear_flag(cap_t, cap_flag_t); /* libcap/cap_file.c */ extern cap_t cap_get_fd(int); 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);