Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3929031pxb; Tue, 17 Nov 2020 07:12:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAXLOSYNgADcbhWORt9CmvoO6fnX8ZMwV5goRuJGTIZIijIM9x3PJ2NI6DRQ99i/ySSzLf X-Received: by 2002:aa7:dd17:: with SMTP id i23mr20540180edv.276.1605625924867; Tue, 17 Nov 2020 07:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605625924; cv=none; d=google.com; s=arc-20160816; b=eukybq9fasKz7YaDTtfjbU/wi0exXBn4pXTYcJIkukim2W4BXtDpQC9eVfzmfgesO8 XBWQZB26RvoY4m23PV1ks+q94lNBLC025M0SkpUMW62bWxYWBxN/3RT8z7Z+FAhM6PrV ZApPS7o4nEsNXFpyuZ+LQD7N8lRofweKDJsjwYZQtebBwuVBh3ZzaTfUdKZvS0w1ZAvX +fUeUs36k2IQ1wre7AzH7rKbf9kpnM8XY1l6RxN+Jb9gXIsrqzF9m+lKp0dofBwelInn 33AseHxZvb7oLQ8O0aOicixg53PpsUEsdTK1Kbi8AN5LvRBVn0FJqsvhMyXmkE+fw3MR gpIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date; bh=2QrDicEXzdiomb4ggASRcCvEgOrXcoeOvwssAWwAyPQ=; b=bqjDS2qrGqyWJxkgHURnmUL53rdNC6CXLeWQrs7xflr5g1yUJMDWlNwtBxlNWAQClH IAXfkYSeBFin8GQ5LnjjM6MaTk2r8uTuDFG/dsNyuDRZwcNf1LCg/nSBcQHMPbBUO6Te h3SAaLpEfBQkdzwEvy0qbiFkJm6qyRqW6aIUZcFhiZlLaZJ45qWLZ5R+WRPU1kEG49rC f0SnGJzdnLeBVGcSh++kh8BNuiOcjj84xkpSLnShjS5badIrIOVgUJLxo+fY5+bIWfN8 5m87Q+BDBitabsttmwt3a4TiED3kD9ejfgbMpsIx87kCX+NAy/690y8t+z7xAZE8Hxy7 acZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si13499095ejt.298.2020.11.17.07.11.41; Tue, 17 Nov 2020 07:12:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729114AbgKQPI6 (ORCPT + 99 others); Tue, 17 Nov 2020 10:08:58 -0500 Received: from mail.hallyn.com ([178.63.66.53]:58964 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728830AbgKQPI5 (ORCPT ); Tue, 17 Nov 2020 10:08:57 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id D03AC1105; Tue, 17 Nov 2020 09:08:56 -0600 (CST) Date: Tue, 17 Nov 2020 09:08:56 -0600 From: "Serge E. Hallyn" To: lkml Cc: James Morris , =?iso-8859-1?Q?Herv=E9?= Guillemet , "Andrew G. Morgan" , Casey Schaufler Subject: [PATCH] fix namespaced fscaps when !CONFIG_SECURITY Message-ID: <20201117150856.GA12240@mail.hallyn.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Namespaced file capabilities were introduced in 8db6c34f1dbc . When userspace reads an xattr for a namespaced capability, a virtualized representation of it is returned if the caller is in a user namespace owned by the capability's owning rootid. The function which performs this virtualization was not hooked up if CONFIG_SECURITY=n. Therefore in that case the original xattr was shown instead of the virtualized one. To test this using libcap-bin (*1), $ v=$(mktemp) $ unshare -Ur setcap cap_sys_admin-eip $v $ unshare -Ur setcap -v cap_sys_admin-eip $v /tmp/tmp.lSiIFRvt8Y: OK "setcap -v" verifies the values instead of setting them, and will check whether the rootid value is set. Therefore, with this bug un-fixed, and with CONFIG_SECURITY=n, setcap -v will fail: $ v=$(mktemp) $ unshare -Ur setcap cap_sys_admin=eip $v $ unshare -Ur setcap -v cap_sys_admin=eip $v nsowner[got=1000, want=0],/tmp/tmp.HHDiOOl9fY differs in [] Fix this bug by calling cap_inode_getsecurity() in security_inode_getsecurity() instead of returning -EOPNOTSUPP, when CONFIG_SECURITY=n. *1 - note, if libcap is too old for getcap to have the '-n' option, then use verify-caps instead. Signed-off-by: Serge Hallyn Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1593431 Cc: Herv? Guillemet Cc: Andrew G. Morgan Cc: Casey Schaufler --- include/linux/security.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/security.h b/include/linux/security.h index bc2725491560..39642626a707 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -869,7 +869,7 @@ static inline int security_inode_killpriv(struct dentry *dentry) static inline int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc) { - return -EOPNOTSUPP; + return cap_inode_getsecurity(inode, name, buffer, alloc); } static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags) -- 2.25.1