Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp842479pxb; Thu, 5 Nov 2020 14:40:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwt4pfikD+ahVNK7lAw4CRUHyb+d/LiK9MIZuOyAAZZ1Gv8LsHPm1KM8xb48tAu8cof7wEU X-Received: by 2002:a50:cbc7:: with SMTP id l7mr5016727edi.148.1604616015543; Thu, 05 Nov 2020 14:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604616015; cv=none; d=google.com; s=arc-20160816; b=DJ3E8Asqaaq2DZ/L3feAyEXxxJEHFjO1+qdWCI5ZPDhB+uybielQEO1zxYGw2kgjW/ y6fhmu84dRBKBDiba/J+9S7TgAhQ+4uhweD6G1yfb0LMgNLf3Nz2tpSs0VrQiFoP+6DA +vCFunZYbjxy72ao+UG02xTaTGZXwGS7I+wDX5/Yqkrt0aZlBSxNKvrAcYRmwo8JTKCH YCU2zD4iS8d/6NmEm/5X1ncjW1snmO64sZf0QIkGuQZ0zu7xQIs+TVq2B4+GvTgIu8Cz NnWEUsGpVWxKLclNmtXxFWfbcRSsEqg4O+Pg0QvNuqJvTEtMSPSUSk50BA5e+XodEeRB O6PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xuDV0hV2Tn43pTJUiwiMZbxhnhM/1eaGdD9lKhf+xtk=; b=0tYvf6pqBWksXHIK7cJDTbhAdtvFMyTaSYisaC97Ouvtn764aDvc2Wdo+yEKtB5abp z3hLuVh4tTPIJ0/L9KhE+AOVPpa0ijMve019zZqwpRBiEm/ivjr/CjY0LX6qF8WxhRXA cj2y1LhI8PlzD9eOQBsFxy5/UMsj8NSA9P4cMv39Z/SwsC53D+hGeP9jM8OOa7HDmDqI oXWWI1Vu8Fb1DVRegan46o8FXhn6fIlsGH0G5X3GxbyTAWJvjj7raGnSi9hxXvIFWOwt 0u3UzeCVJArHElSzoQRMU8V5dNT04Qlfa92a9KY7UeMchlMqmTR7EKVwvvQGm2k71ZkQ 08XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I66iJ0x/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a35si2340774edf.202.2020.11.05.14.39.26; Thu, 05 Nov 2020 14:40:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I66iJ0x/"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbgKEWhp (ORCPT + 99 others); Thu, 5 Nov 2020 17:37:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36366 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732250AbgKEWhp (ORCPT ); Thu, 5 Nov 2020 17:37:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604615863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xuDV0hV2Tn43pTJUiwiMZbxhnhM/1eaGdD9lKhf+xtk=; b=I66iJ0x/2xZrvA84JhunY6sFz/rwfpWs1Y0hW4PyjTJnbvqZpuWhafHuLRIci64VXIASFW 6wGt6rzfOl0YYrS7IdX6tFAdp0B1IsUU3sojWAxYOPGV2I00lZ7VeVSB/EENsDtHE8JAXe My/orw30UDD7h9Yn18FVSgvEhFS05Ac= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-Esy_uLJ3PH68FBTfPHc2YQ-1; Thu, 05 Nov 2020 17:37:40 -0500 X-MC-Unique: Esy_uLJ3PH68FBTfPHc2YQ-1 Received: by mail-lf1-f72.google.com with SMTP id e29so1214191lfb.5 for ; Thu, 05 Nov 2020 14:37:40 -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; bh=xuDV0hV2Tn43pTJUiwiMZbxhnhM/1eaGdD9lKhf+xtk=; b=IOIPwO8JRzh9CKpgEK/UviydixW/9Q+66Wpv6eHV08aFZp6HYq20cWpvgAxtAR7v8t eNFQiMEGf9U+81ZZr7CMK491IWxALhSZMoOXlAfIhku3xNNRnoDw6w07HLuMkawdwkH2 DTAHzSRyNoNUGS1AswyfXdOQgNX3bVx28MivqwpEOqgLWzfb9bDF3fWOxIBawbbR8Lu2 37z+kE8f65hNGP9fJ4xkctlIZYXNwiGjdbNbSevZOpjHq1IyCkmFXQ1ByKXH+kYfhmAP 8aH4hY/X1/FODpSJILBM0jIhvDuCx9cBCqT6smh+ph7AOny6JSxYJnRAAbEtn0xpLEQc GGyQ== X-Gm-Message-State: AOAM531oV9n8qsNnrnRbRVke9HiHEliOi9l4X6R7+aq2DCeMVCJVRvvN hs/XuEUdGqVqDQ0lMq6CRMZD8gFnGaOTQvomEYZ0g30j0MjPHqXuGHw0v9mB8VkZ+9Zb9O+WMzd 8P8nFGnPZ7A2y6DEc+l93160xHgcwsH8cYHYs X-Received: by 2002:a2e:8145:: with SMTP id t5mr1754926ljg.311.1604615858900; Thu, 05 Nov 2020 14:37:38 -0800 (PST) X-Received: by 2002:a2e:8145:: with SMTP id t5mr1754917ljg.311.1604615858645; Thu, 05 Nov 2020 14:37:38 -0800 (PST) MIME-Version: 1.0 References: <20201105221245.2838-1-olga.kornievskaia@gmail.com> In-Reply-To: <20201105221245.2838-1-olga.kornievskaia@gmail.com> From: Ondrej Mosnacek Date: Thu, 5 Nov 2020 23:37:27 +0100 Message-ID: Subject: Re: [PATCH v2 1/1] NFSv4.2: condition READDIR's mask for security label based on LSM state To: Olga Kornievskaia Cc: Trond Myklebust , Anna Schumaker , linux-nfs Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Thu, Nov 5, 2020 at 11:12 PM Olga Kornievskaia wrote: > From: Olga Kornievskaia > > Currently, the client will always ask for security_labels if the server > returns that it supports that feature regardless of any LSM modules > (such as Selinux) enforcing security policy. This adds performance > penalty to the READDIR operation. > > Client adjusts the superblock's support of the security_label based on > the server's support but also on the current client's configuration of > the LSM module(s). Thus, prior to using the default bitmask in READDIR, > this patch checks the server's capabilities and then instructs > READDIR to remove FATTR4_WORD2_SECURITY_LABEL from the bitmask. > > v2: dropping selinux hook and using the sb cap. Thanks! I'm happy that we managed to avoid adding yet another LSM hook in the end :) > > Suggested-by: Ondrej Mosnacek Suggested-by: Scott Mayhew > Signed-off-by: Olga Kornievskaia > --- > fs/nfs/nfs4proc.c | 3 +++ > fs/nfs/nfs4xdr.c | 3 ++- > include/linux/nfs_xdr.h | 1 + > 3 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c > index 9e0ca9b2b210..9c9d9aa2a8f8 100644 > --- a/fs/nfs/nfs4proc.c > +++ b/fs/nfs/nfs4proc.c > @@ -4968,6 +4968,7 @@ static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, > .count = count, > .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, > .plus = plus, > + .labels = true, > }; > struct nfs4_readdir_res res; > struct rpc_message msg = { > @@ -4981,6 +4982,8 @@ static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, > dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__, > dentry, > (unsigned long long)cookie); > + if (!(NFS_SB(dentry->d_sb)->caps & NFS_CAP_SECURITY_LABEL)) > + args.labels = false; Minor nit: you could initialize .labels directly in the initializer of "args" like this: .labels = !!(NFS_SB(dentry->d_sb)->caps & NFS_CAP_SECURITY_LABEL), > nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); > res.pgbase = args.pgbase; > status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); > diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c > index c6dbfcae7517..585d5b5cc3dc 100644 > --- a/fs/nfs/nfs4xdr.c > +++ b/fs/nfs/nfs4xdr.c > @@ -1605,7 +1605,8 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg > FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV| > FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS| > FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; > - attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; > + if (readdir->labels) > + attrs[2] |= FATTR4_WORD2_SECURITY_LABEL; > dircount >>= 1; > } > /* Use mounted_on_fileid only if the server supports it */ > diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h > index d63cb862d58e..95f648b26525 100644 > --- a/include/linux/nfs_xdr.h > +++ b/include/linux/nfs_xdr.h > @@ -1119,6 +1119,7 @@ struct nfs4_readdir_arg { > unsigned int pgbase; /* zero-copy data */ > const u32 * bitmask; > bool plus; > + bool labels; > }; > > struct nfs4_readdir_res { > -- > 2.18.2 > -- Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.