Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9083750pxu; Mon, 28 Dec 2020 06:14:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzhWbwtJ2rqgXqJLN269IyuAgT6uGbMcAtwBFBCtBP2HQSxK9hLi6ZVjhu4C9mRJRZzH/eU X-Received: by 2002:a17:906:4a47:: with SMTP id a7mr42060580ejv.345.1609164876169; Mon, 28 Dec 2020 06:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609164876; cv=none; d=google.com; s=arc-20160816; b=UePsaOoDGPZ4qgtsVD7j3CQRyaZ9QsAn12dkWm88AuSSlSIpib/3STqYR+qOz1Iz0a 7MDBscGh0dZx0/gaFvyD2lv/i1usDFfDMSFRYw8amOdtwvdfDqEOgwED+Qbid5typKZK xw1N9c1KA7TlnzkHIv8kiTPzW4la/6dz4GxAu9Clq8hO2jF2gPbfPKvsBpBBIT3GXGyX C1mL2qwPEzrLjdt28UL8CoEQZQUHYbTahq9oqLkdwE9myrp1faIe0ENCO2c/vY2p6WQT KmEt2z/ZvGE7PNhHtSkn2KjKZzaaAYKhS4c39cGORC06MZUHUOSYDQOerloMkVhNU6xq QDbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LM4MKdkECzICEU4EEzMBvVZd/vt60Q8yRQpZICsatkg=; b=I3t5715hNHBaYxxcxieTvJEl53NuLAtRw4E7HL95G9AzfioVBjuoAunz4vWu4uC2MM 8doq9rq2zDgQY7VCZ8HgdUz8ryo4CI0BVitH5kiUJzRI9tPFqxoGI9RMRdhAVOBEVU/m a52T4xPVg1DkWUhpl+BHhoNk1gJ7n90GfcU/O0myvif4MfSTOqccV7OU0ice2xtA5E9l aiiwBmh0z6JeCCKBPiVOL4MSFt+iOrfnFnstvPq09Jn3usmenERtvkgrYKO+1G3wzSSy DzacfB9cKstd558JFAaeKtKmwcCwaoYXZRVHCg2SrZKN8zjS5ZsN6EV9b6rHGxND10vq Nixg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GYYMr2h4; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si18337380ejf.618.2020.12.28.06.14.13; Mon, 28 Dec 2020 06:14:36 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GYYMr2h4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439878AbgL1OM3 (ORCPT + 99 others); Mon, 28 Dec 2020 09:12:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:46888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439858AbgL1OMX (ORCPT ); Mon, 28 Dec 2020 09:12:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2EDA2206D8; Mon, 28 Dec 2020 14:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164702; bh=rwLZ/14vIO+CpPUWx84R1z3HTF+QRpNkNdzOQDt8Bcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GYYMr2h4GaL+5TVUy4MzULiI0Sfvh1XPCUL48CJY5Gc3Xr2ZghQgFRQfESYn/BVKy MuWJWzImZGESNfU+y9BlM0EnPpdLPrvYrtwMZ6S35Zjg7SGZR7A7JpLd6Irj96p2ST dHehe264sSU5CPG4OFuBq2tT3FYwqWvGLiDpvSa0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ondrej Mosnacek , Scott Mayhew , Olga Kornievskaia , Trond Myklebust , Sasha Levin Subject: [PATCH 5.10 267/717] NFSv4.2: condition READDIRs mask for security label based on LSM state Date: Mon, 28 Dec 2020 13:44:25 +0100 Message-Id: <20201228125033.803342973@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Olga Kornievskaia [ Upstream commit 05ad917561fca39a03338cb21fe9622f998b0f9c ] 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 superblock's support of the security_label based on the server's support but also current client's configuration of the LSM modules. 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. v5: fixing silly mistakes of the rushed v4 v4: simplifying logic v3: changing label's initialization per Ondrej's comment v2: dropping selinux hook and using the sb cap. Suggested-by: Ondrej Mosnacek Suggested-by: Scott Mayhew Signed-off-by: Olga Kornievskaia Fixes: 2b0143b5c986 ("VFS: normal filesystems (and lustre): d_inode() annotations") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs4proc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e89468678ae16..6858b4bb556d5 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4961,12 +4961,12 @@ static int _nfs4_proc_readdir(struct dentry *dentry, const struct cred *cred, u64 cookie, struct page **pages, unsigned int count, bool plus) { struct inode *dir = d_inode(dentry); + struct nfs_server *server = NFS_SERVER(dir); struct nfs4_readdir_arg args = { .fh = NFS_FH(dir), .pages = pages, .pgbase = 0, .count = count, - .bitmask = NFS_SERVER(d_inode(dentry))->attr_bitmask, .plus = plus, }; struct nfs4_readdir_res res; @@ -4981,9 +4981,15 @@ 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 (!(server->caps & NFS_CAP_SECURITY_LABEL)) + args.bitmask = server->attr_bitmask_nl; + else + args.bitmask = server->attr_bitmask; + 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); + status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, + &res.seq_res, 0); if (status >= 0) { memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); status += args.pgbase; -- 2.27.0