Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp486447pxu; Fri, 4 Dec 2020 08:03:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeKduWObIKkXhPejGE5fVYkzoDSdNwVTakJ+oey3U/5y7QAfnhO37GigClLjLyjV7HItvF X-Received: by 2002:a17:906:a244:: with SMTP id bi4mr4413922ejb.59.1607097828576; Fri, 04 Dec 2020 08:03:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607097828; cv=none; d=google.com; s=arc-20160816; b=cuoqWKT4/FKAYscPNHF/jH0mEMASg6V6w64mzuPkLDQ4t33tpW7QqKevKwahusMoiy 8AboIntFDIfcScdBNVFvs7J5FUzivdGK+HQSRVSMJ0LqBQ8AhzRquk7eHgfXDO9fKWpB y5p57uZVX8kzLqgpoYGnDUc27n/uRY9p3rgXsJt2SDjsjKNU7sfvw+rsGcJ4ig2EFEde IA7rDqtDpTZ76aDyb4SGpbkg1I8qwJ8ksrzo8VonG+xnnHr+/6kinxlT4LIy5xtPi1Lg MnCgaiLrcqxgpKmP8+q0lQkv9luHuUMYjwnEDsgT8qJFQaCCx7sOe5c4y3MPxdif5JHs SPcw== 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=KAP5s0NlHxJsb87pFSIwrUWygy9Vdy3HGAWFVhva1y8=; b=jjzgsh/wMbFYFCwH+34xopKBkyaExcNDXaZAhRitqsjqAfh6ethJhuL6Mh5xNaj6iy w0RaQ7FGVZIk6F8wH3D5qo5SP6LrjdMCUtza7YRXNoGdrLWA9UH8BNztFnqVub1zfOIt nlRV4GmJjxf+moAY95YPoWhCRgzR4Hi6Vs1Ct2XAPHDN3of1o1Ka5eDMbHukgeb891jb stz0LUNzxDIH3qC590pcxb1PhWl3VsuBzOlXSXMLsFcVXMQyCOO6pF1UVLKokD5kHUzx lSmcMa3g1x8ZctuoerwflEXeliHmReb4gLOE9u5DH3gAKyuFU9GzhT5Ho5bc97QadghV qQUg== 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 by4si1531385ejc.732.2020.12.04.08.03.24; Fri, 04 Dec 2020 08:03:48 -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 S1730658AbgLDP7N convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Dec 2020 10:59:13 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:46070 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730648AbgLDP7M (ORCPT ); Fri, 4 Dec 2020 10:59:12 -0500 Received: by mail-qt1-f193.google.com with SMTP id v11so4199612qtq.12 for ; Fri, 04 Dec 2020 07:58:51 -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=Va60PHKbXcNtcvtJiWN0ujbNwxJ04G9rj4CXUNzPJ2U=; b=UXJF4+qirH48LGvYnES34iTvcKLrC6oFIyeFJVNyl5n9TGJAU0LzVUMJ05InxPeeJ4 XDBDSLDehlsBL3Q5/3CzelkrlmdU9Lb1mTFWDGNSOO8kSB/HzflZ9SFJt4W3VQISKCKw NbtRX6o3CWbGUyJK5cydCfmaFdjH9AJWuiQEpovzI+J8Q5XW9zgemDIpZ+ZYZxBng6Hh l5fb6vt2FGKoM7X7HuvkSw/V0IH/umyzW18gvY1roJoyg2FVueny+T0oi/lt3UXoEzqj 6yjmY1edIdnfwQDVMcVM4OUxELSLnPwrYGnG5v8cEVa/dSWiRg/HiYyAtMiUZNIhA1UA 3apQ== X-Gm-Message-State: AOAM530JI3dN7ZnYVW8dWqKV1k9CAyB9327LRJLJgwfBOzsz6BDKy4h/ rl8YXGuHRd+9+FqkW6A0VI5p67SO5xg+CPR42Xmdaz94xu3ddQ== X-Received: by 2002:ac8:d0e:: with SMTP id q14mr9764842qti.37.1607097505622; Fri, 04 Dec 2020 07:58:25 -0800 (PST) MIME-Version: 1.0 References: <20201117150856.GA12240@mail.hallyn.com> <20201129211542.GA5227@mail.hallyn.com> In-Reply-To: From: "Andrew G. Morgan" Date: Fri, 4 Dec 2020 07:58:14 -0800 Message-ID: Subject: Re: [PATCH] fix namespaced fscaps when !CONFIG_SECURITY To: James Morris Cc: "Serge E. Hallyn" , lkml , =?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 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 >