From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 42EFE472534; Tue, 21 Jul 2026 20:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784665415; cv=none; b=nnB8s7+IQlgZgO43JOUsT1Vjdqm3G7oG9E4cxhjZH1kBtB2Z3hXH4P1R0rde7lzb+b8+YxYv3TxQ9gx39OEuSx9tnXH7DzPRHTnITymzUDxNdkQo/vUjsvaKpSFKDkmElCTzCogSK1t2ueqasxQDThKFfwItN354wky7LFrbPqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784665415; c=relaxed/simple; bh=BFwsbO6U/w+O0GhBIq67yxlwEIu7ScisaB/6OGUc9nU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dycc3edBajvsevpjVnpTWNa7eodNuVZQLbudO6ShnfEAETs/cPP+3Ah/zudQMEbqiDA4A3LEU78V05ODJHUlGnzjMEnX8uCgWdKgEKCKPCt5kgOePCoby9KYYJz90RjigWmXowgz0jh+2YHAeHnXSOJWKtGXOJ7D1QP3fot1QYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2VyWdidF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2VyWdidF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A81AC1F000E9; Tue, 21 Jul 2026 20:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784665414; bh=0Uw3eovmbG62KmG8U+Us42W1z7ztqjQnmW6M3ACgiTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2VyWdidF4Jt89MPSJwaH6Tox85n1iR4I+Dv6OvK0jRIOz06E/eq/b1YmtcMSBSh6R 46ZtVcm0ubIowa6nWVWpDgD4nNWG5iSE5+dR88WmHNyNjnw7Zsd6LkNqVlhl+x3tGd HTSUqTgOTzOWrDkqkFLajsycYYfXHaw690fKUL/s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Trond Myklebust , Benjamin Coddington , Anna Schumaker Subject: [PATCH 6.6 0295/1266] NFSv4: include MAY_WRITE in open permission mask for O_TRUNC Date: Tue, 21 Jul 2026 17:12:12 +0200 Message-ID: <20260721152448.427653004@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Coddington commit 5140f099ecd8a2f2808b7f7b720ee1bad8468974 upstream. POSIX requires write permission to truncate a file, so an open() that specifies O_TRUNC must be authorized for write access regardless of the O_ACCMODE access mode. nfs_open_permission_mask() builds the access mask passed to nfs_may_open(), which is the local authorization gate for OPENs the client serves itself from a cached write delegation via the can_open_delegated() path in nfs4_try_open_cached(). The mask is derived from O_ACCMODE alone, so an open(O_RDONLY | O_TRUNC) against a file the caller cannot write requests only MAY_READ and passes the local check. The OPEN is then satisfied locally and the truncation is issued to the server as a SETATTR(size=0) over the delegation stateid, which the server accepts under standard write-delegation semantics. POSIX requires that this open fail with EACCES. Include MAY_WRITE in the mask whenever O_TRUNC is set so the local check matches the access the server would have enforced. Suggested-by: Trond Myklebust Fixes: af22f94ae02a ("NFSv4: Simplify _nfs4_do_access()") Cc: stable@vger.kernel.org Signed-off-by: Benjamin Coddington Signed-off-by: Anna Schumaker Signed-off-by: Greg Kroah-Hartman --- fs/nfs/dir.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -3275,6 +3275,8 @@ static int nfs_open_permission_mask(int mask |= MAY_READ; if ((openflags & O_ACCMODE) != O_RDONLY) mask |= MAY_WRITE; + if (openflags & O_TRUNC) + mask |= MAY_WRITE; } return mask;