Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9182097pxu; Mon, 28 Dec 2020 08:37:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyf9LE8tBPMd7xwr8DM8n5WLsFchGNrAy9nXsDipAaf9yy/GzVclLkYnqjr/nQYDBSKb3G4 X-Received: by 2002:a17:906:1955:: with SMTP id b21mr42171267eje.236.1609173449318; Mon, 28 Dec 2020 08:37:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173449; cv=none; d=google.com; s=arc-20160816; b=uDS33y09k7uB0PIKLRssNlcw3a25ZsX43gsLwXqXMAKN4dT/bQ5xamo2Q+P0RaDRJb H/WFNw4+qBxu3JgehRJ/kca5u5UC8A34l8ux9vCnOYZc7ie9bSP66KuM9r0+1Yj1/0Z/ yUivqobmxgdbQGKCGzSalRUXPitfKP7lce2Dx6BiE0HsMZ2rU59PB7M6tX548J5c8kzF ecyqNi160bwjzNX8AJEorb9p0rf7QDN31sSd0MtisWgIKdwTTiulq+MPioAP5swqRcWj cVKBz6ll+/Ycb6cCT0GXL6NBKiglQpfMWGK6xyRmszjweLqnvRFgcIE6/T/UFA5Y/5wg 6Ggw== 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=N/1iZ2PZP0NaF7q50ouRf8JZiLizf4XQ346ht6D6krs=; b=tEFh7/+kdGpOYKAEToBch5HMAm7yv2hSNBHtOZMpWtktufVcp3wmK29bp2ly2h/gTO whKx/ShyvePrCn5gE4r+53ctcG/QGbwVdr1ESYCWuSCu2vS47xe0y+xmimaE8+PV34oy oynyub2GH5Sw1sNoB54p6e9Z9RO/9VEboXCibp7BQpS0/x9BcxDLmWBayolgtq+elAcf Pyn/vfIHCZGJ9hFM7rWSoNruynDnGCSXn67c7UgRmPJihGca2UMzQcatGBI5oInG+knf r4SYvGIUcehr472glB5MN/aobhI56SQQqEm+qstgvsb+HZI7jkFJa/7iwIyjTqYk1PAz tRPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nbzVxDrX; 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 rk17si18254699ejb.509.2020.12.28.08.37.06; Mon, 28 Dec 2020 08:37:29 -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=nbzVxDrX; 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 S2441987AbgL1QeV (ORCPT + 99 others); Mon, 28 Dec 2020 11:34:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:58302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728250AbgL1NDA (ORCPT ); Mon, 28 Dec 2020 08:03:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F15AB207C9; Mon, 28 Dec 2020 13:02:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160564; bh=Zf165PfJWOMNc6a5fm5rVWTojyKe0N3jyb3azQocH0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nbzVxDrX6XMVXLKkqwijLNUKE7uV0gKQ07R/+gPOWLTZro1boVoI6NW1DYZ8W1HYo aGMgHUnhlr7yk3YsH1+MwiwbxtC6k8XaWick9ThKpgerNX7R4qUOFsjHWq7WZoRHHJ pARx/RSCoQNxNGptfZC1HefgyIPe3oUaBXdRseAQ= 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 4.9 086/175] NFSv4.2: condition READDIRs mask for security label based on LSM state Date: Mon, 28 Dec 2020 13:48:59 +0100 Message-Id: <20201228124857.410528765@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 4e2f18c26535d..2abdb2070c879 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4334,12 +4334,12 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, u64 cookie, struct page **pages, unsigned int count, int 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; @@ -4354,9 +4354,15 @@ static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_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