Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9172267pxu; Mon, 28 Dec 2020 08:22:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvXvjBkNE3TgEmnBVBpEw81/GITARXGCWuk0BjE8YkMb9memYitxnm7ERWxqwj4UXx+zXV X-Received: by 2002:aa7:d3cc:: with SMTP id o12mr44695521edr.235.1609172524150; Mon, 28 Dec 2020 08:22:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172524; cv=none; d=google.com; s=arc-20160816; b=DJH7JpXeanOHtdJVJxNI4qquj/+d+giAni5L+Xk+AckpeCS/VXMo+5hCLmu1UqYri6 waJ/Hc+OOLdF2D8QAiZEKivpRKDwQZCpMhnVpHiRcuoh0smrgdmxMLENqoUSHlhJtY/V O67A4KFZY51y0sTiUjfiFX9OaOTzGfnluUMH6CpivEPabyMQWOTIR/Uulv/TociHnwLJ Tki35MLN/+Oos9Cc2ZGdEnEB8Ufwf0DTG1Spsb3JL/2o6eHlaaWin9PNgmkv5Xaf95pv F5DDRzhRLewhqAB3KZhn+7JLYEjHraw0zJ339WCTROpwyWxCjkHrlHZeZVM3nKYrugFu LaQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aDlZjBoKeV+g8UE7/sfdZmv6QUXB7gtSGnJaTxDMyG8=; b=BuUL6HPm3NPPCkNWzR0qG1haMQbW734NgX9jR5iLq1nUYy09l6rNhAoC9qZobs2Fqk IHhVdh1uAWvM9xMX1Mqwp3PLpPPt/GOqCIYjAGdoAmNfO5sxbVMZGeNgcgx6eIScmb9M zVm2h4IA2TlOjIG4KTWav/e+mOCn5aYKUj4/SzrHbziJE1mbQSvuFzi10Cuhde2yopXV 9JVUCI6JxlGC1MLwQQXHcWxuzlEOWCj7gtq78t7xyDgTjpFH6I0myHuHnZcDbZxuwn/2 fJO1QdJhAx8dpGAQ8v57UOiB2VTZ98kq22sVpnvUnKjbbAzxcuiOX6A26Sl+SjEK0WzX aa7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="A//vHyDZ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si18759901ejw.417.2020.12.28.08.21.40; Mon, 28 Dec 2020 08:22: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="A//vHyDZ"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731537AbgL1NRU (ORCPT + 99 others); Mon, 28 Dec 2020 08:17:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:45242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731528AbgL1NRQ (ORCPT ); Mon, 28 Dec 2020 08:17:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10B89207CF; Mon, 28 Dec 2020 13:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161420; bh=jtUNsOUZ5vABG6kent2Hwsx8WvaniRysXjh/JP2XXyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A//vHyDZwcHyUgA5DHAQIoB5yT1vaUOW2YCeC22fblWRR4GZ2VQmuOtQ5jygspSWJ lj1cFJSX6X0dxhxCV7YJpHHKsNi2xmmH8xR1LVcdyovPEmD3ahxivAUAE0ts5kR6ha HSjt8Qa88wY1hqTBAdz+e7uouqeFH00LUotgtm+M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Herv=C3=A9=20Guillemet?= , Casey Schaufler , Serge Hallyn , "Andrew G. Morgan" , James Morris , Sasha Levin Subject: [PATCH 4.14 178/242] [SECURITY] fix namespaced fscaps when !CONFIG_SECURITY Date: Mon, 28 Dec 2020 13:49:43 +0100 Message-Id: <20201228124913.445936891@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Hallyn [ Upstream commit ed9b25d1970a4787ac6a39c2091e63b127ecbfc1 ] 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. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209689 Cc: Hervé Guillemet Acked-by: Casey Schaufler Signed-off-by: Serge Hallyn Signed-off-by: Andrew G. Morgan Signed-off-by: James Morris Signed-off-by: Sasha Levin --- 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 ce6265960d6c4..dab093af4ee8d 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -780,7 +780,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.27.0