Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1294203rdh; Fri, 24 Nov 2023 09:06:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+fHqVPvMa6lWNuFOZhrmdA/6OPpMKE48pbH2nyQGL7BxNpuAyvwE/xiuTNts9m0CRnYB7 X-Received: by 2002:a05:6870:164c:b0:1f4:e2a6:e2d with SMTP id c12-20020a056870164c00b001f4e2a60e2dmr4205528oae.7.1700845618083; Fri, 24 Nov 2023 09:06:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700845618; cv=none; d=google.com; s=arc-20160816; b=FXZMcxZoOHC+qhXSif+WrRum5VnWpA4ZHe1qDAeV4Nrg4INjcwGYtQfygGbnSg0549 2B5hx7vjbCyXOkWr3nT30ELYxeabZPMC4KuUgjY5VE9c0+ZlxQH19FCuC+L4eha+Wm0O PkDMZ6akEy05VRq9U19Jb3XzmqJ4AVNJJvUoatg00fZ+pvT29k3LfTBpmEG4XP/5C1GG igj3V+LK6g5hMo9AxPdJiSd8BNpk96/PsapSBDwugg3f+BxJOjceWyEcGTQtb8ymQmQH Mkpot63bGJ9HPfuhS5epzuUrP8RwNyqHYjk0MLoTm46EelWDwXW5dDfvONh2l+ooklvM qsZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pRa7eBkQCVqRRADvvb9DQWGCOo86IDo14SZsoaGNUG0=; fh=q6XKL7ArGdKsioVJH5IlIe4bY+j84UABH+3xosQaP/E=; b=YxQC/J5Rz5ChbqqNN6uCPd3wmiSFOIzImC8MuJy9VjZtrEm+NF9jmYGJSv3DusUOl1 fpt+Hkhbhu54oSZ8ebEJyUY7Yj8b5Q6bOSil//HmRCXYYIIg3PZFeobEj/8i6pT689F8 FYBx3nWEQOH+t5WAK8W/XpX4JCYlkVh0MhigNq6hKhIVdSa+u9Ks4cr8pTdfIyPv5UPp m5HTPu6pEN99JhrauRgLZVvROUxloEV9LVi42mz0wdIGIO0Y2JbsOptKtPqJ9QyZY5kQ 0Ce5R+sEiIlLDVHdFxpRrJmx20zbPSY9PienwU2MiCjBJ+fIhbfrUBaFPU1FV5G6gM+P tffQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s098XSVg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ng3-20020a056871338300b001bbba238b7bsi1581162oac.249.2023.11.24.09.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 09:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s098XSVg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E64E480B2D74; Fri, 24 Nov 2023 09:06:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230159AbjKXRGi (ORCPT + 99 others); Fri, 24 Nov 2023 12:06:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229741AbjKXRGg (ORCPT ); Fri, 24 Nov 2023 12:06:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B6DD59 for ; Fri, 24 Nov 2023 09:06:43 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E892C433C7; Fri, 24 Nov 2023 17:06:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700845602; bh=PPv7r8G9gWCUU0EJn3vhveqcEwikXh9jLw+nzQQY9WI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s098XSVgPCPMuCM9JTGjDOF6ArkD588pr3xbbacn2qrOnd9HdljQZka8/F74S7hX/ NCrzX39xQUb9ZC1YaRAG/Qblvr+/P97J4ZA0u56pvC3u9G+kuEwR4nl6VwlkZy78Pt psqbG3gpul7rn/IGgdWC86LMED9JYliFM2YB+zwCcpl3grRq9jv6vibKGKBot89jut Tj+gLKs6zd24iD6Jzn8vw2OAum0VVLRac51PEJZjO2Ei0fRwFK/fSMxRvvbTXifNfw Xq70m4AbVloSNq5hz05Q8J/FhfY9FYKrXWXUfR/MIo9HqWCCtNUzAEc+U1fypTaVxx 6W6AIfwVULQxA== Date: Fri, 24 Nov 2023 18:06:34 +0100 From: Christian Brauner To: Michael =?utf-8?B?V2Vpw58=?= Cc: Alexander Mikhalitsyn , Alexei Starovoitov , Paul Moore , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Quentin Monnet , Alexander Viro , Miklos Szeredi , Amir Goldstein , "Serge E. Hallyn" , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, gyroidos@aisec.fraunhofer.de Subject: Re: [RESEND RFC PATCH v2 11/14] vfs: Wire up security hooks for lsm-based device guard in userns Message-ID: <20231124-neidisch-drehbaren-d80ef7aa6390@brauner> References: <20231025094224.72858-1-michael.weiss@aisec.fraunhofer.de> <20231025094224.72858-12-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231025094224.72858-12-michael.weiss@aisec.fraunhofer.de> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 09:06:54 -0800 (PST) On Wed, Oct 25, 2023 at 11:42:21AM +0200, Michael Weiß wrote: > Wire up security_inode_mknod_capns() in fs/namei.c. If implemented > and access is granted by an lsm, check ns_capable() instead of the > global CAP_MKNOD. > > Wire up security_sb_alloc_userns() in fs/super.c. If implemented > and access is granted by an lsm, the created super block will allow > access to device nodes also if it was created in a non-inital userns. > > Signed-off-by: Michael Weiß > --- > fs/namei.c | 16 +++++++++++++++- > fs/super.c | 6 +++++- > 2 files changed, 20 insertions(+), 2 deletions(-) > > diff --git a/fs/namei.c b/fs/namei.c > index f601fcbdc4d2..1f68d160e2c0 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -3949,6 +3949,20 @@ inline struct dentry *user_path_create(int dfd, const char __user *pathname, > } > EXPORT_SYMBOL(user_path_create); > > +static bool mknod_capable(struct inode *dir, struct dentry *dentry, > + umode_t mode, dev_t dev) > +{ > + /* > + * In case of a security hook implementation check mknod in user > + * namespace. Otherwise just check global capability. > + */ > + int error = security_inode_mknod_nscap(dir, dentry, mode, dev); > + if (!error) > + return ns_capable(current_user_ns(), CAP_MKNOD); > + else > + return capable(CAP_MKNOD); > +} > + > /** > * vfs_mknod - create device node or file > * @idmap: idmap of the mount the inode was found from > @@ -3975,7 +3989,7 @@ int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir, > return error; > > if ((S_ISCHR(mode) || S_ISBLK(mode)) && !is_whiteout && > - !capable(CAP_MKNOD)) > + !mknod_capable(dir, dentry, mode, dev)) > return -EPERM; > > if (!dir->i_op->mknod) > diff --git a/fs/super.c b/fs/super.c > index 2d762ce67f6e..bb01db6d9986 100644 > --- a/fs/super.c > +++ b/fs/super.c > @@ -362,7 +362,11 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, > } > s->s_bdi = &noop_backing_dev_info; > s->s_flags = flags; > - if (s->s_user_ns != &init_user_ns) > + /* > + * We still have to think about this here. Several concerns exist > + * about the security model, especially about malicious fuse. > + */ > + if (s->s_user_ns != &init_user_ns && security_sb_alloc_userns(s)) > s->s_iflags |= SB_I_NODEV; Hm, no. We dont want to have security hooks called in alloc_super(). That's just the wrong layer for this. This is deeply internal stuff where we should avoid interfacing with other subsystems. Removing SB_I_NODEV here is also problematic or at least overly broad because you allow to circumvent this for _every_ filesystems including stuff like proc and so on where that doesn't make any sense.