Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3024678rdb; Tue, 6 Feb 2024 05:13:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJKKiO2nUK34fLPOQ+NPcXbGVa8FAIyNbaRUyFcaYgsJIPNJyf9PospkzZlMH26n35cReJ X-Received: by 2002:a05:6870:a107:b0:218:eff8:3161 with SMTP id m7-20020a056870a10700b00218eff83161mr2508759oae.39.1707225196189; Tue, 06 Feb 2024 05:13:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707225196; cv=pass; d=google.com; s=arc-20160816; b=czgEYgcgUnQ0nhmWzS/PUHpx3cH42I2t56nOfP/W4Nc063NyFaM5NYVpfgdEo/UN8b KlxCaGru7ZXi+aiTkGVoG7Q+afsXvnh+xdYNCls4EwudabphxkphRSjGDsKhDGVXw98c nWMideDE5dXE6XbCIOnGqbmi1cnJBofir/l3htHL7yBr6jTjZj1xt09dzJQTa9sJviNj rD6QGttDFueLd0U4atlFdrpWNEmOCSud9MRpI7YHIYkO9nBnsIKJtBHoC1tiJs1NmLnr IcAexbzyJgnLCi6B9MV7XtcZ333PCJWl5o+Xa55bgcwvtT50Qzr+/Ps14ESdLJE7Lzd7 92HA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LVnzxKipUYiwlRsNvwaq8Sof0IFs5runV9DxoRVL20w=; fh=dP6JkuBOirqSjwSgHGLRWm+80lOTZn5KAtmTEp/LtM0=; b=Dq3DkJlII2Owx2lQ8UJHtjMfzHOLPecS6aFrK4IcPKJw6JNCl0j9VY1ZXAs3LjKPC1 yJIlZQhio/px5aR6m6v39tPAjSBDcK4ABp7e8PeJqZX8PQTCQNEP7mWUal7fxv72WdL+ sN3sP7dKqukOqerXlNFOsRPEkAfjtBXy+wZ9yUCQi6VUzvWlf9HdDs6kz1xjxKmCQE4V 9GnZSWl+fOMYfNHXJr9nTgTV3UrBHn9Q5VsvNLWWKXdM5cmdcjjc5T0JEI5ZAJddYjgQ 26K0aSOyGmQTbAzA22Mh91J/GaSC0d/HZKrGFi1YFQm6gsYi0H2N+aDlbdD1VjNbey5C YruQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NvxHEA8W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWpX24M5ulOHzkRgaDTvAXmU4ropB9cuuwPkAYArKAGqvWpPwVbM091vhTEIzvxiA6+NzbTzoMOuiZiE03b2NaV/vaxJZazioAuD3eAFg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v4-20020a634804000000b005dc1281f243si1568946pga.371.2024.02.06.05.13.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 05:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NvxHEA8W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54999-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CCCB1283278 for ; Tue, 6 Feb 2024 13:13:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 163E9131739; Tue, 6 Feb 2024 13:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NvxHEA8W" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 256EF12FF6C; Tue, 6 Feb 2024 13:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707225165; cv=none; b=D0RUNnUO0gp/JaAK/UIqwWJomKEJgtfWPSur7usFe/PdMij76WNIgbu9fCFt6dFEqnmhJGaise7RD49qD8dXT8VjRzd/kqY+Xbk+2HoH+10nX53zxpVdS+GnpeUapez75tcyf3yekRXg/w45nc/nP6Ql2i087JVPcsJZoYHKcbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707225165; c=relaxed/simple; bh=gLkNDwNsAdKLU1ngiauV0VNNKQmAGTKBSOrqgV1zYB8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LkbBVC+6jzHjqR5fVgkkgseK0hSkNgpIUEFVu/1lmHUq57D7a4C9FG2aurPnUrmYqGKtBweRDcVHx36CcMQ35ZzWyDiUpg7kiBLj86rrp4awbtYTlF3olGcy01yCsWV9cbSd54NyoPDTbxaXVER8+BIbvR8wwFwHJtmjCOPtIFM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NvxHEA8W; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09E86C433C7; Tue, 6 Feb 2024 13:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707225164; bh=gLkNDwNsAdKLU1ngiauV0VNNKQmAGTKBSOrqgV1zYB8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NvxHEA8WFxQcnTKLhYJxiB1XBborVcIhIqvoTb6Ey9y+Hq8w3ZjVRKtzCJ4oNsdDv bOOXtSmbXj0OgjvSDNbIpMg4m+xdY6yEdJGmMWHNLKYGLHgJqexd+1CZqwkBTQnXJ/ qKniecy6I8IgbEQCaAPIyIz/uzhcjGtBVAClvPu36lRky+qKBqkmZs84zSAJfTY6AE fy7rCLe4BkbwupcVad/a289tLEJcCnYwJCAmPbqn4RV3dPiPOu9pBxMC4/ovQXC3+j GBTFHGA26PrgGCDI0EOyeNq3t74xgdxiNPU6pRbrsyClpisYVRf5+uoIbsp1LS96WQ VYaBTr0iWVhuQ== Date: Tue, 6 Feb 2024 14:12:38 +0100 From: Christian Brauner To: NeilBrown Cc: Jeff Layton , Alexander Viro , Jan Kara , Chuck Lever , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, Ondrej =?utf-8?B?TW9zbsOhxI1law==?= , Zdenek Pytela Subject: Re: [PATCH] filelock: don't do security checks on nfsd setlease calls Message-ID: <20240206-gewaschen-bauen-f7932047a1be@brauner> References: <20240205-bz2248830-v1-1-d0ec0daecba1@kernel.org> <170716318935.13976.13465352731929804157@noble.neil.brown.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <170716318935.13976.13465352731929804157@noble.neil.brown.name> On Tue, Feb 06, 2024 at 06:59:49AM +1100, NeilBrown wrote: > On Mon, 05 Feb 2024, Jeff Layton wrote: > > Zdenek reported seeing some AVC denials due to nfsd trying to set > > delegations: > > > > type=AVC msg=audit(09.11.2023 09:03:46.411:496) : avc: denied { lease } for pid=5127 comm=rpc.nfsd capability=lease scontext=system_u:system_r:nfsd_t:s0 tcontext=system_u:system_r:nfsd_t:s0 tclass=capability permissive=0 > > > > When setting delegations on behalf of nfsd, we don't want to do all of > > the normal capabilty and LSM checks. nfsd is a kernel thread and runs > > with CAP_LEASE set, so the uid checks end up being a no-op in most cases > > anyway. > > > > Some nfsd functions can end up running in normal process context when > > tearing down the server. At that point, the CAP_LEASE check can fail and > > cause the client to not tear down delegations when expected. > > > > Also, the way the per-fs ->setlease handlers work today is a little > > convoluted. The non-trivial ones are wrappers around generic_setlease, > > so when they fail due to permission problems they usually they end up > > doing a little extra work only to determine that they can't set the > > lease anyway. It would be more efficient to do those checks earlier. > > > > Transplant the permission checking from generic_setlease to > > vfs_setlease, which will make the permission checking happen earlier on > > filesystems that have a ->setlease operation. Add a new kernel_setlease > > function that bypasses these checks, and switch nfsd to use that instead > > of vfs_setlease. > > > > There is one behavioral change here: prior this patch the > > setlease_notifier would fire even if the lease attempt was going to fail > > the security checks later. With this change, it doesn't fire until the > > caller has passed them. I think this is a desirable change overall. nfsd > > is the only user of the setlease_notifier and it doesn't benefit from > > being notified about failed attempts. > > > > Cc: Ondrej Mosnáček > > Reported-by: Zdenek Pytela > > Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2248830 > > Signed-off-by: Jeff Layton > > Reviewed-by: NeilBrown > > It definitely nice to move all the security and sanity check early. > This patch allows a minor clean-up in cifs which could possibly be > included: > diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c > index 2a4a4e3a8751..0f142d1ec64f 100644 > > --- a/fs/smb/client/cifsfs.c > +++ b/fs/smb/client/cifsfs.c > @@ -1094,9 +1094,6 @@ cifs_setlease(struct file *file, int arg, struct file_lock **lease, void **priv) > struct inode *inode = file_inode(file); > struct cifsFileInfo *cfile = file->private_data; > > - if (!(S_ISREG(inode->i_mode))) > - return -EINVAL; > - > /* Check if file is oplocked if this is request for new lease */ > if (arg == F_UNLCK || > ((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) || > > > as ->setlease() is now never called for non-ISREG files. I've added the following on top. I've made you author and added your SoB. Please tell me if you have any problems with this: From d30e52329760873bf0d7984a442cace3a4b5f39d Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 6 Feb 2024 14:08:57 +0100 Subject: [PATCH] smb: remove redundant check ->setlease() is never called on non-regular files now. So remove the check from cifs_setlease(). Link: https://lore.kernel.org/r/170716318935.13976.13465352731929804157@noble.neil.brown.name Signed-off-by: NeilBrown Signed-off-by: Christian Brauner --- fs/smb/client/cifsfs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index 5eee5b00547f..cbcb98d5f2d7 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1094,9 +1094,6 @@ cifs_setlease(struct file *file, int arg, struct file_lease **lease, void **priv struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; - if (!(S_ISREG(inode->i_mode))) - return -EINVAL; - /* Check if file is oplocked if this is request for new lease */ if (arg == F_UNLCK || ((arg == F_RDLCK) && CIFS_CACHE_READ(CIFS_I(inode))) || -- 2.43.0