Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3975620pxb; Tue, 17 Nov 2020 08:15:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+6Yb6az3yabjv4LReP5+TIfNyn5aSAk6QZT1amkOO8aIH5pCUz13lKhjqzYHw79ZbEoML X-Received: by 2002:a5d:5342:: with SMTP id t2mr238178wrv.243.1605629743519; Tue, 17 Nov 2020 08:15:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605629743; cv=none; d=google.com; s=arc-20160816; b=TPcD75yeBBnYFD2UjhlNXu+WcSsUMch54ie+ZM/joOZqQpkeB+ZLQAktAAFEuCgPF0 eRxR6J1rsZ848VhSqp27bBEaE2GeUvw0qvDUlozGnQAW236EJp4JwioPlANEzedggL7x JYe5NUofNh6S7q6SQ0ALMjVR3oDnWaaS3nqbG9LsOMvQKN+23YoViGUQNjQHZLGJI9I8 3SHCwZ5XCsvJu2jWEaOKWy6b97AAvwT9n/55uZtvEKXa7TEm8LAU8fkIkz1WHIEgtxwC ue24r9BEO2jlHlpyFF3vO0daQd4uqZkcj0W2fTVzsi/8urdYqZocvKV3rHX2r265CD2+ YskQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=To7TrPVgo3qyeXT8a81UEsgQYKhaE0CKyJO5uSQSCzo=; b=coV0CtSMKRW/SE9o/rpVkqhomhCsKUlKa9GOaVEKpaz1hfsl65cCRvO397sfF2jBZ7 ojeOGokkIramkqmQNwYlVRRIkudCXiTVw3ZasE/FAFLKdYt0ecCgKIaCEeH8Rx8Fxn/t 4f/e6Zo01p/pMG1GRs4fqPoGR9at8Uq5zQwljnE2yrP0GJMuPE34nCydFKY23RkdCLbL nd0f6PG4uveheRw3V3vXS1DGwMgEGMSWGWlI7DfuTi3srDBb7v4/kXsziqZ+/DcYiage QpnkiqxGVq8vQR9J5h7Tk6GWjZJNo1x15TEqQPQ/VxbQKsGVTdzammJ+NdisrexTeTy4 X2/w== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb31si11755277ejc.187.2020.11.17.08.15.19; Tue, 17 Nov 2020 08:15:43 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbgKQQLu convert rfc822-to-8bit (ORCPT + 99 others); Tue, 17 Nov 2020 11:11:50 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:40008 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbgKQQLt (ORCPT ); Tue, 17 Nov 2020 11:11:49 -0500 Received: by mail-qk1-f194.google.com with SMTP id y197so20843109qkb.7 for ; Tue, 17 Nov 2020 08:11:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4jQUk+uUdUDMuBpooa0vLGDCE03iHWsS7jO3tfLTcGg=; b=avCj0kArPnH5IYX1Dg5Qrm1oOcfBRUXPBHC6DEAbrHy4S6tKBMp6Gw51H/J9rMF/sx uWCWEdmDz0ZV0NpTynLdXxIxeMjqOxTnKwLSMzBjb1+Qpo7yIuZP/QEhDJ4a6NtYnXjs fPR0aw1FJFIiM+NuWE5UO1sc6DHfoxfNlYUmX5QxopYc5PCfNMpBVzi2JWMYZNV1aK5k k/WYSlO0mZZAeMj0yzoL3xK1VQPAeyrY0vo2LCyzELCr3F2mpCSWxetsrj8QwW73vp9K SUBirg787U5ADHUbI/YOiniQoSRsDeyw1T0TBdDGxfNkbERh22cKshlhA7OG1fIvPpye 44fQ== X-Gm-Message-State: AOAM533F1QAdlraD08TnLGudmdvSXmvT0qEML2b1v8vuG4T/Lne1vSgs cMcc8YHd5/DLDWQAxDmmuFYjk4c3N0dP5v0QpY6gWA== X-Received: by 2002:a37:a249:: with SMTP id l70mr245194qke.79.1605629508326; Tue, 17 Nov 2020 08:11:48 -0800 (PST) MIME-Version: 1.0 References: <20201117150856.GA12240@mail.hallyn.com> In-Reply-To: <20201117150856.GA12240@mail.hallyn.com> From: "Andrew G. Morgan" Date: Tue, 17 Nov 2020 08:11:37 -0800 Message-ID: Subject: Re: [PATCH] fix namespaced fscaps when !CONFIG_SECURITY To: "Serge E. Hallyn" Cc: lkml , James Morris , =?UTF-8?Q?Herv=C3=A9_Guillemet?= , Casey Schaufler Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Andrew G. Morgan On Tue, Nov 17, 2020 at 7:09 AM Serge E. Hallyn wrote: > > 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 >