Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp283813rwe; Wed, 31 Aug 2022 22:08:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR47gINGx01hnxGOIfmvheZzf+MX9mlNFrKMgxNXQBONrsAZB+FXaRIHQPus2BPTgvk+DKx1 X-Received: by 2002:a63:a516:0:b0:42b:8bb2:7036 with SMTP id n22-20020a63a516000000b0042b8bb27036mr21034409pgf.389.1662008935898; Wed, 31 Aug 2022 22:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662008935; cv=none; d=google.com; s=arc-20160816; b=q+Uv9MzteCGuR3CnJRIO9Un6W5MhdASip/Qa9quMMy9M3N9ungsAFyOzNkZcz8EWWo 0Fz9T6uj2lRCfGgsGimpoyZ3St58m+QTv6ZYqYxV48WIkZnTA+2WNtkGq+gA4lOBIf+z eHnT/pugBdHQHDDhWpLXRYkqJTvusG0yAWej+5bKi1GU12T7BKjTV2hGrhgDA08ofi4k yjKxwWyhq+MyGfkj85jk+QxGuGycvKGpvRDFjpA/HA9crU+3AzQbN0MhAcBsss26Z7jQ HT554XcXqUqtbiaVPVOblYrHYvYsiC/ok1TUa8BFe/u44O8qlX2s5v7DYYZV6pwC5LFE Is0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=9MgdM/4E/TOLmi5ouDu792LxVmllOqtYXJ7y3pATFgQ=; b=U+f3cVwGNQqXzrp6DyUWitPoTVzypb/3eBH1aZEV2JVu+mh/fbG00PPKmpK2AgqKJ5 PC5Zw0KJVvD1oYFjIFy2Hns5WWsKy5rWHNwEUmUr/mR+HFHNVzfuXqlRWYmV/C3WrXEJ aougDYQipU+0rBWXS87DGniymUWkJYf4IqgGD65HXqMG07+fULJxmkZYA04i8INrE9tH hnh35oGzWrO56dHdC504d4AATJ1cG8kagtNi1B20YE8DnHMNRiregxVoDycsP2EiA+cH 7wj317zzKrfn2fDBgrd5ocJmdCnD/4ePlCNVU1IwA7wM7FL+u5EdysOXk3K2kc2NyLbP XCvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=pSZCdMPw; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 13-20020a63144d000000b0042b6e87d121si6914464pgu.345.2022.08.31.22.08.17; Wed, 31 Aug 2022 22:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=pSZCdMPw; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232374AbiIAFEf (ORCPT + 99 others); Thu, 1 Sep 2022 01:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiIAFEe (ORCPT ); Thu, 1 Sep 2022 01:04:34 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77C881157F5; Wed, 31 Aug 2022 22:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9MgdM/4E/TOLmi5ouDu792LxVmllOqtYXJ7y3pATFgQ=; b=pSZCdMPw4gdcTYtt1r9bP+HAlK gU+1IgMTmybd7HuQhOOMEkC6JigND3VXY7zlyLDvXJiSMswIBSVrQGt9s9NROjx8QZ18YBGuVNUv8 kdfGLL2VqDpbs77GqAQNt7PSgOP9rD2VAH610+zip0lIuDWyGW0WwOQETLLEaCaw529fi3UKzjQs5 s7/sJZoF5/ns40rXGoptnnJMNQ+8/A/9oGgnzn6dtYiI3rdntD6yqwUyebhsjcXKwRU3GNw7UGe0y 3Ti/O5aDOvsVO9na6UmeQnRUMSTrlibkrj+p1hRpypHQonh4ix9Bc8plfJl5W1Qrv0/sw8sOXzfFq tf+YRkkA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1oTcNI-00Ar6I-Sm; Thu, 01 Sep 2022 05:04:21 +0000 Date: Thu, 1 Sep 2022 06:04:20 +0100 From: Al Viro To: David Howells Cc: Jeff Layton , Trond Myklebust , Anna Schumaker , Scott Mayhew , Paul Moore , Casey Schaufler , linux-nfs@vger.kernel.org, selinux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, dwysocha@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] vfs, security: Fix automount superblock LSM init problem, preventing NFS sb sharing Message-ID: References: <166133579016.3678898.6283195019480567275.stgit@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <166133579016.3678898.6283195019480567275.stgit@warthog.procyon.org.uk> Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Wed, Aug 24, 2022 at 11:09:50AM +0100, David Howells wrote: What's the reason for difference between selinux and smack instances of context_init? The former allocates only on submount, the latter - unconditionally... > +static int selinux_fs_context_init(struct fs_context *fc, > + struct dentry *reference) > +{ > + const struct superblock_security_struct *sbsec; > + const struct inode_security_struct *root_isec; > + struct selinux_mnt_opts *opts; > + > + if (fc->purpose == FS_CONTEXT_FOR_SUBMOUNT) { > + opts = kzalloc(sizeof(*opts), GFP_KERNEL); > + if (!opts) > + return -ENOMEM; > + > + root_isec = backing_inode_security(reference->d_sb->s_root); > + sbsec = selinux_superblock(reference->d_sb); > + if (sbsec->flags & FSCONTEXT_MNT) > + opts->fscontext_sid = sbsec->sid; > + if (sbsec->flags & CONTEXT_MNT) > + opts->context_sid = sbsec->mntpoint_sid; > + if (sbsec->flags & DEFCONTEXT_MNT) > + opts->defcontext_sid = sbsec->def_sid; > + fc->security = opts; > + } > + > + return 0; > +} > +/** > + * smack_fs_context_init - Initialise security data for a filesystem context > + * @fc: The filesystem context. > + * @reference: Reference dentry (automount/reconfigure) or NULL > + * > + * Returns 0 on success or -ENOMEM on error. > + */ > +static int smack_fs_context_init(struct fs_context *fc, > + struct dentry *reference) > +{ > + struct superblock_smack *sbsp; > + struct smack_mnt_opts *ctx; > + struct inode_smack *isp; > + > + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); > + if (!ctx) > + return -ENOMEM; > + fc->security = ctx; > + > + if (fc->purpose == FS_CONTEXT_FOR_SUBMOUNT) { > + sbsp = smack_superblock(reference->d_sb); > + isp = smack_inode(reference->d_sb->s_root->d_inode);