From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 515F5C4361A for ; Sat, 5 Dec 2020 17:51:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 122492311D for ; Sat, 5 Dec 2020 17:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbgLERut (ORCPT ); Sat, 5 Dec 2020 12:50:49 -0500 Received: from mail.hallyn.com ([178.63.66.53]:60704 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727466AbgLERlV (ORCPT ); Sat, 5 Dec 2020 12:41:21 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id AF1396A6; Sat, 5 Dec 2020 11:40:00 -0600 (CST) Date: Sat, 5 Dec 2020 11:40:00 -0600 From: "Serge E. Hallyn" To: "Andrew G. Morgan" Cc: James Morris , "Serge E. Hallyn" , lkml , =?iso-8859-1?Q?Herv=E9?= Guillemet , Casey Schaufler Subject: Re: [PATCH] fix namespaced fscaps when !CONFIG_SECURITY Message-ID: <20201205174000.GA3290@mail.hallyn.com> References: <20201117150856.GA12240@mail.hallyn.com> <20201129211542.GA5227@mail.hallyn.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org How odd - where did that come from? James, I force-pushed that with corrected bugzilla link to 2020-11-29/fix-nscaps. Sorry about that. On Fri, Dec 04, 2020 at 07:58:14AM -0800, Andrew G. Morgan wrote: > The correct bug reference for this patch is: > > https://bugzilla.kernel.org/show_bug.cgi?id=209689 > > Reviewed-by: Andrew G. Morgan > > On Mon, Nov 30, 2020 at 6:58 PM James Morris wrote: > > > > On Sun, 29 Nov 2020, Serge E. Hallyn wrote: > > > > > Hi James, > > > > > > would you mind adding this to the security tree? (You can cherrypick > > > from https://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux.git/commit/?h=2020-11-29/fix-nscaps ) > > > > Sure. > > > > > > > > thanks, > > > -serge > > > > > > On Tue, Nov 17, 2020 at 08:09:59AM -0800, Andrew G. Morgan wrote: > > > > 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 > > > > > > > > > > > > > > > > > -- > > James Morris > >