From nobody Fri Oct 3 13:21:32 2025 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 F2B8BEAD7; Sun, 31 Aug 2025 12:36:34 +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=1756643795; cv=none; b=Hbz9OZm8mUpRvpqpUPkPc68OeaB3XLUEHEaFPRS+VuFXzt1aUC91Ngd6xwjJaBaDTxgvsWmwhVuMKvo0N+n4puJuoW+7zPWUp7kAKrfKXQdykzJB/Dy6ujhjK9Alw+TUmb7fKoX12AMHNnHFLgDhJHHsm6YOR3WcBxzLwTQqbc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643795; c=relaxed/simple; bh=rxCdwQlYnec2995LbRwxC0xImYoxqfc9Q+HrlJEr2+Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=L9iAT9VrZ5eSvBD0udlmXOWx+toUIAIvkySdpvsd5KOtSI2AsAWvvghpgi98IK/aS0dYL5RugeXFloIDlaEC2k0a/Rqok6EN1sGw1MpGTLA8M2X0qptPu4amsfgEoNpFvlrXepYTzv4nEm5DhdA20nF4XgyzewaXKARw3bWUoI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EkjKxtzl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EkjKxtzl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D299C4CEF5; Sun, 31 Aug 2025 12:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643794; bh=rxCdwQlYnec2995LbRwxC0xImYoxqfc9Q+HrlJEr2+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EkjKxtzl1zMTqi79q/UkX47NFvYOxTNLpLkWb3nUecNcsgoMR/2N5gCDvaXEaqxod fWLHp8NSVqW0+YPS2yS0iEDRqze7n7V+aPgHQ7DCha7mCJRsu5TpNydrtu7bOnD90q xM391ljS0UaiYpnNTpxsL/HAZW2YdVsrkiSA50C9xN3Qm/ACB1DVw5X091gBOUQiPa 8CvN14qhkuqmXnQNDGY6m191TEGWDI2K+fMs3ECWI1qkXZHJCIafGMAdW/TKHVrHMQ QvsXHZQpNbblb7BeMy8739GW6rrRP/AFBd6hcOIJu/BSq0E/ja5GN77dQ2nOhdjIO3 cWWaU0fa0RmDQ== Received: by pali.im (Postfix) id DEE85D58; Sun, 31 Aug 2025 14:36:30 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/35] cifs: Fix and improve cifs_is_path_accessible() function Date: Sun, 31 Aug 2025 14:35:28 +0200 Message-Id: <20250831123602.14037-2-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Do not call SMBQueryInformation() command for path with SMB wildcard characters on non-UNICODE connection because server expands wildcards. Function cifs_is_path_accessible() needs to check if the real path exists and must not expand wildcard characters. Do not dynamically allocate memory for small FILE_ALL_INFO structure and instead allocate it on the stack. This structure is allocated on stack by all other functions. When CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() command. This command returns failure by non-NT Win9x SMB servers, so there is no need try it. The purpose of cifs_is_path_accessible() function is just to check if the path is accessible, so SMBQueryInformation() for old servers is enough. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb1ops.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 893a1ea8c000..1772f30419a9 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -521,21 +521,27 @@ static int cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path) { - int rc; - FILE_ALL_INFO *file_info; + int rc =3D -EOPNOTSUPP; + FILE_ALL_INFO file_info; =20 - file_info =3D kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); - if (file_info =3D=3D NULL) - return -ENOMEM; + if (tcon->ses->capabilities & CAP_NT_SMBS) + rc =3D CIFSSMBQPathInfo(xid, tcon, full_path, &file_info, + 0 /* not legacy */, cifs_sb->local_nls, + cifs_remap(cifs_sb)); =20 - rc =3D CIFSSMBQPathInfo(xid, tcon, full_path, file_info, - 0 /* not legacy */, cifs_sb->local_nls, - cifs_remap(cifs_sb)); + /* + * Non-UNICODE variant of fallback functions below expands wildcards, + * so they cannot be used for querying paths with wildcard characters. + * Therefore for such paths returns -ENOENT as they cannot exist. + */ + if ((rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL) && + !(tcon->ses->capabilities & CAP_UNICODE) && + strpbrk(full_path, "*?\"><")) + rc =3D -ENOENT; =20 if (rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL) - rc =3D SMBQueryInformation(xid, tcon, full_path, file_info, + rc =3D SMBQueryInformation(xid, tcon, full_path, &file_info, cifs_sb->local_nls, cifs_remap(cifs_sb)); - kfree(file_info); return rc; } =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 5B48F25BF1B; Sun, 31 Aug 2025 12:36:35 +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=1756643795; cv=none; b=rQQeygHRvkjfQerUMxSU14c2PdYXzbNQNAiEQGjB9meKYM8ScxY0gMrQsAZn/kH+4h7NPCSCIx64ivX9xaQH7hv+Uv1pIecPLAPfLRPe07e+DhqH+jX4OAcJASOEpxV6H4i3fxh9yeDUw9tWCdaGM46XJXm+92duN1/rKOsSj34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643795; c=relaxed/simple; bh=2yaxe8JvAoaujWsh6C/ntd9QE+7VcZOUC9n6I84/Phs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=o8HZAeot1Mzb3721NViRPyGMVjQTUzDOo8yEMPPmPEYGcU5Wyh7IodHkrc03o1N1lxYytmu7S04+S2Cyqrdn/ijj+InR85vESQ+tLhD1Pq0VH0qeI/j3izOt0K74P0U2ctl0hFCr2OVqMCMB4R5mq9U7QD3K3cu6c/wyLjGspsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iJlIgbxW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iJlIgbxW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1B29C4CEF6; Sun, 31 Aug 2025 12:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=2yaxe8JvAoaujWsh6C/ntd9QE+7VcZOUC9n6I84/Phs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iJlIgbxWuvAvhorbe5j+m5xZR80aeqoHXvlZr9qahtFtPGiqNFdnvds9m2LoMbl8H AAINj0tJptOQ1ZFKD6SrnEODpYzCDze8aLKwXARKPfYG/yCSSmm3x0WsWwQsG+YbwJ GoFP5ZaXl+cN/Q3PCm1orsjKTS70y+/3kY5swmp/+eF0N24BeP07aL20v7OjsD/zzZ myymSa00xEg/Q80A6+moVKfQ4e1Vjz3nQPsE84YpF+CSqnvlKRTkl7ZaucIcIrjorU R0ZvpmlC3LRPjkLjdUO7YmoHlXQ2EXiTkaYdHiEjwp0cm9cKyP8hF05pX1K5SfbTIt YO9zQuavWjeDA== Received: by pali.im (Postfix) id 1B937D70; Sun, 31 Aug 2025 14:36:31 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/35] cifs: Allow fallback code in smb_set_file_info() also for directories Date: Sun, 31 Aug 2025 14:35:29 +0200 Message-Id: <20250831123602.14037-3-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable On NT systems, it is possible to do SMB open call also for directories. Open argument CREATE_NOT_DIR disallows opening directories. So in fallback code path in smb_set_file_info() remove CREATE_NOT_DIR restriction to allow it also for directories. Similar fallback is implemented also in CIFSSMBSetPathInfoFB() function and this function already allows to call operation for directories. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb1ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 1772f30419a9..cc4feebbdd11 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -980,7 +980,7 @@ smb_set_file_info(struct inode *inode, const char *full= _path, .tcon =3D tcon, .cifs_sb =3D cifs_sb, .desired_access =3D SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, - .create_options =3D cifs_create_options(cifs_sb, CREATE_NOT_DIR), + .create_options =3D cifs_create_options(cifs_sb, 0), .disposition =3D FILE_OPEN, .path =3D full_path, .fid =3D &fid, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 1CAAE260566; Sun, 31 Aug 2025 12:36:35 +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=1756643796; cv=none; b=E8h4/DEPBIkCgRO6mDm92iH3Cn9w4LcjlFaHTzLhN/nS52z14RxSsYSjX7lEIDy0xPCffyE1Rmpb5bSh25KLHMZpz0KcgJDMk9glSOuYzjevxmm41I5+dq4kKihLLE1rqdMY2QYzS9Y0oobgA6FHHcv1+4LTQm8y4YmCIhS7SHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=Xq06GFTx1+d7lXTSarZu2S3z+Y49rpz/H7is/9UlQFY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=BdrPzUUro2uHgZz8mB0XZVOCBFGAu7v44I8EJgTbPnKbhEQYNaa+KT1xQ1+5Yzgw3dlIQkHbaKV+9LOCtBUGgt8gGlekC2P3bD/EOMYt3dkNbVlCGNV38GVBN8k4mZKY1lNvEbKCMOqzNzcyEBzNNFEyf6HTu1AViU4eor6ixuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k0EVwz/R; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k0EVwz/R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95379C4CEF8; Sun, 31 Aug 2025 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=Xq06GFTx1+d7lXTSarZu2S3z+Y49rpz/H7is/9UlQFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k0EVwz/R2fTzK+KEFX+oSnvS/HQdxa6Y1yCp4oqPW1X3jqAe1Y6XdCoOFh8l9NiEf sSGuCPfXc1fSMfrMJc0UCAyeRipirCW05T1gVbpWawDuXBxbg8ZQxfvMR6xvlBesYa cYmI4c+yKwig8dem/b42G1OqniFcN3wlfXK6AMEUesselbppYrS0JnYfhfEFXh1XbK jkloLh9fqtJxhqbH2WxtQtZDjyGlduo3JumknC23YIgcSRPkn/ZwtoIWjTpGdI3d76 pWA8F7dWMwgvVb+A/nuVkopVdDFWK5bwk5DZgVBIDzBVuQ0bfBoQUE80LgdC5u6xfr TNSLasdpAemrA== Received: by pali.im (Postfix) id 41CB0EB3; Sun, 31 Aug 2025 14:36:31 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/35] cifs: Add fallback code path for cifs_mkdir_setinfo() Date: Sun, 31 Aug 2025 14:35:30 +0200 Message-Id: <20250831123602.14037-4-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Use SMBSetInformation() as a fallback function (when CIFSSMBSetPathInfo() fails) which can set attribudes on the directory, including changing read-only attribute. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb1ops.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index cc4feebbdd11..de415b9945ee 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -824,6 +824,11 @@ cifs_mkdir_setinfo(struct inode *inode, const char *fu= ll_path, info.Attributes =3D cpu_to_le32(dosattrs); rc =3D CIFSSMBSetPathInfo(xid, tcon, full_path, &info, cifs_sb->local_nls, cifs_sb); + if (rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL) + rc =3D SMBSetInformation(xid, tcon, full_path, + info.Attributes, + 0 /* do not change write time */, + cifs_sb->local_nls, cifs_sb); if (rc =3D=3D 0) cifsInode->cifsAttrs =3D dosattrs; } --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 8EEB9262FDC; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=Kdo7np/FCLJyRgEUigrLQaK2IUhNirj8CGKNZjUNbEsMBox2RMgRsOe4GNNgOX0W7VV2KHLt/E70ZMjIxTNt2buE5M7M+/JcaU1vuTS30eylzLZziB/SJW1MP1D0KHuHgKpFW9ok+oE3kugYpVS+1f2qb09Dqk+5McyVA+4c5tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=PBsNBsU7BY6C7lAfXKklGf8nUYze5AXKchvgMMlH4YI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=NUqDs7hgDJFq2OPR0r+5XIP63t/c1qS2ZsGzoW7gzrqjar6MfmhnC8Hgup/i2X11w7zQbTWLy8b9W1CDnVLY7cnCPNUI3RZdnkD0tGUcgA2OovjjZZRZ9VTtD0XWRkCgnrLONZORmZN3o21nbxQDMrwitKsJzl9oIDZdzyiRdhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hlv7KWCT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hlv7KWCT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24E71C4CEFC; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=PBsNBsU7BY6C7lAfXKklGf8nUYze5AXKchvgMMlH4YI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlv7KWCTbt7XnhdAskkxhrX1YQiMv2MboAHykPLEud7E27NnKx3vXpcj3fTQDHE5R MNq8zcQYbbxYrw0jTJsAr0ncIAracRCkolPJkF9VbKj37Xv0USr1Wnm5+RPqIQIrcZ mncTX6FXNQBqEnkWMnDlpeK1elhenhItjrZH+VRxkgrdOFBRdOjQwv5TQ7L6j4iTI/ Yr/X7KSWvOgzQ6X9QKGnj0ySld8HGuTdEDbKwCo5xW+1g3Rj+mRgzM58NX9FbMA9Nf iNIlBcBYo8owX/GXjJuGZO2y5KdG3WpOon+gv3otpp2dHrQ2pT//hpUxzOdSxbunnX i+bEGlXF8W/bQ== Received: by pali.im (Postfix) id 6918DF12; Sun, 31 Aug 2025 14:36:31 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/35] cifs: Remove code for querying FILE_INFO_STANDARD via CIFSSMBQPathInfo() Date: Sun, 31 Aug 2025 14:35:31 +0200 Message-Id: <20250831123602.14037-5-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Querying FILE_INFO_STANDARD structure via SMB_INFO_STANDARD level over TRANS2_QUERY_PATH_INFORMATION or TRANS2_QUERY_FILE_INFORMATION command (implemented in CIFSSMBQPathInfo() when called with argument legacy=3Dtrue) is mostly unusable. Win9x SMB server returns over those commands the FILE_INFO_STANDARD structure with swapped TIME and DATE fields, compared with [MS-CIFS] spec and Samba server implementation. Therefore this command cannot be used unless we know against which server implementation we are connected. There are already two fallback mechanisms for querying information about path which are working correctly against Samba, NT and Win9x servers: CIFSFindFirst() and SMBQueryInformation() commands. So remove TRANS2_QUERY_PATH_INFORMATION/SMB_INFO_STANDARD code from CIFSSMBQPathInfo() function, when the function is called with legacy=3Dtrue. Note that there is no use of CIFSSMBQPathInfo(legacy=3Dtrue) anymore. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsproto.h | 1 - fs/smb/client/cifssmb.c | 22 +++------------------- fs/smb/client/smb1ops.c | 4 ++-- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index c34c533b2efa..f467b24fd984 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -368,7 +368,6 @@ extern int CIFSSMBQFileInfo(const unsigned int xid, str= uct cifs_tcon *tcon, u16 netfid, FILE_ALL_INFO *pFindData); extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *search_Name, FILE_ALL_INFO *data, - int legacy /* whether to use old info level */, const struct nls_table *nls_codepage, int remap); extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *t= con, const char *search_name, FILE_ALL_INFO *data, diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index d20766f664c4..42ab901a08e7 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -3856,7 +3856,6 @@ CIFSSMBQFileInfo(const unsigned int xid, struct cifs_= tcon *tcon, int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *search_name, FILE_ALL_INFO *data, - int legacy /* old style infolevel */, const struct nls_table *nls_codepage, int remap) { /* level 263 SMB_QUERY_FILE_ALL_INFO */ @@ -3904,10 +3903,7 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs= _tcon *tcon, byte_count =3D params + 1 /* pad */ ; pSMB->TotalParameterCount =3D cpu_to_le16(params); pSMB->ParameterCount =3D pSMB->TotalParameterCount; - if (legacy) - pSMB->InformationLevel =3D cpu_to_le16(SMB_INFO_STANDARD); - else - pSMB->InformationLevel =3D cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); + pSMB->InformationLevel =3D cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); pSMB->Reserved4 =3D 0; inc_rfc1001_len(pSMB, byte_count); pSMB->ByteCount =3D cpu_to_le16(byte_count); @@ -3921,25 +3917,13 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cif= s_tcon *tcon, =20 if (rc) /* BB add auto retry on EOPNOTSUPP? */ rc =3D -EIO; - else if (!legacy && get_bcc(&pSMBr->hdr) < 40) + else if (get_bcc(&pSMBr->hdr) < 40) rc =3D -EIO; /* bad smb */ - else if (legacy && get_bcc(&pSMBr->hdr) < 24) - rc =3D -EIO; /* 24 or 26 expected but we do not read - last field */ else if (data) { int size; __u16 data_offset =3D le16_to_cpu(pSMBr->t2.DataOffset); =20 - /* - * On legacy responses we do not read the last field, - * EAsize, fortunately since it varies by subdialect and - * also note it differs on Set vs Get, ie two bytes or 4 - * bytes depending but we don't care here. - */ - if (legacy) - size =3D sizeof(FILE_INFO_STANDARD); - else - size =3D sizeof(FILE_ALL_INFO); + size =3D sizeof(FILE_ALL_INFO); memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + data_offset, size); } else diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index de415b9945ee..9dca458dbc96 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -526,7 +526,7 @@ cifs_is_path_accessible(const unsigned int xid, struct = cifs_tcon *tcon, =20 if (tcon->ses->capabilities & CAP_NT_SMBS) rc =3D CIFSSMBQPathInfo(xid, tcon, full_path, &file_info, - 0 /* not legacy */, cifs_sb->local_nls, + cifs_sb->local_nls, cifs_remap(cifs_sb)); =20 /* @@ -571,7 +571,7 @@ static int cifs_query_path_info(const unsigned int xid, * do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. */ if (tcon->ses->capabilities & CAP_NT_SMBS) - rc =3D CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, + rc =3D CIFSSMBQPathInfo(xid, tcon, full_path, &fi, cifs_sb->local_nls, cifs_remap(cifs_sb)); =20 /* --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 5B42825BF18; Sun, 31 Aug 2025 12:36:35 +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=1756643795; cv=none; b=kgPUtRRmHj7z6XjdtGdE6nl4+gb72+cfOLt2EwLLxaPVsB+zXWpoAZd3ZS9TK158D1efKMSOJg+CGVsOx1zCuc+D4TYyyS8SWysYH+u9Gt1E295wEn9GsYz5BD/e7da6ZompbwjHNBidlWa+U2l1oOHdlsTznpNhqYi9PhV9rgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643795; c=relaxed/simple; bh=wBAUeZrOIYEFOy72ePFEAHGR9uOeu4N2neoE8ztNYoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=VHrzfvFVKL9JUdLn99iCsduUv0rSCCLKxSXEW9pX9UJfbNKHGEDrvXsnKE9Hmt/sUjDKscM5yke1UG7AanlnP5TppdWx3VF/F/OYXiim9Q4A4Ke5BR5v5sFGfDu20iLfsbIrlgRiZlAplnPOX4+VDHtpEum1zheWSAgdY2r+FSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pM0smwug; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pM0smwug" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E78F6C4CEF8; Sun, 31 Aug 2025 12:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=wBAUeZrOIYEFOy72ePFEAHGR9uOeu4N2neoE8ztNYoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pM0smwugvCwjBRTJQxInP7tHWyGA6ZTDWUzgARrw9ZpGYohayL1CWzvGz+QZL9+VQ 5q/KHvDg2cJjMjMUN9FbRHVfrEawLlMJtgWxLVMSoQeGG1V1RpxQuMbG+m/gdWXcem BvL6ifzw6PiS5Yq6LmkY+XiBDo6pRtNTPOFuazAsBHU5N798TPtfkyiSlDJOPlmDBo ww47vjMtTmhN9M7Gqn8Qdo/iGuR23L1OCNDsXML9WNgDW5sYoVdeEmKMnxJs44IPAE vddP5yRH+00iMKh3vj2IGyYg/LehhmyWD1oi/D/GSK9eEmgWBv3wF5yXu6VC0Q9Hv9 FV/OYKa3n2gOQ== Received: by pali.im (Postfix) id 969EFF96; Sun, 31 Aug 2025 14:36:31 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/35] cifs: Remove CIFSSMBSetPathInfoFB() fallback function Date: Sun, 31 Aug 2025 14:35:32 +0200 Message-Id: <20250831123602.14037-6-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable This fallback function CIFSSMBSetPathInfoFB() is called only from CIFSSMBSetPathInfo() function. CIFSSMBSetPathInfo() is used in smb_set_file_info() which contains all required fallback code, including fallback via filehandle. So the CIFSSMBSetPathInfoFB() is just code duplication, which is not needed anymore. Therefore remove it. This change depends on other changes which are extending cifs_mkdir_setinfo() and smb_set_file_info() functions: "Fix changing times and read-only attr over SMB1 smb_set_file_info() function" and "Add fallback code path for cifs_mkdir_setinfo()" Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 42ab901a08e7..0d773860fd6c 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -5518,38 +5518,6 @@ CIFSSMBSetFileDisposition(const unsigned int xid, st= ruct cifs_tcon *tcon, return rc; } =20 -static int -CIFSSMBSetPathInfoFB(const unsigned int xid, struct cifs_tcon *tcon, - const char *fileName, const FILE_BASIC_INFO *data, - const struct nls_table *nls_codepage, - struct cifs_sb_info *cifs_sb) -{ - int oplock =3D 0; - struct cifs_open_parms oparms; - struct cifs_fid fid; - int rc; - - oparms =3D (struct cifs_open_parms) { - .tcon =3D tcon, - .cifs_sb =3D cifs_sb, - .desired_access =3D GENERIC_WRITE, - .create_options =3D cifs_create_options(cifs_sb, 0), - .disposition =3D FILE_OPEN, - .path =3D fileName, - .fid =3D &fid, - }; - - rc =3D CIFS_open(xid, &oparms, &oplock, NULL); - if (rc) - goto out; - - rc =3D CIFSSMBSetFileInfo(xid, tcon, data, fid.netfid, current->tgid); - CIFSSMBClose(xid, tcon, fid.netfid); -out: - - return rc; -} - int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const FILE_BASIC_INFO *data, @@ -5626,10 +5594,6 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct ci= fs_tcon *tcon, if (rc =3D=3D -EAGAIN) goto SetTimesRetry; =20 - if (rc =3D=3D -EOPNOTSUPP) - return CIFSSMBSetPathInfoFB(xid, tcon, fileName, data, - nls_codepage, cifs_sb); - return rc; } =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 84BA125D218; Sun, 31 Aug 2025 12:36:35 +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=1756643795; cv=none; b=pF5FPZ7ietPLyiYEYNdopDMl6sWh3cQ+QE6Xr+eQIxFKmwxZdlnvToIyzHpzBUokg1NfHMATL53T8wp+HCfsn+Nt6G1GuukL4whL6I4Pl6HSzikkKBWXOtLMw0aRmOQM+VsQPdSuLeMX6sCbDo7f2KZERJEJDOeSez+Cq0BTvmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643795; c=relaxed/simple; bh=DuCeT8rY6iS66n7NYmrNc7MoJE31jMTchtGIjhcADlw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MHwTltFe9y6dZrAGafVjBLtfWD5Oqya+3A9iM0PXZynzV63rf+Dy7CDplfv/MAP5pLkqTld2ehKMIwejPk4qmUCnon4hIbsqXKXjor5Wcshw2oBBJfXuoI+FKwnaRjObR0l95H0P0lu5fjrhhjFJUO7MpSq7NynxCkr66jFZJFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZ8IRncX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZ8IRncX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B1E2C4CEFA; Sun, 31 Aug 2025 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=DuCeT8rY6iS66n7NYmrNc7MoJE31jMTchtGIjhcADlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZ8IRncXSuxSdDqZPq6QN6VKw0YGZrOE3fgQduFt1XAex/19HPHbXSFxo0OfmtawL NGQ22zx5cO6fFYDME0wPAwNJVhoCgPSpojFISM7ClWPgRp2bg09jSXhUXEuwt38SQB W5DKcaSnOtAylkxWCr/XWAkc/v5UmFyTuIiFhsqr24VcCzjwOJTOqlBxWSPkLX7vk8 RQUyD9lNN4uIa2V23rk9cx3JZxNYVgnBpJKrfQZHMj2yVZSjHqUwcKGELD1+djdmMV sWnv2ykZLW53g0Bml88RclGYPmJKz+z+Q2ZUDly1VK21Ak+m9zJ1xV1REQF5Hc6Dby crv4anKXtMtOg== Received: by pali.im (Postfix) id CEF701168; Sun, 31 Aug 2025 14:36:31 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/35] cifs: Remove cifs_backup_query_path_info() and replace it by cifs_query_path_info() Date: Sun, 31 Aug 2025 14:35:33 +0200 Message-Id: <20250831123602.14037-7-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Response handling of cifs_backup_query_path_info() function in cifs_get_fattr() is broken and can cause buffer overflows because cifs_backup_query_path_info() prepares request with different info levels but the response parser in cifs_get_fattr() always expects response structure FILE_DIRECTORY_INFO. Code which queries file/dir attributes via CIFSFindFirst() is already implemented in cifs_query_path_info() function, so extend it for backup_cred(), which is the only missing functionality compared to cifs_backup_query_path_info(). With this change the cifs_query_path_info() would do everything which is open-coded in cifs_set_fattr_ino() and cifs_backup_query_path_info() functions for SMB1. So remove that SMB1 code from cifs_set_fattr_ino() and also remove whole cifs_backup_query_path_info() function. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 97 ----------------------------------------- fs/smb/client/smb1ops.c | 7 ++- 2 files changed, 5 insertions(+), 99 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 75be4b46bc6f..cd06598eacbd 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1046,61 +1046,6 @@ static __u64 simple_hashstr(const char *str) return hash; } =20 -#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY -/** - * cifs_backup_query_path_info - SMB1 fallback code to get ino - * - * Fallback code to get file metadata when we don't have access to - * full_path (EACCES) and have backup creds. - * - * @xid: transaction id used to identify original request in logs - * @tcon: information about the server share we have mounted - * @sb: the superblock stores info such as disk space available - * @full_path: name of the file we are getting the metadata for - * @resp_buf: will be set to cifs resp buf and needs to be freed with - * cifs_buf_release() when done with @data - * @data: will be set to search info result buffer - */ -static int -cifs_backup_query_path_info(int xid, - struct cifs_tcon *tcon, - struct super_block *sb, - const char *full_path, - void **resp_buf, - FILE_ALL_INFO **data) -{ - struct cifs_sb_info *cifs_sb =3D CIFS_SB(sb); - struct cifs_search_info info =3D {0}; - u16 flags; - int rc; - - *resp_buf =3D NULL; - info.endOfSearch =3D false; - if (tcon->unix_ext) - info.info_level =3D SMB_FIND_FILE_UNIX; - else if ((tcon->ses->capabilities & - tcon->ses->server->vals->cap_nt_find) =3D=3D 0) - info.info_level =3D SMB_FIND_FILE_INFO_STANDARD; - else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) - info.info_level =3D SMB_FIND_FILE_ID_FULL_DIR_INFO; - else /* no srvino useful for fallback to some netapp */ - info.info_level =3D SMB_FIND_FILE_DIRECTORY_INFO; - - flags =3D CIFS_SEARCH_CLOSE_ALWAYS | - CIFS_SEARCH_CLOSE_AT_END | - CIFS_SEARCH_BACKUP_SEARCH; - - rc =3D CIFSFindFirst(xid, tcon, full_path, - cifs_sb, NULL, flags, &info, false); - if (rc) - return rc; - - *resp_buf =3D (void *)info.ntwrk_buf_start; - *data =3D (FILE_ALL_INFO *)info.srch_entries_start; - return 0; -} -#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ - static void cifs_set_fattr_ino(int xid, struct cifs_tcon *tcon, struct sup= er_block *sb, struct inode **inode, const char *full_path, struct cifs_open_info_data *data, struct cifs_fattr *fattr) @@ -1314,45 +1259,6 @@ static int cifs_get_fattr(struct cifs_open_info_data= *data, cifs_create_junction_fattr(fattr, sb); rc =3D 0; break; - case -EACCES: -#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY - /* - * perm errors, try again with backup flags if possible - * - * For SMB2 and later the backup intent flag - * is already sent if needed on open and there - * is no path based FindFirst operation to use - * to retry with - */ - if (backup_cred(cifs_sb) && is_smb1_server(server)) { - /* for easier reading */ - FILE_ALL_INFO *fi; - FILE_DIRECTORY_INFO *fdi; - SEARCH_ID_FULL_DIR_INFO *si; - - rc =3D cifs_backup_query_path_info(xid, tcon, sb, - full_path, - &smb1_backup_rsp_buf, - &fi); - if (rc) - goto out; - - move_cifs_info_to_smb2(&data->fi, fi); - fdi =3D (FILE_DIRECTORY_INFO *)fi; - si =3D (SEARCH_ID_FULL_DIR_INFO *)fi; - - cifs_dir_info_to_fattr(fattr, fdi, cifs_sb); - fattr->cf_uniqueid =3D le64_to_cpu(si->UniqueId); - /* uniqueid set, skip get inum step */ - goto handle_mnt_opt; - } else { - /* nothing we can do, bail out */ - goto out; - } -#else - goto out; -#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ - break; default: cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc); goto out; @@ -1367,9 +1273,6 @@ static int cifs_get_fattr(struct cifs_open_info_data = *data, /* * 4. Tweak fattr based on mount options */ -#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY -handle_mnt_opt: -#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ /* query for SFU type info if supported and needed */ if ((fattr->cf_cifsattrs & ATTR_SYSTEM) && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) { diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 9dca458dbc96..55ab8a5b150c 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -584,15 +584,18 @@ static int cifs_query_path_info(const unsigned int xi= d, /* * Then fallback to CIFSFindFirst() which works also with non-NT servers * but does not does not provide NumberOfLinks. + * Can be used with backup intent flag to overcome -EACCES error. */ - if ((rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL) && + if ((rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL || + (backup_cred(cifs_sb) && rc =3D=3D -EACCES)) && !non_unicode_wildcard) { if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) search_info.info_level =3D SMB_FIND_FILE_INFO_STANDARD; else search_info.info_level =3D SMB_FIND_FILE_FULL_DIRECTORY_INFO; rc =3D CIFSFindFirst(xid, tcon, full_path, cifs_sb, NULL, - CIFS_SEARCH_CLOSE_ALWAYS | CIFS_SEARCH_CLOSE_AT_END, + CIFS_SEARCH_CLOSE_ALWAYS | CIFS_SEARCH_CLOSE_AT_END | + (backup_cred(cifs_sb) ? CIFS_SEARCH_BACKUP_SEARCH : 0), &search_info, false); if (rc =3D=3D 0) { if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) { --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 1CB132609D0; Sun, 31 Aug 2025 12:36:35 +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=1756643796; cv=none; b=sO3u6CtGl6prgQHWvQeEBwfEb7i/wHvLYYzl7aCY4ZTU7ZNUagmVmnqtA7QLRE5f31wqfzMqs0+0ukvGBun4i3IN0SFOmeMwSOJflz6FPTqNvGn5KGBg6ohqFkVBOZflaRPAm6u8tS5S9tilJPQzPfImbsJBTHrm1GqJUx0vWvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=Az5JDJb6gm7BaaOCT/rbQWvWiCkLEb8ew0r6DIb5I1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=a35WMgdvGv8+wWP5MnugcI9Hb7O1JYrks2VSnxx7R9kuIHR31Tjs/uD5vBMXoRddi8bxOdwAqYFjcGwQXQeiVGkcdawgPi83H74df2seJXVhMrhIwtBcf9AUen1rKb8tF6om3sU9FYiKcxLUVhHWUgEtL95x2vRF5qHabPG9mvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NnokS++/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NnokS++/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78811C4CEED; Sun, 31 Aug 2025 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=Az5JDJb6gm7BaaOCT/rbQWvWiCkLEb8ew0r6DIb5I1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NnokS++/bzuy4r6n4H5NBbR466sdbazsVmgBu3Xk5x6T9s50pl6gcMq9t9923E2Qg NJBxaFcKNs7kSxrhmcEhF5qliaYug7xq4TSANTLgRQV62crGL5+zw8tBu/0OdtiSip hS3f1GoJMyvJFd0suivn/5zRPNxLpD+0e3tPHL5sTC0Z5Pyc1YfnHnE+8NI8RWbXcH eoQzVQbxXKL0lKr+BT2nZNkfOyxvGxNTvN0Zo6wY7qenOg/mYsY37RgwyU4kvHeEJz aPj1hUJCc3HdL2IVJdbSKaF4o3rmTOdGybT+o2g4h4RoBkWdOdCsF6MnuQVIlmSJR0 aDPlavk39oDkw== Received: by pali.im (Postfix) id 11DDB11D8; Sun, 31 Aug 2025 14:36:32 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/35] cifs: Change translation of STATUS_DELETE_PENDING to -EBUSY Date: Sun, 31 Aug 2025 14:35:34 +0200 Message-Id: <20250831123602.14037-8-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable STATUS_DELETE_PENDING error is returned when trying to open a file which is in delete pending state. Linux SMB client currently translates this error to -ENOENT. So Linux application trying to open a file which still exists will receive -ENOENT error. This is confusing as -ENONET means that directory entry does not exist. File on SMB server can be in delete pending state for an indefinite long period. Moreover it does not have to final state before the real deleting, as any SMB client who still have opened handle to such file can revert file from delete pending state back to normal state. And therefore client can cancel any scheduled file removal. So change translation of STATUS_DELETE_PENDING error to -EBUSY. -EBUSY is used also for STATUS_SHARING_VIOLATION error which is similar case, when opening a file was disallowed by server due to concurrent usage. For SMB1, STATUS_DELETE_PENDING is translated to ERRDOS+ERRbadshare which is then translated to -EBUSY. In the same way is STATUS_SHARING_VIOLATION translated to -EBUSY. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/netmisc.c | 2 +- fs/smb/client/smb2maperror.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c index 9ec20601cee2..4fb265525ea4 100644 --- a/fs/smb/client/netmisc.c +++ b/fs/smb/client/netmisc.c @@ -302,7 +302,7 @@ static const struct { ERRHRD, ERRgeneral, NT_STATUS_EA_CORRUPT_ERROR}, { ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT}, { ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED}, { - ERRDOS, ERRbadfile, NT_STATUS_DELETE_PENDING}, { + ERRDOS, ERRbadshare, NT_STATUS_DELETE_PENDING}, { ERRDOS, ERRunsup, NT_STATUS_CTL_FILE_NOT_SUPPORTED}, { ERRHRD, ERRgeneral, NT_STATUS_UNKNOWN_REVISION}, { ERRHRD, ERRgeneral, NT_STATUS_REVISION_MISMATCH}, { diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c index 12c2b868789f..6d381f26c5cd 100644 --- a/fs/smb/client/smb2maperror.c +++ b/fs/smb/client/smb2maperror.c @@ -368,7 +368,7 @@ static const struct status_to_posix_error smb2_error_ma= p_table[] =3D { {STATUS_EA_CORRUPT_ERROR, -EIO, "STATUS_EA_CORRUPT_ERROR"}, {STATUS_FILE_LOCK_CONFLICT, -EACCES, "STATUS_FILE_LOCK_CONFLICT"}, {STATUS_LOCK_NOT_GRANTED, -EACCES, "STATUS_LOCK_NOT_GRANTED"}, - {STATUS_DELETE_PENDING, -ENOENT, "STATUS_DELETE_PENDING"}, + {STATUS_DELETE_PENDING, -EBUSY, "STATUS_DELETE_PENDING"}, {STATUS_CTL_FILE_NOT_SUPPORTED, -ENOSYS, "STATUS_CTL_FILE_NOT_SUPPORTED"}, {STATUS_UNKNOWN_REVISION, -EIO, "STATUS_UNKNOWN_REVISION"}, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 1CA2D260563; Sun, 31 Aug 2025 12:36:35 +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=1756643796; cv=none; b=Hx7yeTNZkmqOzb1XfbQ7yBNjUSYCO02Fqxjew1IwTMGzXiFgU4Q3a8rh856+6pCHavKRXm5TvQNMM4gXfQTlE3cTyDHsCXbrOTyu7kAadT/XmjWHm8noQkk0Ec9olRh++I2aIzFa+qXUuwv3nedutVH+Enq1hdi7EH8Zf3Ui4kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=b4o6J/pe3WRjO1kZddfQlYqkYBTvWGI5jK3dOnvi1uE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MsXF1Abu1JhJZ405L2LRcekgF+Ggo79GJbMMgcKs7+zA7kEiOsdUQdLmpqbj9fiaU4nwRp4REbLdm6HYL/bXsFuoUBieN+FeNNxBRC7YFOLlWpslTKAGNZcNNWNPJayKlIt5I4Az3xFPQLq7mhgDJJ3W+Bbl+drGG24sa3ctNx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R5iubEEw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R5iubEEw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D78CC4CEFB; Sun, 31 Aug 2025 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643795; bh=b4o6J/pe3WRjO1kZddfQlYqkYBTvWGI5jK3dOnvi1uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5iubEEw87lPIQSQtZTKiSfkPSNHu2vcZRrM+BWooMdEsAXTC3cz0XJsrrQwB+jS7 dfz3ZPbyCGPeYWLPoA8KTmEJJdZRHRPxKuhzZWKe9xjAXuLRalpAr7FBYRZdGutK8f Vzkz2O1SKVszTGbKQ3Rp39Q9HAiIAxYChDDM2J1NoQrj0K7bo0ymOgZA1Bje05cVLH ItLb//1gsyjSyDr5tG/hkCWFdKBXdEUEIHx3A7lensjmmi3qGyUuQIAinAz1wtgapN AdkKK9yYffkScyNKDlXfjZl0wNJr4CY70kXeaMUdEHLvd0Qafd3KqFd8OxJp6uuFSE F97DGrVDMmoVQ== Received: by pali.im (Postfix) id 3CA4A129B; Sun, 31 Aug 2025 14:36:32 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/35] cifs: Improve SMB2+ stat() to work also for paths in DELETE_PENDING state Date: Sun, 31 Aug 2025 14:35:35 +0200 Message-Id: <20250831123602.14037-9-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Paths in DELETE_PENDING state cannot be opened at all. So standard way of querying path attributes for this case is not possible. There is an alternative way how to query limited information about file over SMB2+ dialects without opening file itself. It is by opening the parent directory, querying specific child with filled search filter and asking for attributes for that child. Implement this fallback when standard case in smb2_query_path_info fails with STATUS_DELETE_PENDING error and stat was asked for path which is not top level one (because top level does not have parent directory at all). Depends on "cifs: Change translation of STATUS_DELETE_PENDING to -EBUSY". Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2glob.h | 1 + fs/smb/client/smb2inode.c | 177 +++++++++++++++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index e6830ab3a546..0ecf4988664e 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -2337,6 +2337,7 @@ struct smb2_compound_vars { struct smb_rqst rqst[MAX_COMPOUND]; struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; struct kvec qi_iov; + struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE]; struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; struct kvec close_iov; diff --git a/fs/smb/client/smb2glob.h b/fs/smb/client/smb2glob.h index 224495322a05..1cb219605e75 100644 --- a/fs/smb/client/smb2glob.h +++ b/fs/smb/client/smb2glob.h @@ -39,6 +39,7 @@ enum smb2_compound_ops { SMB2_OP_GET_REPARSE, SMB2_OP_QUERY_WSL_EA, SMB2_OP_OPEN_QUERY, + SMB2_OP_QUERY_DIRECTORY, }; =20 /* Used when constructing chained read requests. */ diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 2a0316c514e4..460e75614ef1 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -176,6 +176,9 @@ static int smb2_compound_op(const unsigned int xid, str= uct cifs_tcon *tcon, struct kvec *out_iov, int *out_buftype, struct dentry *dentry) { =20 + bool has_cifs_mount_server_inum =3D cifs_sb->mnt_cifs_flags & CIFS_MOUNT_= SERVER_INUM; + struct smb2_query_directory_req *qd_rqst =3D NULL; + struct smb2_query_directory_rsp *qd_rsp =3D NULL; struct smb2_create_rsp *create_rsp =3D NULL; struct smb2_query_info_rsp *qi_rsp =3D NULL; struct smb2_compound_vars *vars =3D NULL; @@ -344,6 +347,41 @@ static int smb2_compound_op(const unsigned int xid, st= ruct cifs_tcon *tcon, trace_smb3_posix_query_info_compound_enter(xid, tcon->tid, ses->Suid, full_path); break; + case SMB2_OP_QUERY_DIRECTORY: + rqst[num_rqst].rq_iov =3D &vars->qd_iov[0]; + rqst[num_rqst].rq_nvec =3D SMB2_QUERY_DIRECTORY_IOV_SIZE; + + rc =3D SMB2_query_directory_init(xid, + tcon, + server, + &rqst[num_rqst], + cfile ? + cfile->fid.persistent_fid : COMPOUND_FID, + cfile ? + cfile->fid.volatile_fid : COMPOUND_FID, + 0, + has_cifs_mount_server_inum ? + SMB_FIND_FILE_ID_FULL_DIR_INFO : + SMB_FIND_FILE_FULL_DIRECTORY_INFO); + if (!rc) { + /* + * Change the default search wildcard pattern '*' + * to the requested file name stored in in_iov[i] + * and request for only one single entry. + */ + qd_rqst =3D rqst[num_rqst].rq_iov[0].iov_base; + qd_rqst->Flags |=3D SMB2_RETURN_SINGLE_ENTRY; + qd_rqst->FileNameLength =3D cpu_to_le16(in_iov[i].iov_len); + rqst[num_rqst].rq_iov[1] =3D in_iov[i]; + } + if (!rc && (!cfile || num_rqst > 1)) { + smb2_set_next_command(tcon, &rqst[num_rqst]); + smb2_set_related(&rqst[num_rqst]); + } else if (rc) { + goto finished; + } + num_rqst++; + break; case SMB2_OP_DELETE: trace_smb3_delete_enter(xid, tcon->tid, ses->Suid, full_path); break; @@ -730,6 +768,64 @@ static int smb2_compound_op(const unsigned int xid, st= ruct cifs_tcon *tcon, trace_smb3_posix_query_info_compound_done(xid, tcon->tid, ses->Suid); break; + case SMB2_OP_QUERY_DIRECTORY: + if (rc =3D=3D 0) { + qd_rsp =3D (struct smb2_query_directory_rsp *) + rsp_iov[i + 1].iov_base; + rc =3D smb2_validate_iov(le16_to_cpu(qd_rsp->OutputBufferOffset), + le32_to_cpu(qd_rsp->OutputBufferLength), + &rsp_iov[i + 1], + has_cifs_mount_server_inum ? + sizeof(SEARCH_ID_FULL_DIR_INFO) : + sizeof(FILE_FULL_DIRECTORY_INFO)); + } + if (rc =3D=3D 0) { + /* + * Both SEARCH_ID_FULL_DIR_INFO and FILE_FULL_DIRECTORY_INFO + * have same member offsets except the UniqueId and FileName. + */ + SEARCH_ID_FULL_DIR_INFO *si =3D + (SEARCH_ID_FULL_DIR_INFO *)qd_rsp->Buffer; + + idata =3D in_iov[i + 1].iov_base; + idata->fi.CreationTime =3D si->CreationTime; + idata->fi.LastAccessTime =3D si->LastAccessTime; + idata->fi.LastWriteTime =3D si->LastWriteTime; + idata->fi.ChangeTime =3D si->ChangeTime; + idata->fi.Attributes =3D si->ExtFileAttributes; + idata->fi.AllocationSize =3D si->AllocationSize; + idata->fi.EndOfFile =3D si->EndOfFile; + idata->fi.EASize =3D si->EaSize; + idata->fi.Directory =3D + !!(le32_to_cpu(si->ExtFileAttributes) & ATTR_DIRECTORY); + /* + * UniqueId is present only in struct SEARCH_ID_FULL_DIR_INFO. + * It is not present in struct FILE_FULL_DIRECTORY_INFO. + * struct SEARCH_ID_FULL_DIR_INFO was requested only when + * CIFS_MOUNT_SERVER_INUM is set. + */ + if (has_cifs_mount_server_inum) + idata->fi.IndexNumber =3D si->UniqueId; + /* + * Do not change idata->fi.NumberOfLinks to correctly + * trigger the CIFS_FATTR_UNKNOWN_NLINK flag. + */ + /* + * Do not change idata->fi.DeletePending as we do not know if + * the entry is in the delete pending state. SMB2 QUERY_DIRECTORY + * at any level does not provide this information. + */ + } + SMB2_query_directory_free(&rqst[num_rqst++]); + if (rc) + trace_smb3_query_dir_err(xid, + cfile ? cfile->fid.persistent_fid : COMPOUND_FID, + tcon->tid, ses->Suid, 0, 0, rc); + else + trace_smb3_query_dir_done(xid, + cfile ? cfile->fid.persistent_fid : COMPOUND_FID, + tcon->tid, ses->Suid, 0, 0); + break; case SMB2_OP_DELETE: if (rc) trace_smb3_delete_err(xid, tcon->tid, ses->Suid, rc); @@ -1090,9 +1186,9 @@ int smb2_query_path_info(const unsigned int xid, break; case -EREMOTE: break; - default: - if (hdr->Status !=3D STATUS_OBJECT_NAME_INVALID) - break; + } + + if (hdr->Status =3D=3D STATUS_OBJECT_NAME_INVALID) { rc2 =3D cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb, full_path, &islink); if (rc2) { @@ -1101,6 +1197,81 @@ int smb2_query_path_info(const unsigned int xid, } if (islink) rc =3D -EREMOTE; + } else if (hdr->Status =3D=3D STATUS_DELETE_PENDING && full_path[0]) { + /* + * If SMB2 OPEN/CREATE fails with STATUS_DELETE_PENDING error, + * it means that the path is in delete pending state and it is + * not possible to open it until some other client clears delete + * pending state or all other clients close all opened handles + * to that path. + * + * There is an alternative way how to query limited information + * about path which is in delete pending state still suitable + * for the stat() syscall. It is by opening the parent directory, + * querying specific child with filled search filer and asking + * for attributes for that child. + */ + + char *parent_path; + const char *basename; + __le16 *basename_utf16; + int basename_utf16_len; + struct cifsFileInfo *parent_cfile; + + basename =3D strrchr(full_path, CIFS_DIR_SEP(cifs_sb)); + if (basename) { + parent_path =3D kstrndup(full_path, basename - full_path, GFP_KERNEL); + basename++; + } else { + parent_path =3D kstrdup("", GFP_KERNEL); + basename =3D full_path; + } + + if (!parent_path) { + rc =3D -ENOMEM; + goto out; + } + + basename_utf16 =3D cifs_convert_path_to_utf16(basename, cifs_sb); + if (!basename_utf16) { + kfree(parent_path); + rc =3D -ENOMEM; + goto out; + } + + basename_utf16_len =3D 2 * UniStrnlen((wchar_t *)basename_utf16, PATH_MA= X); + +retry_query_directory: + num_cmds =3D 1; + cmds[0] =3D SMB2_OP_QUERY_DIRECTORY; + in_iov[0].iov_base =3D basename_utf16; + in_iov[0].iov_len =3D basename_utf16_len; + in_iov[1].iov_base =3D data; + in_iov[1].iov_len =3D sizeof(*data); + oparms =3D CIFS_OPARMS(cifs_sb, tcon, parent_path, FILE_READ_DATA, + FILE_OPEN, CREATE_NOT_FILE, ACL_NO_MODE); + cifs_get_readable_path(tcon, parent_path, &parent_cfile); + free_rsp_iov(out_iov, out_buftype, ARRAY_SIZE(out_iov)); + rc =3D smb2_compound_op(xid, tcon, cifs_sb, parent_path, + &oparms, in_iov, cmds, num_cmds, + parent_cfile, out_iov, out_buftype, NULL); + if (rc =3D=3D -EOPNOTSUPP && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVE= R_INUM)) { + /* + * If querying of server inode numbers is not supported + * but is enabled, then disable it and try again. + */ + cifs_autodisable_serverino(cifs_sb); + goto retry_query_directory; + } + + kfree(parent_path); + kfree(basename_utf16); + + hdr =3D out_iov[0].iov_base; + if (!hdr || out_buftype[0] =3D=3D CIFS_NO_BUFFER) + goto out; + + data->fi.DeletePending =3D 1; /* This is code path for STATUS_DELETE_PEN= DING. */ } =20 out: --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 C61F226738B; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=XI2sGWDvwsdrH0vR1z9hwDJHyxHrzRi5JF8PnevGQ7n01Z7bkKPTy2Zpt1FGYwwbhnZ+IvG4ZAUNmqyqehl16rJ6mKD2dmpOsD3ZJbn9vQxOmnaD/aSCrD3mOhyKNjlBqowRq26kcP2CRWrBiBPLtyh86U2roBxOTUoFIw6/70s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=BXUcj05D0nzaBygjxeeEalRlR274ycVXMEtvJz86+vc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=FGShzMQk6bNaTHU9IHNiItIHRr+FjYrWI8UEv7Sq+LRWYG71BWKWudSHpIktqQa6DMeKMJgWBycM+4cVDzDIf7E/OLjWpQByWzll3kd+LqMcQt6cqQQxwIBWO+wDByuSMRoMrdhk4cA9/aG/s1ROzwkj5bDKDzeelEb/fsvRWCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UYsmgHwx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UYsmgHwx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85CF9C4CEFB; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=BXUcj05D0nzaBygjxeeEalRlR274ycVXMEtvJz86+vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UYsmgHwxRnzDZXYkUeNdrxqbkbWhEHx1l+62UWnV44irYXz970jrYPCFjF48Veynz HY8FMM9LQfurcI4zGnP7xiVoCGi2pNhhW/i4f0C5O7RorFr84JGl7JLXTYVQomFawL lLpQ9MmV2UMKCzVs9L2uxWRabWoLOfGrxCzTWaCF+5Ouwmxq78JqmDotwP3F4qyMyF V6Jk/kRKYp1CM8Kp599sRgT5VT9ad0v1ef9EDrScHWEtOQ5DCECLNpcgUvt4OlzQBv UJJkflc8chXFZmJMvOAHKkEFE2eY2zhoZ6HL1iUGzST/Axri+d6ITcM/EYSN9uKEpU iG+wFH2GRoYKA== Received: by pali.im (Postfix) id 629CE12A7; Sun, 31 Aug 2025 14:36:32 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/35] cifs: Improve SMB1 stat() to work also for paths in DELETE_PENDING state Date: Sun, 31 Aug 2025 14:35:36 +0200 Message-Id: <20250831123602.14037-10-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Windows NT SMB server may return -EBUSY (STATUS_DELETE_PENDING) from CIFSSMBQPathInfo() function for files which are in DELETE_PENDING state. When this happens, it is still possible to use CIFSFindFirst() fallback. So allow to use CIFSFindFirst() fallback also for -EBUSY error. This change fixes stat() to work also against Windows Server 2022 for files in DELETE_PENDING state. Depends on "cifs: Change translation of STATUS_DELETE_PENDING to -EBUSY". Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb1ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 55ab8a5b150c..176bc2a211bf 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -583,10 +583,11 @@ static int cifs_query_path_info(const unsigned int xi= d, =20 /* * Then fallback to CIFSFindFirst() which works also with non-NT servers - * but does not does not provide NumberOfLinks. + * but does not does not provide NumberOfLinks. Also it works for files + * in DELETE_PENDING state (CIFSSMBQPathInfo() returns -EBUSY for them). * Can be used with backup intent flag to overcome -EACCES error. */ - if ((rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL || + if ((rc =3D=3D -EOPNOTSUPP || rc =3D=3D -EINVAL || rc =3D=3D -EBUSY || (backup_cred(cifs_sb) && rc =3D=3D -EACCES)) && !non_unicode_wildcard) { if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 7F226262FCD; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=W92tnl61HYKwJWTNsuhagToBc4aXkv7Yc+eNaZEpQWGgW+CaBNbJwv4EPzThTokygmEKhJYWxh0o/6nPDbAUTh5eSA0kgIX5ZXKsuddi4IpERojIDAOVixMY5iM+yNTyZD9V5Q+XFRPsNFB4lmnTRvCyTgW/zcO0ZrVR7RHXwb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=TnPcF/6qorEoK+kPpWDJGGJ4T8oJ3meDyJpxJleBazA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=b7Qlq/N0FeYS08BjYL74K3cOs1aN2EuXzfiKZey6UMldv386MtE/sh+fch/2czlqxuxIU/2mUaO7gz9vzFUrCl3OiyIHoEFcjfi59Bca145Hy/pIHPcbW6bds2JzUQxPm/mV8gTptEJMHfAbodtjQqn5jXKbiaxERPGZn26FZTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BSIGQFQX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BSIGQFQX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0F72C4CEF5; Sun, 31 Aug 2025 12:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=TnPcF/6qorEoK+kPpWDJGGJ4T8oJ3meDyJpxJleBazA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BSIGQFQXTmIbJGwFAu2Q0/ZROKk5VUz8SK21TD90twLwTURjNPTtW/20V6JhGp/ke wKiGx2lpdFyDyeuX1ga+m/Ercee6OHmCy3eIcNxO96RBZ2ktU8r+UwKCmElr4fGZBd pT19AsXObJTqOJs1RcAd3GQdotBesz8gAiSFITfejTCay4pFSKwAYo8dt96g8qtqkt MZBvrzGs5ZwdX1PFu/BuBFZsjfYfxggPMVhAnRwWm8X3rjaATCAMDnW4GlGZMEKZG5 1+1RzFnaOFCHa3LBIBOE6yPw5bo+Htz/OKd1I133j9ENbYFqjQcW/k9uDDykBTEssc D9uUh+pP3lcLw== Received: by pali.im (Postfix) id 9D92812DE; Sun, 31 Aug 2025 14:36:32 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/35] cifs: Improve detect_directory_symlink_target() function Date: Sun, 31 Aug 2025 14:35:37 +0200 Message-Id: <20250831123602.14037-11-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Function detect_directory_symlink_target() is not currently able to detect if the target path is directory in case the path is in the DELETE_PENDING state or the user has not granted FILE_READ_ATTRIBUTES permission on the path. This limitation is written in TODO comment. Resolve this problem by replacing code which determinate path type by the query_path_info() callback, which now is able to handle all these cases. Depends on "cifs: Improve SMB2+ stat() to work also for paths in DELETE_PENDING state". Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/reparse.c | 75 ++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/fs/smb/client/reparse.c b/fs/smb/client/reparse.c index 7869cec58f52..236629778e1c 100644 --- a/fs/smb/client/reparse.c +++ b/fs/smb/client/reparse.c @@ -250,18 +250,16 @@ static int detect_directory_symlink_target(struct cif= s_sb_info *cifs_sb, bool *directory) { char sep =3D CIFS_DIR_SEP(cifs_sb); - struct cifs_open_parms oparms; + struct cifs_open_info_data query_info; struct tcon_link *tlink; struct cifs_tcon *tcon; const char *basename; - struct cifs_fid fid; char *resolved_path; int full_path_len; int basename_len; int symname_len; char *path_sep; - __u32 oplock; - int open_rc; + int query_rc; =20 /* * First do some simple check. If the original Linux symlink target ends @@ -284,7 +282,8 @@ static int detect_directory_symlink_target(struct cifs_= sb_info *cifs_sb, if (symname[0] =3D=3D '/') { cifs_dbg(FYI, "%s: cannot determinate if the symlink target path '%s' " - "is directory or not, creating '%s' as file symlink\n", + "is directory or not because path is absolute, " + "creating '%s' as file symlink\n", __func__, symname, full_path); return 0; } @@ -322,58 +321,34 @@ static int detect_directory_symlink_target(struct cif= s_sb_info *cifs_sb, if (sep =3D=3D '\\') convert_delimiter(path_sep, sep); =20 + /* + * Query resolved SMB symlink path and check if it is a directory or not. + * Callback query_path_info() already handles cases when the server does + * not grant FILE_READ_ATTRIBUTES permission for object, or when server + * denies opening the object (e.g. because of DELETE_PENDING state). + */ tcon =3D tlink_tcon(tlink); - oparms =3D CIFS_OPARMS(cifs_sb, tcon, resolved_path, - FILE_READ_ATTRIBUTES, FILE_OPEN, 0, ACL_NO_MODE); - oparms.fid =3D &fid; - - /* Try to open as a directory (NOT_FILE) */ - oplock =3D 0; - oparms.create_options =3D cifs_create_options(cifs_sb, - CREATE_NOT_FILE | OPEN_REPARSE_POINT); - open_rc =3D tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL); - if (open_rc =3D=3D 0) { - /* Successful open means that the target path is definitely a directory.= */ - *directory =3D true; - tcon->ses->server->ops->close(xid, tcon, &fid); - } else if (open_rc =3D=3D -ENOTDIR) { - /* -ENOTDIR means that the target path is definitely a file. */ - *directory =3D false; - } else if (open_rc =3D=3D -ENOENT) { + query_rc =3D tcon->ses->server->ops->query_path_info(xid, tcon, cifs_sb, + resolved_path, &query_info); + if (query_rc =3D=3D 0) { + /* Query on path was successful, so just check for directory attr. */ + *directory =3D le32_to_cpu(query_info.fi.Attributes) & ATTR_DIRECTORY; + } else if (query_rc =3D=3D -ENOENT) { /* -ENOENT means that the target path does not exist. */ cifs_dbg(FYI, "%s: symlink target path '%s' does not exist, " "creating '%s' as file symlink\n", __func__, symname, full_path); } else { - /* Try to open as a file (NOT_DIR) */ - oplock =3D 0; - oparms.create_options =3D cifs_create_options(cifs_sb, - CREATE_NOT_DIR | OPEN_REPARSE_POINT); - open_rc =3D tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL); - if (open_rc =3D=3D 0) { - /* Successful open means that the target path is definitely a file. */ - *directory =3D false; - tcon->ses->server->ops->close(xid, tcon, &fid); - } else if (open_rc =3D=3D -EISDIR) { - /* -EISDIR means that the target path is definitely a directory. */ - *directory =3D true; - } else { - /* - * This code branch is called when we do not have a permission to - * open the resolved_path or some other client/process denied - * opening the resolved_path. - * - * TODO: Try to use ops->query_dir_first on the parent directory - * of resolved_path, search for basename of resolved_path and - * check if the ATTR_DIRECTORY is set in fi.Attributes. In some - * case this could work also when opening of the path is denied. - */ - cifs_dbg(FYI, - "%s: cannot determinate if the symlink target path '%s' " - "is directory or not, creating '%s' as file symlink\n", - __func__, symname, full_path); - } + /* + * This code branch is called when we do not have a permission to + * query the resolved_path or some other error occurred during query. + */ + cifs_dbg(FYI, + "%s: cannot determinate if the symlink target path '%s' " + "is directory or not because query path failed (%d), " + "creating '%s' as file symlink\n", + __func__, symname, query_rc, full_path); } =20 kfree(resolved_path); --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 AE3D12638BF; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=BP8L4Kv0f0ZZqfRVmaJcIqq0Av9bvDEt8ZtX8dTyuGYea8oARXQDwDH+2HqGoOsebA7qOW6AreSAHV+YKNZeO5Nzk8rmFAxC9fA6nXJA1Q9Sq3j/XD3GrWyodRua4CrctekbSquQoD6XjkTCtoFwj699WJv9PQa80hL593fFk/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=+QzW6WS770qe8L4U8LsmAd3yFbVgCPbv0vehCJ85w1o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YwW/OgDB7WdvLXY5kbrWzofmhGdq+6D1CHG0RNMTYiBOdXIVPep9YYHpg0eB4nPFtFayBOPDB12idb7VMrW/wbYJwlKv3kMKDf7Yvni/sL4nw9D/ecr2B2LWTDwxHmMnSnO1+HDwhvdcwFZbX0IOZom+n45NXbNmorXwhT2or4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dBzApElm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dBzApElm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F046C4CEF6; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=+QzW6WS770qe8L4U8LsmAd3yFbVgCPbv0vehCJ85w1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dBzApElmB76e9kqne+3ADizGg0v5RqPjbcFkvb4DzqwHOslQN60GKUnhgaCJBSU5p lc0G7DiqYvXFz1s50RmuV5vMcH58IxGNIoATSmBVztmFD0OAslYGZXaz8kG0wyj19T HWSeYUNccm1oI9U0UiY83OFN2PBQT5EwZsV+IzEdAtL6rfhwRP6paIXtpbwLDoygC5 11xeR6sNgqsXYSGnnx06oxHSVWuVb22KsXNs3ncJ9+i3AtDd4jndyJfvmCP/FN3Ahu Jdb1PtvIpdQPw44TA90W0SEJHgg2ZCZhSZ/ROqteBe9bhbcxZ0bId2+ED98g40xr+V 0K0pPAc/Wft3g== Received: by pali.im (Postfix) id E121812ED; Sun, 31 Aug 2025 14:36:32 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/35] cifs: Fix random name construction for cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:38 +0200 Message-Id: <20250831123602.14037-12-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Currently the random name for SMB1 silly rename used in cifs_rename_pending_delete() is generated as: cifs This is not very unique and can cause conflicts. Also it does not match the comment which says something different. Change the way how it is generated and use the algorithm from nfs client and construct random name as: .smb Where counter is global counter incremented for each request and generated name is checked if it really does not exist before it is used. NFS client uses same pattern but instead of ".smb" it has ".nfs". Move random name construction code from CIFSSMBRenameOpenFile() function to cifs_rename_pending_delete() function as it is the place where silly rename is implemented. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 12 +----------- fs/smb/client/inode.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 0d773860fd6c..8d9f6f28c17e 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -2320,7 +2320,6 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, str= uct cifs_tcon *pTcon, struct smb_com_transaction2_sfi_rsp *pSMBr =3D NULL; struct set_file_rename *rename_info; char *data_offset; - char dummy_string[30]; int rc =3D 0; int bytes_returned =3D 0; int len_of_str; @@ -2354,21 +2353,12 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, s= truct cifs_tcon *pTcon, pSMB->TotalParameterCount =3D pSMB->ParameterCount; pSMB->ParameterOffset =3D cpu_to_le16(param_offset); pSMB->DataOffset =3D cpu_to_le16(offset); - /* construct random name ".cifs_tmp" */ rename_info->overwrite =3D cpu_to_le32(1); rename_info->root_fid =3D 0; /* unicode only call */ - if (target_name =3D=3D NULL) { - sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); - len_of_str =3D - cifsConvertToUTF16((__le16 *)rename_info->target_name, - dummy_string, 24, nls_codepage, remap); - } else { - len_of_str =3D - cifsConvertToUTF16((__le16 *)rename_info->target_name, + len_of_str =3D cifsConvertToUTF16((__le16 *)rename_info->target_name, target_name, PATH_MAX, nls_codepage, remap); - } rename_info->target_name_len =3D cpu_to_le32(2 * len_of_str); count =3D sizeof(struct set_file_rename) + (2 * len_of_str); byte_count +=3D count; diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index cd06598eacbd..a37dfd50f33d 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -6,6 +6,7 @@ * */ #include +#include #include #include #include @@ -1689,6 +1690,13 @@ cifs_set_file_info(struct inode *inode, struct iattr= *attrs, unsigned int xid, * and rename it to a random name that hopefully won't conflict with * anything else. */ +#define SILLYNAME_PREFIX ".smb" +#define SILLYNAME_PREFIX_LEN ((unsigned int)sizeof(SILLYNAME_PREFIX) - 1) +#define SILLYNAME_FILEID_LEN ((unsigned int)sizeof(u64) << 1) +#define SILLYNAME_COUNTER_LEN ((unsigned int)sizeof(unsigned int) << 1) +#define SILLYNAME_LEN (SILLYNAME_PREFIX_LEN + \ + SILLYNAME_FILEID_LEN + \ + SILLYNAME_COUNTER_LEN) int cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, const unsigned int xid) @@ -1704,12 +1712,40 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, struct cifs_tcon *tcon; __u32 dosattr, origattr; FILE_BASIC_INFO *info_buf =3D NULL; + unsigned char sillyname[SILLYNAME_LEN + 1]; + int sillyname_len; =20 tlink =3D cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) return PTR_ERR(tlink); tcon =3D tlink_tcon(tlink); =20 + /* construct random name ".smb" */ + while (true) { + static unsigned int sillycounter; /* globally unique */ + bool sillyname_available =3D false; + struct dentry *sdentry =3D NULL; + + sillycounter++; + sillyname_len =3D scnprintf(sillyname, sizeof(sillyname), + SILLYNAME_PREFIX "%0*llx%0*x", + SILLYNAME_FILEID_LEN, (unsigned long long)cifsInode->uniqueid, + SILLYNAME_COUNTER_LEN, sillycounter); + sdentry =3D lookup_noperm(&QSTR(sillyname), dentry->d_parent); + if (IS_ERR(sdentry)) { + rc =3D -EBUSY; + goto out; + } + + if (d_inode(sdentry) =3D=3D NULL) /* need negative lookup */ + sillyname_available =3D true; + + dput(sdentry); + + if (sillyname_available) + break; + } + /* * We cannot rename the file if the server doesn't support * CAP_INFOLEVEL_PASSTHRU @@ -1761,7 +1797,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, } =20 /* rename the file */ - rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, NULL, + rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, cifs_sb->local_nls, cifs_remap(cifs_sb)); if (rc !=3D 0) { --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 6AB93261B9C; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=NSfgjM5xD8LhSorzkUYmgT0VVi1ImIQOinziq8a2zD0u0Jdc3IeWnVznINC32G9FnJTCZhi936lpPVkkvfvNsJ15MCJYyT2a35tDWu5R9zKVCH+i/LSU/XU/jMWuJobC/I1Ys3MzcZoqRptqCVUtcmM+8IbTu56QELz8DZdiLQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=kC5DjeLp2/DF2gH6YKCu9BPP80cHs8gGhN3jPgrVOhM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=X6GU6LQnPcicF4TF84jU9fY0LqDAQRng6vt80G/5STZDZ6xk/ID+8kM6FspBB0MFiG4MKxr9vcC1GY42Kgu7xHx2SpxqQ7DDuh32AdNXAcfJSx6C/gD6scEqsueR1Wlf3QVhILMCTGqSmoI1L7rbF6RMflOwa5b0DNF5hmHDhKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rG7HX2nm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rG7HX2nm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D567C4CEF9; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=kC5DjeLp2/DF2gH6YKCu9BPP80cHs8gGhN3jPgrVOhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rG7HX2nmFUOHpmI5lSiNVGNEM1x/5RK7jIoI6qM+n2b0Mgtwth/ZwNs5bociYxySy uFa3t1PWZpomgBDqMfRAIQlJUUTikqn+q2MtPsEoOAIH4ywK/nsRRy4rxYuUNseiF1 zwTPGdONtQi+HxcJh1WztNAMX2leC2B978sNbR2Jl8HN+eGVSHam0duRocfJHDDKTG O6z1wiQ8xjURbMrJ+CNzzqyGeufFBJSojcv/4bAbPRI8+umyZeMcw0Gb8APvCKEHIX gv6BtsacOlN63ARTXKrD0uCUHdrPm6EiKALBuP8WxLkyY7PQnS6gYwmc4rv0Gpznwz HstsX5K38yDuQ== Received: by pali.im (Postfix) id 291D91308; Sun, 31 Aug 2025 14:36:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/35] cifs: Fix DELETE comments in cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:39 +0200 Message-Id: <20250831123602.14037-13-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable DELETE_ON_CLOSE is a flag which is being set during the opening a file and DELETE_PENDING flag is being set by SetFileDisposition() on the already opened file. Those two flags are different and have different meaning. There in the function cifs_rename_pending_delete() is being set DELETE_PENDING flag on the already opened file. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index a37dfd50f33d..88d1d657cfb0 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1686,7 +1686,7 @@ cifs_set_file_info(struct inode *inode, struct iattr = *attrs, unsigned int xid, =20 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY /* - * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit + * Open the given file (if it isn't already), set the DELETE_PENDING bit * and rename it to a random name that hopefully won't conflict with * anything else. */ @@ -1805,7 +1805,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, goto undo_setattr; } =20 - /* try to set DELETE_ON_CLOSE */ + /* try to set DELETE_PENDING */ if (!test_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags)) { rc =3D CIFSSMBSetFileDisposition(xid, tcon, true, fid.netfid, current->tgid); --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 7AF13262FC2; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=JEgJGbtVluW4LWnDxIkl2r5yN8mV7/9ZTJmiwsNm+nqkqkdp5OtOPfTTYRVtvpTGjeMEy6ZtJKX8CZPoQ6nL0sZhiuypf5zAUEHV8mDJlTTph3DpcuQmiu2oSGbioMMaWG5zSBNvL/dNktTiyqYAVZnpm4jdhfQLggL0VLhdCg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=sXWaFMdUwYOSr6TRFPlyz4v0sDW5h49C99sHYUcew2g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Pz7uKyrMFT+BtQRo8vabqJbpnTOdhh+dQYApuVb2EoasWicmQySVlSqtmBC4eLBcPu7xZUj/BS12Fi6sDsrpdRh1v0jXuhEdKnnz9pnprAj4qJsEqlOdqVIzX1M7WiXXN/j6ag413gc4oCeraaMO4oi4FuzplVaOuXP/8ONQV/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aY85IN9P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aY85IN9P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D159C4CEFD; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=sXWaFMdUwYOSr6TRFPlyz4v0sDW5h49C99sHYUcew2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aY85IN9PU/YNTZd4PC8ODJ87KR2GZUSfI/dHQHoYjRxmDjgYMl4VJjQ/dyhpq9qqr puj6ehpPUAb4sz8nrhGtD5evz8aKthJYhjaCrxGjJ/mwMfjGzg98PQ5Z3g9Mds7Tqx DFlJj1DsldC0CiD2xT1QSoy9bGCuZe727M/p3vJc+9cEOrpW1kk/MdqTrGCBVfvANi p4KkLl2y6sdMzfE4qzKx+8NP3e1vff7A7FlIcQ6GIbHAuCh7AF2M7NQ+KmrxszpigA teCKDiH5CL5JoPi7S/dtPt4YzhA9UvSr7b/cEwfx2KL0k1ye/ynlsN6z8lWJ/k9fvE vBQuDRZqTjoLA== Received: by pali.im (Postfix) id 52F8613DE; Sun, 31 Aug 2025 14:36:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/35] cifs: Avoid dynamic memory allocation of FILE_BASIC_INFO buffer in cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:40 +0200 Message-Id: <20250831123602.14037-14-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Put FILE_BASIC_INFO buffer on the stack as it is not too large. This simplify error handling in cifs_rename_pending_delete(). Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 88d1d657cfb0..2889fa6625af 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1711,7 +1711,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, struct tcon_link *tlink; struct cifs_tcon *tcon; __u32 dosattr, origattr; - FILE_BASIC_INFO *info_buf =3D NULL; + FILE_BASIC_INFO info_buf =3D {}; unsigned char sillyname[SILLYNAME_LEN + 1]; int sillyname_len; =20 @@ -1780,13 +1780,8 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, =20 /* set ATTR_HIDDEN and clear ATTR_READONLY, but only if needed */ if (dosattr !=3D origattr) { - info_buf =3D kzalloc(sizeof(*info_buf), GFP_KERNEL); - if (info_buf =3D=3D NULL) { - rc =3D -ENOMEM; - goto out_close; - } - info_buf->Attributes =3D cpu_to_le32(dosattr); - rc =3D CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid, + info_buf.Attributes =3D cpu_to_le32(dosattr); + rc =3D CIFSSMBSetFileInfo(xid, tcon, &info_buf, fid.netfid, current->tgid); /* although we would like to mark the file hidden if that fails we will still try to rename it */ @@ -1829,7 +1824,6 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, out_close: CIFSSMBClose(xid, tcon, fid.netfid); out: - kfree(info_buf); cifs_put_tlink(tlink); return rc; =20 @@ -1843,8 +1837,8 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, cifs_sb->local_nls, cifs_remap(cifs_sb)); undo_setattr: if (dosattr !=3D origattr) { - info_buf->Attributes =3D cpu_to_le32(origattr); - if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid, + info_buf.Attributes =3D cpu_to_le32(origattr); + if (!CIFSSMBSetFileInfo(xid, tcon, &info_buf, fid.netfid, current->tgid)) cifsInode->cifsAttrs =3D origattr; } --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 7113326A1B5; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=gYSX9wB9DSz2PIGwWFPb4Psk6ivtN9F50pgTJdvKggbhc5ewClH/Pa/jPSZye2JtPsz6eVOUU3OjfVFzlAEN6HsGZIdGvSsXrFKKITHV+UmTbjT05tArOotB752i6P+kuKO2nVAyzaRzGVP2SUbc6TCCDfblWWKZLdmloQ1IBts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=bf7MNX1yDmW4c/5HyYGIxpycUcryAysX16+cXoiPGH8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hlnHeg7wCEY5isom6BXdzuVcYq64nT0taBRW5uYo03oJw+n1OsC6ifRM/5yUNMbjYYMu5L+3UOp0odlrTBH7ljSR+a+g1+aiOLuPiSqdz2hql2eCljKxGvHzK5WgsBnw77Gf+LFQRKWw7frthQQ4xByj0Tp7X4E8BHdelaPC1yY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D6w09TsT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D6w09TsT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32D96C4CEF5; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=bf7MNX1yDmW4c/5HyYGIxpycUcryAysX16+cXoiPGH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D6w09TsT9Rg/oxH9nY68HHBbgba+ITmO33hXijm8x/fBWXbFuJzA3rfnmqHPAXqDg QUbhXdLewhTCgC/ndzBCId4sZKp3e1XArHkl2IX4JHvTdguC2K8AI51DYTdKGK0+8Z 8WE+FQpygMIkVlJIgjdtUTISPbetzpQ/IMwmi0ZFqeYCjamN8RZmo/GFfTJmgiXuzc rUMh4VQfx38KpcCnzk6uoXa8ZR/B94J3OrbTRmOfJuEumkPsFLiHnurFr9qcf4IubU kzwlxv/DsyqQE21cahQ6D3Zn/n7R7GSJx5z8vDkWr1dj733uH3nmrUsUpDSUDOnq2R e9CSuRfDeVSsg== Received: by pali.im (Postfix) id 7E3691407; Sun, 31 Aug 2025 14:36:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/35] cifs: Extend CIFSSMBRenameOpenFile() function for overwrite parameter Date: Sun, 31 Aug 2025 14:35:41 +0200 Message-Id: <20250831123602.14037-15-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Currently CIFSSMBRenameOpenFile() function always overwrite the target location. This new overwrite parameter allows to specify if the rename should fail when the target location exists. This new parameter would be used in follow up changes. No functional change. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsproto.h | 2 +- fs/smb/client/cifssmb.c | 4 ++-- fs/smb/client/inode.c | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index f467b24fd984..f248b18f1cf3 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -470,7 +470,7 @@ int CIFSSMBRename(const unsigned int xid, struct cifs_t= con *tcon, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb); extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon = *tcon, - int netfid, const char *target_name, + int netfid, const char *target_name, bool overwrite, const struct nls_table *nls_codepage, int remap_special_chars); int CIFSCreateHardLink(const unsigned int xid, diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 8d9f6f28c17e..f12bc0f4d0c1 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -2313,7 +2313,7 @@ int CIFSSMBRename(const unsigned int xid, struct cifs= _tcon *tcon, } =20 int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, - int netfid, const char *target_name, + int netfid, const char *target_name, bool overwrite, const struct nls_table *nls_codepage, int remap) { struct smb_com_transaction2_sfi_req *pSMB =3D NULL; @@ -2353,7 +2353,7 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, str= uct cifs_tcon *pTcon, pSMB->TotalParameterCount =3D pSMB->ParameterCount; pSMB->ParameterOffset =3D cpu_to_le16(param_offset); pSMB->DataOffset =3D cpu_to_le16(offset); - rename_info->overwrite =3D cpu_to_le32(1); + rename_info->overwrite =3D cpu_to_le32(overwrite); rename_info->root_fid =3D 0; /* unicode only call */ len_of_str =3D cifsConvertToUTF16((__le16 *)rename_info->target_name, diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 2889fa6625af..be8e5e5ca6cd 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1793,6 +1793,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, =20 /* rename the file */ rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, + true /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); if (rc !=3D 0) { @@ -1834,6 +1835,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, */ undo_rename: CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name, + true /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); undo_setattr: if (dosattr !=3D origattr) { @@ -2374,6 +2376,7 @@ cifs_do_rename(const unsigned int xid, struct dentry = *from_dentry, if (rc =3D=3D 0) { rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, (const char *) to_dentry->d_name.name, + true /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); CIFSSMBClose(xid, tcon, fid.netfid); } --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 CE876263F54; Sun, 31 Aug 2025 12:36:36 +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=1756643796; cv=none; b=KrKx4Hbcr/bHmR6h5YIF501xIpZo03f1zH0T4inw07gPDEwQZpK7jFmkEJS+lkf+L0N78nRmCg0eMWzDRJNcolW32JPx9xPK3y+mxhRwuUVEtbCuPu1D+Tu7fWBPSBVAslILX9S+YUm3/8n2zoLtbTAeccLPxKBqrc2+FHCl6SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643796; c=relaxed/simple; bh=RS6jv98pnSxASt8tSXB8W9+iiLL49EZrErEKsIhDzvI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hM0gt9IZYy0bsDwlwB/y/FcHrldulBlfsOC3+QrP9byGhu3L55ja+c3LnCFKbNjVxE5qWe3H6CRkOVL1NRvA+yqK70KBKyqdhOMkQ2Mmo5i2T6leh8ooyxg4XjisYWfcjOcTR7i98tV12m5e36S6nWpA9lK7Bqmk2Tl+wRvfbIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LxD166UV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LxD166UV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92775C4CEED; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=RS6jv98pnSxASt8tSXB8W9+iiLL49EZrErEKsIhDzvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LxD166UVZNwifmFSwn5mOgLaEozK1LEW8jt+FwkTEQ5w2gSub7gOw04WXxLRcx0Ul 6Xn3EZkOhRk7ef1U6Glepc05Pdpqwm84TUz9hMLMdIF5q1HiBOn3f7wcbCpP74F5AV hgSnyJN7tnQYmBGb7Eyg69EBF2BoJyk51JaNOjkg1ZT1gNLxC/Ijn8+/u/yT/ch0Xn L2w27I48TlpPKz+yS8TM/NKs21mrrYeFyxW53quLsZGwqy7Yh9Z5SOipPDY1Smokrg JNBpTou7VW68EB+5LqIWzA5Uy1mir0BWtAaGb3qVU0JuMXlt1klCtylzOeYq0DloL2 F/wzC2KpZBy0g== Received: by pali.im (Postfix) id AB4CF14A3; Sun, 31 Aug 2025 14:36:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/35] cifs: Do not try to overwrite existing sillyname in cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:42 +0200 Message-Id: <20250831123602.14037-16-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable If the target location for newly generated sillyname file already exists then do not try to rename file to that new target name. It would either fail (because file is still in use) or it will unexpectedly remove additional file which was not requested. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index be8e5e5ca6cd..89d1b82ac55c 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1793,7 +1793,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, =20 /* rename the file */ rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, - true /* overwrite */, + false /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); if (rc !=3D 0) { --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 F3A5E264636; Sun, 31 Aug 2025 12:36:36 +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=1756643797; cv=none; b=eKaCWfqbn0AHflVuRiIjKTKBeN0YGfsHEI/vEbgHnJPIF1zVFSH7G3SkJtVIEQvAaIjEZBo8L+MhtbA2vozOoGDjTzyzMDdE1TAoXsIbTzp/xskGz+BTn8+X3AGveyOVD88t5nDIzc3bjgS78IJnjrPDBM9IRrQaubJuQ31ygoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=OZ8Nhb8bdpAwvT+5qtyxnSoZYNOZJt10537C8Kt76O0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=lZRy4E+mgbTIWWZDPqWjP44ca49Ewu+EfiIaxPVbnYtpxj3UW20fSt+u/qtNihxhT9N88aq4NKRjVkp2+tyJU5iTNS2N7hscydUu5u6MVkw3g25EpdqnHmvpEGuYvswtJvw+QwO5QD+NDepVMQw7OtlS8qWnMFfkMRF2LtdxdQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZqNXy8IA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZqNXy8IA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7D5AC4CEFB; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=OZ8Nhb8bdpAwvT+5qtyxnSoZYNOZJt10537C8Kt76O0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqNXy8IAgbgNCAOItd6y5Z7Z8P5AF019nyyTE+9Vgecdf/czYUFab4mIUlEnSxC9d JrrBSvunZqsqN0OS8FyT7vkScgWcP9jI+zD17k9TsLAyExp/SW9VSkJyvdIYVvl/aR oJ6rwEwQ+o3w3EJJLKkuwiILMeWH8HARybCz+09ZU6i1qXTpFo+Ov4nchwP5PUzpaZ 2aOzriLfi6MaZwh3YSRL7XRhtpR3dsVSJ3vUclQiZvE++IhIrCwzCtPXXHThJDORfv Odiq6jFcgREWNuynohFvR1B1DOKiiesUuUsixuUbVM9Qz/3zVwGctG+JjvYbc/imFD a/AT3JztUGpjQ== Received: by pali.im (Postfix) id DEF3B1857; Sun, 31 Aug 2025 14:36:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 16/35] cifs: Add comments for DeletePending assignments in open functions Date: Sun, 31 Aug 2025 14:35:43 +0200 Message-Id: <20250831123602.14037-17-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable On more places is set DeletePending member to 0. Add comments why is 0 the correct value. Paths in DELETE_PENDING state cannot be opened by new calls. So if the newly issued open for that path succeed then it means that the path cannot be in DELETE_PENDING state. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 4 ++-- fs/smb/client/smb2inode.c | 2 +- fs/smb/client/smb2pdu.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index f12bc0f4d0c1..6dabff82f6ae 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -1163,7 +1163,7 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tco= n *tcon, cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); pfile_info->EndOfFile =3D pfile_info->AllocationSize; pfile_info->NumberOfLinks =3D cpu_to_le32(1); - pfile_info->DeletePending =3D 0; + pfile_info->DeletePending =3D 0; /* successful open =3D not delete pend= ing */ } } =20 @@ -1288,7 +1288,7 @@ CIFS_open(const unsigned int xid, struct cifs_open_pa= rms *oparms, int *oplock, buf->AllocationSize =3D rsp->AllocationSize; buf->EndOfFile =3D rsp->EndOfFile; buf->NumberOfLinks =3D cpu_to_le32(1); - buf->DeletePending =3D 0; + buf->DeletePending =3D 0; /* successful open =3D not delete pending */ } =20 cifs_buf_release(req); diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 460e75614ef1..6c9da150a402 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -698,7 +698,7 @@ static int smb2_compound_op(const unsigned int xid, str= uct cifs_tcon *tcon, idata->fi.EndOfFile =3D create_rsp->EndofFile; if (le32_to_cpu(idata->fi.NumberOfLinks) =3D=3D 0) idata->fi.NumberOfLinks =3D cpu_to_le32(1); /* dummy value */ - idata->fi.DeletePending =3D 0; + idata->fi.DeletePending =3D 0; /* successful open =3D not delete pending= */ idata->fi.Directory =3D !!(le32_to_cpu(create_rsp->FileAttributes) & ATT= R_DIRECTORY); =20 /* smb2_parse_contexts() fills idata->fi.IndexNumber */ diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 2df93a75e3b8..58800490142e 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3277,7 +3277,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_pa= rms *oparms, __le16 *path, buf->EndOfFile =3D rsp->EndofFile; buf->Attributes =3D rsp->FileAttributes; buf->NumberOfLinks =3D cpu_to_le32(1); - buf->DeletePending =3D 0; + buf->DeletePending =3D 0; /* successful open =3D not delete pending */ } =20 =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 0D83C264A90; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=DL47cUWyQVHOPejqo45nB/bis+WfeKYOIGdVYyBYwPsw928FqT5rk604mHmdza7Ybb1FMRntuL3ePPSBnJQ4hdxZlsxpfc3bc5ZKvIA0Y/FQwX99uwfoMm1JJ3ur7NQmG+D2VB5cXDHOA+8rM7okEpaQO7jxUBj8rvfa8NLrH9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=pjmshuuowk3VsHfdSRy9TJR/wkRXjxdcCJg5ne0gJxY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=pF97BxTJEUNzNCn/t66Ypf3F22bFslmqmQQhzJM7nRUKoYCFB6I2VCUp9/oM+yoIFQ55hSwQQGq2kZZOnUmoJ2/CSQOIPLS8CSCJH8Qh/v7BldTlAB387NJhGfS2FMn5jcCK4MR7mGVPeFniwAni4QHARnu5bclMTguPBrTb5C0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WHRTlVg6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WHRTlVg6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C39DCC4CEF5; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643796; bh=pjmshuuowk3VsHfdSRy9TJR/wkRXjxdcCJg5ne0gJxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHRTlVg6RbMsdGjLyMPFeGaHSsFQu4tqzS6VxSyDbhUzyYut53oq3zMemL5FUdmOz XlCVMEG9Y2TUz1krMrxt2aOwlXoOUEGWf3/e7x0DVoSAcOAZ2oD1dE1C2kUwSylpOa cTPwq9iVFdk98boHbtxFVTA9IWNbahwDMNs2JxUQlaTjfqbwug87BomaiZTcRuk5bC Sh2mjZ3k7nVLf0nF2VOvHoGJEsUTxkg4UoEsoI81JDfZNY+AzwAXaFu1zqxMk63tQE Jpb9J4/fb+JROdIgLhcUIvIPSeQXeSTBRxSegVD+gTJhwiysLJmDPClN0d9M2xGq0y ynUKdAuDwIlDQ== Received: by pali.im (Postfix) id 24DCC198B; Sun, 31 Aug 2025 14:36:34 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/35] cifs: Use NT_STATUS_DELETE_PENDING for filling fi.DeletePending in cifs_query_path_info() Date: Sun, 31 Aug 2025 14:35:44 +0200 Message-Id: <20250831123602.14037-18-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Function CIFSSMBQPathInfo() returns NT_STATUS_DELETE_PENDING status code when the path is in the delete pending state. So use this information when filling the fi.DeletePending member in cifs_query_path_info() function. Depends on "cifs: Change translation of STATUS_DELETE_PENDING to -EBUSY". Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 6 ++++++ fs/smb/client/smb1ops.c | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 6dabff82f6ae..2427752bc224 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -35,6 +35,7 @@ #include "cifs_debug.h" #include "fscache.h" #include "smbdirect.h" +#include "nterr.h" #ifdef CONFIG_CIFS_DFS_UPCALL #include "dfs_cache.h" #endif @@ -3902,6 +3903,11 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs= _tcon *tcon, (struct smb_hdr *) pSMBr, &bytes_returned, 0); if (rc) { cifs_dbg(FYI, "Send error in QPathInfo =3D %d\n", rc); + /* Fill at least the DeletePending for -EBUSY error code */ + if (rc =3D=3D -EBUSY && data) + data->DeletePending =3D + (pSMBr->hdr.Flags2 & SMBFLG2_ERR_STATUS) && + pSMBr->hdr.Status.CifsError =3D=3D cpu_to_le32(NT_STATUS_DELETE_PENDI= NG); } else { /* decode response */ rc =3D validate_t2((struct smb_t2_rsp *)pSMBr); =20 diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 176bc2a211bf..618470db6444 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -628,7 +628,11 @@ static int cifs_query_path_info(const unsigned int xid, fi.EASize =3D di->EaSize; } fi.NumberOfLinks =3D cpu_to_le32(1); - fi.DeletePending =3D 0; + /* + * Do not change fi.DeletePending as it is set by the above + * CIFSSMBQPathInfo() call even on error. By default it is + * initialized to zero (false). + */ fi.Directory =3D !!(le32_to_cpu(fi.Attributes) & ATTR_DIRECTORY); cifs_buf_release(search_info.ntwrk_buf_start); } else if (!full_path[0]) { --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 423BA2652AF; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=paRCiRc8FZBK5WTp5DRLTu07+6SBbIa80e4Q1kxsPik1JL1Q/I0hmuGXMw9XjbHHJZaFzklfHN5umbIiYiQyGRWtTkGAmyBo0N4VXgy93yAVEahbAV6df/ajWeUBvRkyBiy3KP9qKvYynLLbWLIvI+eVAn9yUD6fXryJKKL0u2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=xd3znamZi+4zYsYbHX3omonDAZMvYkQtdUQTv4wYa5U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=q2fFQ8ma1EC0Yq7yrAiD2XK8nP0X56U8FjoQ1QN9/NufFa6w1aKrJLJWWvNOnY7OLfU04Iok9mYoIpBFaD1E6uRJGv4nAa+S+NTxXVx2XevhL2tRVt4KDo1SrP3ZzRkTmXmyOWXODq5co6GNYZE7fGfAQ75HG/cGdwJ7PZyjTBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X29NLIZp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X29NLIZp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6FA4C4CEF9; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=xd3znamZi+4zYsYbHX3omonDAZMvYkQtdUQTv4wYa5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X29NLIZpfgWjbFgEww9UZkc6i1Nt325WX1y9mdjRr4ZySILP9tqPp70gHsVuIjFbd Yh6vxXWpt09D7t17nZaU9vhQ+bpwqt6Oslg6kpcS+tTVybuHIpCmgbEFu8c9rwpeO0 eva41iTkIZcHlgVx3rWQ7/vulzx2cjf8fXm2fRqE4g0y/BeN8K2fUQ+8NAqA89erdD kJfXg1XV30dJ9KMOshIZ215Cg0WN2I+yys2hv/FAj6C+GB9YSWbLZkYaNwAPYzwV5Z cyxmV6Ev9LbG5GLiWsP1CNoeXa9U01klkY8dvoexzh4nsf2zn53Pf56nqDYi6YsN0r r+z7EvlmJHCZQ== Received: by pali.im (Postfix) id 555A91ADF; Sun, 31 Aug 2025 14:36:34 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 18/35] cifs: Do not set NumberOfLinks to 1 from open or query calls Date: Sun, 31 Aug 2025 14:35:45 +0200 Message-Id: <20250831123602.14037-19-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Current code already interprets zero value as unknown number of links and sets the CIFS_FATTR_UNKNOWN_NLINK flag to handle this situation. Setting NumberOfLinks to 1 prevents the CIFS_FATTR_UNKNOWN_NLINK indicator. So set the NumberOfLinks to 0 when it is unknown. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 4 ++-- fs/smb/client/smb1ops.c | 2 +- fs/smb/client/smb2inode.c | 6 ++++-- fs/smb/client/smb2pdu.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 2427752bc224..2a83fbc65395 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -1163,7 +1163,7 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tco= n *tcon, pfile_info->AllocationSize =3D cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); pfile_info->EndOfFile =3D pfile_info->AllocationSize; - pfile_info->NumberOfLinks =3D cpu_to_le32(1); + pfile_info->NumberOfLinks =3D cpu_to_le32(0); /* CIFS_FATTR_UNKNOWN_NLI= NK */ pfile_info->DeletePending =3D 0; /* successful open =3D not delete pend= ing */ } } @@ -1288,7 +1288,7 @@ CIFS_open(const unsigned int xid, struct cifs_open_pa= rms *oparms, int *oplock, /* the file_info buf is endian converted by caller */ buf->AllocationSize =3D rsp->AllocationSize; buf->EndOfFile =3D rsp->EndOfFile; - buf->NumberOfLinks =3D cpu_to_le32(1); + buf->NumberOfLinks =3D cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLI= NK */ buf->DeletePending =3D 0; /* successful open =3D not delete pending */ } =20 diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 618470db6444..6e928e90d72b 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -627,7 +627,7 @@ static int cifs_query_path_info(const unsigned int xid, fi.EndOfFile =3D di->EndOfFile; fi.EASize =3D di->EaSize; } - fi.NumberOfLinks =3D cpu_to_le32(1); + fi.NumberOfLinks =3D cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLIN= K */ /* * Do not change fi.DeletePending as it is set by the above * CIFSSMBQPathInfo() call even on error. By default it is diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 6c9da150a402..c8b0e9b2438f 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -696,8 +696,10 @@ static int smb2_compound_op(const unsigned int xid, st= ruct cifs_tcon *tcon, idata->fi.Attributes =3D create_rsp->FileAttributes; idata->fi.AllocationSize =3D create_rsp->AllocationSize; idata->fi.EndOfFile =3D create_rsp->EndofFile; - if (le32_to_cpu(idata->fi.NumberOfLinks) =3D=3D 0) - idata->fi.NumberOfLinks =3D cpu_to_le32(1); /* dummy value */ + /* + * Do not change idata->fi.NumberOfLinks to correctly + * trigger the CIFS_FATTR_UNKNOWN_NLINK flag. + */ idata->fi.DeletePending =3D 0; /* successful open =3D not delete pending= */ idata->fi.Directory =3D !!(le32_to_cpu(create_rsp->FileAttributes) & ATT= R_DIRECTORY); =20 diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 58800490142e..bf588ec99618 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3276,7 +3276,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_pa= rms *oparms, __le16 *path, buf->AllocationSize =3D rsp->AllocationSize; buf->EndOfFile =3D rsp->EndofFile; buf->Attributes =3D rsp->FileAttributes; - buf->NumberOfLinks =3D cpu_to_le32(1); + buf->NumberOfLinks =3D cpu_to_le32(0); /* trigger CIFS_FATTR_UNKNOWN_NLI= NK */ buf->DeletePending =3D 0; /* successful open =3D not delete pending */ } =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 23ECB264FB5; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=bAupcNegsIzpNgp1a0mkGKZIoct9qo6049XnehgOIyz1Pmq+cMLlrPaEUuR+cTd8AEPydJ2KdIN2KajVR6JpyfLMs8eAqoWFhAOx4KwPeyeZf5bhlPFvCe8RuvWIY6gf9GHjBXXSK4FSr1MXzzA3WyQNE0s4r0IVm6OrUpiXdZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=GCZSbjBPCLF1eAXCX5z+2NAiYG122Va1HFGU46nBOyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kwGCObK6MJVKLquCVdxqLviom85WRQGTA1vZujiIGl+nn14eD/4FA6MX8YwuNt1+uDycXVpw5gmV1Lcvl2OT+Dq9MTqBy0wHMp/yz3DREaN0Jenax4NRD+ENX1Pk0LGwgrQRP/vognl3nqnVf0N1q0VcUMPOc15Gz3Nt8NssKlw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nd/9gMtz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nd/9gMtz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCF45C4CEF8; Sun, 31 Aug 2025 12:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=GCZSbjBPCLF1eAXCX5z+2NAiYG122Va1HFGU46nBOyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nd/9gMtzXUChoUlZ8aMj9gHuQEAKqh6xeyjMhoSIReml7H3vQE9+s3TgjhgOU9uc3 xaktQRdB2t0rMP89zUgej/u2CEwpIX4hk6gYfpQiRhtRj0Ntx3dZtN9c9+HqLTeAro 20fq39gIf9qL2n0BoLMI0R3zaQR19xpcfE4g8mUEr94nYmkt9LWIWAg7V6fOdloupO JFH++EPP+qc2KSOWFiIG4EOBUgHtOv3sgu/HgTN1d5rOYWi0rP5ukt59Hh+v8SOKy8 gK1DAxblWz3aq5zXVgafuGz87kIOTK9pA6a3nCEEQTE41bL9QSM5srO4uC/GDSk2H2 AM15ULWp6y64w== Received: by pali.im (Postfix) id 7AA991B0A; Sun, 31 Aug 2025 14:36:34 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 19/35] cifs: Fix cifs_rename_pending_delete() for files with more hardlinks Date: Sun, 31 Aug 2025 14:35:46 +0200 Message-Id: <20250831123602.14037-20-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Do not set ATTR_HIDDEN when the file has more links. These attributes are shared across all links, they are not direntry specific. So changing attribute on one hardlink affects all other hardlinks. The cifs_rename_pending_delete() function called from unlink() should affect only the path passed to unlink(), and not other links. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 89d1b82ac55c..4658af632098 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1769,16 +1769,26 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, if (rc !=3D 0) goto out; =20 - origattr =3D cifsInode->cifsAttrs; - if (origattr =3D=3D 0) - origattr |=3D ATTR_NORMAL; + origattr =3D cifsInode->cifsAttrs & ~ATTR_NORMAL; =20 + /* clear ATTR_READONLY, needed for opening file with DELETE access */ dosattr =3D origattr & ~ATTR_READONLY; + + /* + * Set ATTR_HIDDEN to hide the file, but only if this is not a hardlink + * because all hardlinked directory entries shares same attribues and + * we do not want to mark all hardlinked entries as hidden. + */ + if (inode->i_nlink <=3D 1) + dosattr |=3D ATTR_HIDDEN; + + /* clearing all attributes is done via ATTR_NORMAL value */ + if (origattr =3D=3D 0) + origattr |=3D ATTR_NORMAL; if (dosattr =3D=3D 0) dosattr |=3D ATTR_NORMAL; - dosattr |=3D ATTR_HIDDEN; =20 - /* set ATTR_HIDDEN and clear ATTR_READONLY, but only if needed */ + /* change dosattr, but only if needed */ if (dosattr !=3D origattr) { info_buf.Attributes =3D cpu_to_le32(dosattr); rc =3D CIFSSMBSetFileInfo(xid, tcon, &info_buf, fid.netfid, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 D44D42673B7; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=o+qgn0j2J1eBlgpiK9TrNX8mYtHGsguMjZ61OaSsqtrpQOLq9QBx7t0EKCiOmuyzTM+jZcnEVzvVNMe1SxiFre6nf2coRkuxfcv8PoMAjmhf1cb4EQ/Q69dF7MU0jcxzPGNNS30jzcyosnnYE3L9L6K95w8rLdRWrmRXKV8SyYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=hHR1lBd0YmwQFz+umy/fyXgJon1sazFIo4kz+GMPEtU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=YmkECSTNcENe5hnZRYkKZlrxjj/RzBtRIIWYzbToJ/WjoMOjar4gDa5BejOcAI1bg93osNOwtxrl3CVEEuJWHbRMQcaQ8fFvV7Ralh0GNfeEk03NzD41oHrw/X70e+iYfmDC0OlqQI35i3PBIpkb0a9oEbFLxiwTPWJOBKOjla4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GI42Y+PY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GI42Y+PY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A3E7C4CEFA; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=hHR1lBd0YmwQFz+umy/fyXgJon1sazFIo4kz+GMPEtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GI42Y+PYTTF6IGM9uWZshIx1D2yGzdxMjG19EtlYquRDH+oLmAxUwMDYKWEbEOrTO NBowRRungnBzbbdix99rwkIo9i7Y2av1oTKb9suyS70owAjysRciBxIBdW4DTKIQwI vzDUcplIAhPcQ60hOmjkjDGDDuFKfuIB2PtPpdZ78xaD6u7UJHbrdFq5Y1pXq7ZaTr caI3iEl/Hot+x67yS7hfq0ArdBJb/WZq4WPDWcOOx1qn0+CiDhJBz8TT1E2ONumPEC 4JjMkIO3z8ikNXStXh20Y0VVyBUG5DG6mcCQ3EH2CunESUnpM/zV6SyCNk92Ff17zA hdhOtWBTv4qvg== Received: by pali.im (Postfix) id A5B071B0B; Sun, 31 Aug 2025 14:36:34 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 20/35] cifs: Fix permission logic in cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:47 +0200 Message-Id: <20250831123602.14037-21-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Opening file with DELETE access does not have to be allowed by server for file with ATTR_READONLY attribute set. So the current logic for clearing the ATTR_READONLY attribute in cifs_rename_pending_delete() can fail as it tries to open file with access mask DELETE | FILE_WRITE_ATTRIBUTES. Fix the permission logic. First clear the ATTR_READONLY attribute and then the open file with DELETE access. As for the RENAME and SET_DELETE_PENDING operations is not required the FILE_WRITE_ATTRIBUTES access, do not pass it into open. This allows to call cifs_rename_pending_delete() also on the files with ACL permissions which disallows file modification. For changing attributes use the set_file_info() callback function which already handles the situation when the caller wants to clear the ATTR_READONLY flag. Note that the set_file_info() callback also updates the cifsInode->cifsAttrs member, so remove explicit assignment here. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 48 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 4658af632098..63ab233517f2 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1755,20 +1755,6 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, goto out; } =20 - oparms =3D (struct cifs_open_parms) { - .tcon =3D tcon, - .cifs_sb =3D cifs_sb, - .desired_access =3D DELETE | FILE_WRITE_ATTRIBUTES, - .create_options =3D cifs_create_options(cifs_sb, CREATE_NOT_DIR), - .disposition =3D FILE_OPEN, - .path =3D full_path, - .fid =3D &fid, - }; - - rc =3D CIFS_open(xid, &oparms, &oplock, NULL); - if (rc !=3D 0) - goto out; - origattr =3D cifsInode->cifsAttrs & ~ATTR_NORMAL; =20 /* clear ATTR_READONLY, needed for opening file with DELETE access */ @@ -1791,16 +1777,27 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, /* change dosattr, but only if needed */ if (dosattr !=3D origattr) { info_buf.Attributes =3D cpu_to_le32(dosattr); - rc =3D CIFSSMBSetFileInfo(xid, tcon, &info_buf, fid.netfid, - current->tgid); + rc =3D tcon->ses->server->ops->set_file_info(inode, full_path, &info_buf= , xid); /* although we would like to mark the file hidden if that fails we will still try to rename it */ - if (!rc) - cifsInode->cifsAttrs =3D dosattr; - else + if (rc) dosattr =3D origattr; /* since not able to change them */ } =20 + oparms =3D (struct cifs_open_parms) { + .tcon =3D tcon, + .cifs_sb =3D cifs_sb, + .desired_access =3D DELETE, + .create_options =3D cifs_create_options(cifs_sb, CREATE_NOT_DIR), + .disposition =3D FILE_OPEN, + .path =3D full_path, + .fid =3D &fid, + }; + + rc =3D CIFS_open(xid, &oparms, &oplock, NULL); + if (rc !=3D 0) + goto undo_setattr; + /* rename the file */ rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, false /* overwrite */, @@ -1808,7 +1805,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, cifs_remap(cifs_sb)); if (rc !=3D 0) { rc =3D -EBUSY; - goto undo_setattr; + goto undo_close; } =20 /* try to set DELETE_PENDING */ @@ -1832,8 +1829,8 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, set_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags); } =20 -out_close: CIFSSMBClose(xid, tcon, fid.netfid); + out: cifs_put_tlink(tlink); return rc; @@ -1847,15 +1844,14 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name, true /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); +undo_close: + CIFSSMBClose(xid, tcon, fid.netfid); undo_setattr: if (dosattr !=3D origattr) { info_buf.Attributes =3D cpu_to_le32(origattr); - if (!CIFSSMBSetFileInfo(xid, tcon, &info_buf, fid.netfid, - current->tgid)) - cifsInode->cifsAttrs =3D origattr; + tcon->ses->server->ops->set_file_info(inode, full_path, &info_buf, xid); } - - goto out_close; + goto out; } #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 31BCD26CE10; Sun, 31 Aug 2025 12:36:39 +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=1756643799; cv=none; b=qNPs2h73ica405aMSgnnv0lnoxUG4rqPYI+duep5Z4/I0fCTFhDtOnhQrKITrBHxrDSco/IQG9EbEyDzX6FKq0dPS5NZH8vpXhsfKmDW2if9RZ/hwpQIfliQxKl+/60R7z6EO8HKCrFj6YuRHPoFL4Lm506JWnVQ8iZOmjxGf24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643799; c=relaxed/simple; bh=YrTaPphT5xReaVE8kxQXjKTYVGCfayvzY3KlTdv2IHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MqB/RBSlgZI+2wNe+jnYaSUo8dMxx+QDxl+zStnOLQk8OnIzAuxhnCCjeUZh/WWTZxSdhcMfQdrnB1PE7Xl8Y8gD4ZwNY8h1cRQ+HTjzPkLllha+V0KipIK/uf3enDmgO6uy4+x6/B5veV+FkrJVnlb/9XJDLbQmypTy3uPJQ1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p6x9YeaW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p6x9YeaW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5FE9C4CEF5; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643799; bh=YrTaPphT5xReaVE8kxQXjKTYVGCfayvzY3KlTdv2IHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p6x9YeaW/zV80Ir81y5JZ1Ky2z8zgJyRNR1fV990lpQ2820WC8kzFKyioneXoeEo7 R+2w5bqLvKih3rPPiNhqSPk2LeKeIxlWrw2x/g3x8j9ETv/thUgDiMPGrWibNpT3ni Lmy+W8tCpbaEcH9aYCbCW+1djxGFKZ+QDClVqDrvYlJcytcyv7OdFCayOHT4yIsKfP vvcaMwxeoLdTq0Av63ccDZthE549jYBFafo/1rs0ZAZ112MAM6SMAh/te7xjCi9PaN QqMQqBNdO2hNR/VirnLwTEv7rqmn6j7jAiCap7E/15KyG8hl67VgS+Fkx1YsmJeTmi P+znM+o8YIfvA== Received: by pali.im (Postfix) id D6523D58; Sun, 31 Aug 2025 14:36:34 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 21/35] cifs: Propagate error code from CIFSSMBSetFileInfo() to cifs_rename_pending_delete() Date: Sun, 31 Aug 2025 14:35:48 +0200 Message-Id: <20250831123602.14037-22-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Function CIFSSMBSetFileInfo() setting the file to the delete pending state, the core part of the cifs_rename_pending_delete() functionality. So do not mask error code from CIFSSMBSetFileInfo() function and properly propagate it to the caller of cifs_rename_pending_delete(). Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 63ab233517f2..b0526787138d 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1822,10 +1822,8 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, */ if (rc =3D=3D -ENOENT) rc =3D 0; - else if (rc !=3D 0) { - rc =3D -EBUSY; + else if (rc !=3D 0) goto undo_rename; - } set_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags); } =20 --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 C2C49267386; Sun, 31 Aug 2025 12:36:37 +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=1756643797; cv=none; b=eq0RwkEdAIGHRe2q6+6E7GPhOWzwynWcAdMN8MqcqoThv40P8ProD+ypIy9NTLngOKjvARoWYUcy2UtndKVPlB5oNefBFV5VfHRgaOQMgBMcdsFUUaRnKsoyKlta6GXNQLw/TVEAoZdoWNo+dduT7/XJr000+zLOSZaGLvpG1Vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643797; c=relaxed/simple; bh=jS3iUQivvb7RhPhXLqpAYxJyCsCjn5OHdf4ysw4mfY4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=HRJgn7S7niapt9VoEIvfoUiTf+orHZqJAl8uCClzDJnqk6AKG6FOibXPeNlh7jt4p2KWIzlSyy8F6QVV+yVY5wlq8MAsDqSkAZ0uCtmx91KUSDHOrQbuP4zMiEy8Cg7qaX5K3z31UJBAU/yc7Io5D2W4NfHcERGqEwF/a/PEGgI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WvPEG5sy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WvPEG5sy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DDBAC4CEED; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=jS3iUQivvb7RhPhXLqpAYxJyCsCjn5OHdf4ysw4mfY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvPEG5syvUXoLTUgCcpHdsg/AZpLl+V9iXVuoX4d5laUEg3Hz3AaXYR2ZvaXVl5kT Q7Mmm+/yjCCggf80fQ7onDQGFu8Z75o8/xvMJpkzXhSWR1L4Cpab3WYVmcMcIJYdD6 +9e/rF+ZHc1IDfA/yZjEZ0ElfiaPGoKotBeGnm/lJ4lRM2bGFBjD9V+ekeGmaSxI9f nB5+1h2O88A2Y5BdwD2SlqcOnIaNn0DysitPVftDEj0BQxanCV0cu2COqXf/zgxhTd PQ76EEHp+i9+OUUt92bHj7Hl5XjodcbjILxzPaB5TS7L9v/32RC+UP0hU93tWhw5aY AVorBa9V5P0bA== Received: by pali.im (Postfix) id 21B10598; Sun, 31 Aug 2025 14:36:35 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 22/35] cifs: Improve cifs_rename_pending_delete() to work without the PASSTHRU support Date: Sun, 31 Aug 2025 14:35:49 +0200 Message-Id: <20250831123602.14037-23-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable If PASSTHRU support is not supported by SMB server (which is currently required for renaming the opened file) then rename the file via path before opening it. This does not require PASSTHRU support on SMB server. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 63 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index b0526787138d..9a5504a3406d 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1711,9 +1711,13 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, struct tcon_link *tlink; struct cifs_tcon *tcon; __u32 dosattr, origattr; + char *sillyname_full_path =3D NULL; + bool can_rename_opened_file =3D true; FILE_BASIC_INFO info_buf =3D {}; unsigned char sillyname[SILLYNAME_LEN + 1]; int sillyname_len; + const char *dirpath_end; + size_t dirpath_len; =20 tlink =3D cifs_sb_tlink(cifs_sb); if (IS_ERR(tlink)) @@ -1747,13 +1751,26 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, } =20 /* - * We cannot rename the file if the server doesn't support - * CAP_INFOLEVEL_PASSTHRU + * We cannot rename the opened file if the SMB1 server doesn't + * support CAP_INFOLEVEL_PASSTHRU. But we can rename file via path. */ - if (!(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)) { - rc =3D -EBUSY; + if (!(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)) + can_rename_opened_file =3D false; + + dirpath_end =3D strrchr(full_path, CIFS_DIR_SEP(cifs_sb)); + if (!dirpath_end) { + rc =3D -EINVAL; + goto out; + } + dirpath_len =3D dirpath_end + 1 - full_path; + + sillyname_full_path =3D kzalloc(dirpath_len + sillyname_len + 1, GFP_KERN= EL); + if (!sillyname_full_path) { + rc =3D -ENOMEM; goto out; } + memcpy(sillyname_full_path, full_path, dirpath_len); + memcpy(sillyname_full_path + dirpath_len, sillyname, sillyname_len); =20 origattr =3D cifsInode->cifsAttrs & ~ATTR_NORMAL; =20 @@ -1784,6 +1801,16 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, dosattr =3D origattr; /* since not able to change them */ } =20 + /* rename the file path (before open if server does not support renaming = opened file) */ + if (!can_rename_opened_file) { + rc =3D tcon->ses->server->ops->rename(xid, tcon, dentry, full_path, + sillyname_full_path, cifs_sb); + if (rc !=3D 0) { + rc =3D -EBUSY; + goto undo_setattr; + } + } + oparms =3D (struct cifs_open_parms) { .tcon =3D tcon, .cifs_sb =3D cifs_sb, @@ -1796,16 +1823,18 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, =20 rc =3D CIFS_open(xid, &oparms, &oplock, NULL); if (rc !=3D 0) - goto undo_setattr; + goto undo_rename_path; =20 - /* rename the file */ - rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, + /* rename the opened file (if it was not already renamed before the open)= */ + if (can_rename_opened_file) { + rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, false /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); - if (rc !=3D 0) { - rc =3D -EBUSY; - goto undo_close; + if (rc !=3D 0) { + rc =3D -EBUSY; + goto undo_close; + } } =20 /* try to set DELETE_PENDING */ @@ -1823,13 +1852,14 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, if (rc =3D=3D -ENOENT) rc =3D 0; else if (rc !=3D 0) - goto undo_rename; + goto undo_rename_opened_file; set_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags); } =20 CIFSSMBClose(xid, tcon, fid.netfid); =20 out: + kfree(sillyname_full_path); cifs_put_tlink(tlink); return rc; =20 @@ -1838,12 +1868,19 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, * dealing with errors here since we can't do anything about * them anyway. */ -undo_rename: - CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name, +undo_rename_opened_file: + if (can_rename_opened_file) + CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name, true /* overwrite */, cifs_sb->local_nls, cifs_remap(cifs_sb)); undo_close: CIFSSMBClose(xid, tcon, fid.netfid); +undo_rename_path: + if (!can_rename_opened_file) + CIFSSMBRename(xid, tcon, dentry, + sillyname_full_path, + full_path, + cifs_sb); undo_setattr: if (dosattr !=3D origattr) { info_buf.Attributes =3D cpu_to_le32(origattr); --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 0F793268690; Sun, 31 Aug 2025 12:36:37 +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=1756643798; cv=none; b=sNX/6Sn2085SLT5C2/XWtiPbvdxJHb46TI3Bqz3rrUq2UqlAO+sKUgATaJhUHQw83DoOIWYXeK/ib//2vbybcbdHv2K0y4sdIoyhPmETsTilrth2nOPcf/2456SFGZ67rdmcuMO7yAqJWdkw6SIp+miKFuTXoY1CtIGUiE1C6pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=ZLF42ulSn4oztGUtexC/05mImgiTglF5VFIenWM/R94=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=JZomm0YJaPNeuQ0apHk9+ZEvZ4Ynomq9A8C4Nvk0Dh5vSJCP/HepB1JffeNMUTE5L5lQ2cSvjWeHzMrDEuy39BOaTWQYCJwNB3ugrqRbeamMWVyF5mcvP9uVsvV0RvdYyilwmHk9peH1yP51ynp24PO3n1DI356wFC3U7fG/sd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HmlH9VDO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HmlH9VDO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A941C4CEF5; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=ZLF42ulSn4oztGUtexC/05mImgiTglF5VFIenWM/R94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmlH9VDOPQw2LRQdaradMDTvNfbtjZgl7WPT9jqHmNs3QnIPjv1sdbX6rUHmf401c eot98YGuza9eDBYSAL4QVUQT2UqaUdUE3XuO8RtoxAdRhb6GH9GxF5gLMlw2RBtgxl c/DNIj4qf37pkfsVujA4OdnDZV6iuyXm49ZzW3sujfzTxtzrCOeMZjTPsm76Nq2fhr WzJbR/yatBZQMDRbMkQvL5QZ6l39xeApyNCrWr0hr3WfZt9ATzgeCd6n+/Q7XykENQ j+ozLlQqTZHkd6BO+MODWIPzN5aJ9fQV5NiBcNPmiTN41nDyW2wQEv3+Lji+tYRPd5 F4MDfgi8Tu9LA== Received: by pali.im (Postfix) id 64455D70; Sun, 31 Aug 2025 14:36:35 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 23/35] cifs: Fix SMBLegacyOpen() function Date: Sun, 31 Aug 2025 14:35:50 +0200 Message-Id: <20250831123602.14037-24-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Function SMBLegacyOpen() contains many FIXME comments, commented code and missing handling of different flags. Fix the FIXME comments, add missing handling of different flags and use named macros as constants instead of magic numbers. This is done according to MS-CIFS spec. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifspdu.h | 4 +++ fs/smb/client/cifssmb.c | 73 +++++++++++++++++++++++++++-------------- fs/smb/client/smb1ops.c | 4 ++- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index d9cf7db0ac35..cb1f99d22dd7 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -137,6 +137,10 @@ * Flags on SMB open */ #define SMBOPEN_WRITE_THROUGH 0x4000 +#define SMBOPEN_DO_NOT_CACHE 0x1000 +#define SMBOPEN_RANDOM_ACCESS 0x0200 +#define SMBOPEN_SEQUENTIAL 0x0100 +#define SMBOPEN_DENY_COMPAT 0x0000 #define SMBOPEN_DENY_ALL 0x0010 #define SMBOPEN_DENY_WRITE 0x0020 #define SMBOPEN_DENY_READ 0x0030 diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 2a83fbc65395..c09713ebdc7c 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -1103,32 +1103,41 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_t= con *tcon, count =3D 0; /* no pad */ name_len =3D copy_path_name(pSMB->fileName, fileName); } - if (*pOplock & REQ_OPLOCK) - pSMB->OpenFlags =3D cpu_to_le16(REQ_OPLOCK); - else if (*pOplock & REQ_BATCHOPLOCK) + + if (*pOplock & REQ_BATCHOPLOCK) pSMB->OpenFlags =3D cpu_to_le16(REQ_BATCHOPLOCK); + else if (*pOplock & REQ_OPLOCK) + pSMB->OpenFlags =3D cpu_to_le16(REQ_OPLOCK); + + if (pfile_info) + pSMB->OpenFlags |=3D cpu_to_le16(REQ_MORE_INFO); =20 - pSMB->OpenFlags |=3D cpu_to_le16(REQ_MORE_INFO); pSMB->Mode =3D cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); - pSMB->Mode |=3D cpu_to_le16(0x40); /* deny none */ + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_DENY_NONE); + + if (create_options & CREATE_WRITE_THROUGH) + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_WRITE_THROUGH); + + if (create_options & CREATE_NO_BUFFER) + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_DO_NOT_CACHE); + + if (create_options & CREATE_RANDOM_ACCESS) + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_RANDOM_ACCESS); + else if (create_options & CREATE_SEQUENTIAL) + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_SEQUENTIAL); + /* set file as system file if special file such as fifo, * socket, char or block and server expecting SFU style and no Unix extensions */ - if (create_options & CREATE_OPTION_SPECIAL) pSMB->FileAttributes =3D cpu_to_le16(ATTR_SYSTEM); - else /* BB FIXME BB */ - pSMB->FileAttributes =3D cpu_to_le16(0/*ATTR_NORMAL*/); + else + pSMB->FileAttributes =3D cpu_to_le16(0); =20 if (create_options & CREATE_OPTION_READONLY) pSMB->FileAttributes |=3D cpu_to_le16(ATTR_READONLY); =20 - /* BB FIXME BB */ -/* pSMB->CreateOptions =3D cpu_to_le32(create_options & - CREATE_OPTIONS_MASK); */ - /* BB FIXME END BB */ - - pSMB->Sattr =3D cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); + pSMB->Sattr =3D cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | A= TTR_ARCHIVE); pSMB->OpenFunction =3D cpu_to_le16(convert_disposition(openDisposition)); count +=3D name_len; inc_rfc1001_len(pSMB, count); @@ -1139,24 +1148,38 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_t= con *tcon, cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); if (rc) { cifs_dbg(FYI, "Error in Open =3D %d\n", rc); + } else if (pSMBr->hdr.WordCount !=3D 15) { + rc =3D -EIO; } else { - /* BB verify if wct =3D=3D 15 */ - -/* *pOplock =3D pSMBr->OplockLevel; */ /* BB take from action field*/ + if (!(pSMBr->Action & 0x8000)) + *pOplock =3D OPLOCK_NONE; + else if (*pOplock & REQ_BATCHOPLOCK) + *pOplock =3D OPLOCK_BATCH; + else if (*pOplock & REQ_OPLOCK) + *pOplock =3D OPLOCK_EXCLUSIVE; + else + *pOplock =3D OPLOCK_NONE; =20 *netfid =3D pSMBr->Fid; /* cifs fid stays in le */ + /* Let caller know file was created so we can set the mode. */ /* Do we care about the CreateAction in any other cases? */ - /* BB FIXME BB */ -/* if (cpu_to_le32(FILE_CREATE) =3D=3D pSMBr->CreateAction) - *pOplock |=3D CIFS_CREATE_ACTION; */ - /* BB FIXME END */ + if ((pSMBr->Action & 0x0003) =3D=3D 2) + *pOplock |=3D CIFS_CREATE_ACTION; =20 if (pfile_info) { - pfile_info->CreationTime =3D 0; /* BB convert CreateTime*/ - pfile_info->LastAccessTime =3D 0; /* BB fixme */ - pfile_info->LastWriteTime =3D 0; /* BB fixme */ - pfile_info->ChangeTime =3D 0; /* BB fixme */ + struct timespec64 ts; + __u32 time =3D le32_to_cpu(pSMBr->LastWriteTime); + + ts.tv_nsec =3D 0; + ts.tv_sec =3D time; + pfile_info->LastWriteTime =3D cpu_to_le64(cifs_UnixTimeToNT(ts)); + pfile_info->ChangeTime =3D pfile_info->LastWriteTime; + if (*pOplock & CIFS_CREATE_ACTION) + pfile_info->CreationTime =3D pfile_info->LastWriteTime; + else + pfile_info->CreationTime =3D 0; + pfile_info->LastAccessTime =3D 0; pfile_info->Attributes =3D cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); /* the file_info buf is endian converted by caller */ diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 6e928e90d72b..73d3dc83faa6 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -853,7 +853,9 @@ static int cifs_open_file(const unsigned int xid, struc= t cifs_open_parms *oparms oparms->disposition, oparms->desired_access, oparms->create_options, - &oparms->fid->netfid, oplock, &fi, + &oparms->fid->netfid, + oplock, + data ? &fi : NULL, oparms->cifs_sb->local_nls, cifs_remap(oparms->cifs_sb)); else --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 0F72D268688; Sun, 31 Aug 2025 12:36:37 +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=1756643798; cv=none; b=llH+E+Q2NXdSi9/TPYWIR3+mbpciKesDONQbpxHiGGn4ZykjT8HJnnTO9qOUeO8IRNHBQq9caDvimuxYGwScWm15tkiyZtKXWIaNlRiWId4b1kx4WxgKgID5SJiMlOuNpQgS/r4OKCSqqYf2PrZGuB5X4L0AajazwK8sigutnTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=u6ubCb8TEYt3r5vCDGsHNbkpi+oiKBa5gvpt/OaLiso=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=gPlwP+vK5a3zV7/sfXCGXl649rx+drvWNiGjHtFf6mQXX7kiJEQ49TiYLsfSxCi6+B210YcpwJhfpbGqgcHlIYlAGdRrSVdYCbZlYnRPgysCby9egdjs3CazrUxpqcF4fSV83HIm7j4CRn94uuFiCsHQM5EyfhvxDYCCjQA3ayk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nbiD4uh0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nbiD4uh0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75AC1C4CEF9; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=u6ubCb8TEYt3r5vCDGsHNbkpi+oiKBa5gvpt/OaLiso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nbiD4uh0QubSjtDpH2opUr65y70y8EAwcNgKyaN2NIs9UXBsvb3h5dqHFjMur9+NQ uJXzMWLdzRu/ho9x6UUfsUFf1e+K9HOC6pdpivIk1eTnWp2TcR0kbcZPQKg2iUb1Fd F2hKpUNZeUtohBkO7m8AoZLWMkQ3Hvkv/qX1eV44NH7EUWl7Eis4dTVHPdRR19MAfC uuYcNIKDcgcIEXA6TZaMevR+C6TZz7hcd/Y2r/fPi3acmu57f+b1wBOjDCspGLcBTU lUunEj4E7gu2H8lGh+ZBU+cQvYi+JmC7Tc9MpnLN8QDY8zHUvKpUMLNz0Hif1ZE1ZN zTIOV4Bk5POig== Received: by pali.im (Postfix) id 9B37CF96; Sun, 31 Aug 2025 14:36:35 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/35] cifs: Add a new callback set_file_disp() for setting file disposition (delete pending state) Date: Sun, 31 Aug 2025 14:35:51 +0200 Message-Id: <20250831123602.14037-25-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Implement it for all SMB dialects. It will be used by follow up changes. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsglob.h | 3 +++ fs/smb/client/smb1ops.c | 8 ++++++++ fs/smb/client/smb2ops.c | 11 +++++++++++ fs/smb/client/smb2pdu.c | 13 +++++++++++++ fs/smb/client/smb2proto.h | 2 ++ 5 files changed, 37 insertions(+) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 0ecf4988664e..7162b9120198 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -426,6 +426,9 @@ struct smb_version_operations { /* set attributes */ int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *, const unsigned int); + /* set file disposition (delete pending state) */ + int (*set_file_disp)(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, bool delete_pending); int (*set_compression)(const unsigned int, struct cifs_tcon *, struct cifsFileInfo *); /* check if we can send an echo or nor */ diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 73d3dc83faa6..e37104d3c5d7 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -1079,6 +1079,13 @@ smb_set_file_info(struct inode *inode, const char *f= ull_path, return rc; } =20 +static int +cifs_set_file_disp(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, bool delete_pending) +{ + return CIFSSMBSetFileDisposition(xid, tcon, delete_pending, fid->netfid, = current->tgid); +} + static int cifs_set_compression(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile) @@ -1391,6 +1398,7 @@ struct smb_version_operations smb1_operations =3D { .set_path_size =3D CIFSSMBSetEOF, .set_file_size =3D CIFSSMBSetFileSize, .set_file_info =3D smb_set_file_info, + .set_file_disp =3D cifs_set_file_disp, .set_compression =3D cifs_set_compression, .echo =3D CIFSSMBEcho, .mkdir =3D CIFSSMBMkDir, diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index ad8947434b71..530e66fa4671 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -1515,6 +1515,13 @@ smb2_close_getattr(const unsigned int xid, struct ci= fs_tcon *tcon, return rc; } =20 +static int +smb2_set_file_disp(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, bool delete_pending) +{ + return SMB2_set_disp(xid, tcon, fid->persistent_fid, fid->volatile_fid, d= elete_pending); +} + static int SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, @@ -5310,6 +5317,7 @@ struct smb_version_operations smb20_operations =3D { .set_path_size =3D smb2_set_path_size, .set_file_size =3D smb2_set_file_size, .set_file_info =3D smb2_set_file_info, + .set_file_disp =3D smb2_set_file_disp, .set_compression =3D smb2_set_compression, .mkdir =3D smb2_mkdir, .mkdir_setinfo =3D smb2_mkdir_setinfo, @@ -5413,6 +5421,7 @@ struct smb_version_operations smb21_operations =3D { .set_path_size =3D smb2_set_path_size, .set_file_size =3D smb2_set_file_size, .set_file_info =3D smb2_set_file_info, + .set_file_disp =3D smb2_set_file_disp, .set_compression =3D smb2_set_compression, .mkdir =3D smb2_mkdir, .mkdir_setinfo =3D smb2_mkdir_setinfo, @@ -5520,6 +5529,7 @@ struct smb_version_operations smb30_operations =3D { .set_path_size =3D smb2_set_path_size, .set_file_size =3D smb2_set_file_size, .set_file_info =3D smb2_set_file_info, + .set_file_disp =3D smb2_set_file_disp, .set_compression =3D smb2_set_compression, .mkdir =3D smb2_mkdir, .mkdir_setinfo =3D smb2_mkdir_setinfo, @@ -5635,6 +5645,7 @@ struct smb_version_operations smb311_operations =3D { .set_path_size =3D smb2_set_path_size, .set_file_size =3D smb2_set_file_size, .set_file_info =3D smb2_set_file_info, + .set_file_disp =3D smb2_set_file_disp, .set_compression =3D smb2_set_compression, .mkdir =3D smb2_mkdir, .mkdir_setinfo =3D smb2_mkdir_setinfo, diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index bf588ec99618..e05ddd446467 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5755,6 +5755,19 @@ SMB2_set_ea(const unsigned int xid, struct cifs_tcon= *tcon, 0, 1, (void **)&buf, &len); } =20 +int +SMB2_set_disp(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, bool delete_pending) +{ + __u8 disp =3D delete_pending; + __u8 *buf =3D &disp; + unsigned int len =3D sizeof(disp); + + return send_set_info(xid, tcon, persistent_fid, volatile_fid, + current->tgid, FILE_DISPOSITION_INFORMATION, + SMB2_O_INFO_FILE, 0, 1, (void **)&buf, &len); +} + int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, const u64 persistent_fid, const u64 volatile_fid, diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index 6e805ece6a7b..d78ea3a6a5fb 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -249,6 +249,8 @@ extern int SMB2_set_acl(const unsigned int xid, struct = cifs_tcon *tcon, extern int SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, struct smb2_file_full_ea_info *buf, int len); +extern int SMB2_set_disp(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, bool delete_pending); extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *= tcon, u64 persistent_fid, u64 volatile_fid); extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tco= n, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 033EF267B89; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=ncRU8n8S2TGUSza1LPsmtGjpJoKWm7NUuyTeV79rDnhNstl3oLJbZeaPXaGflq9cZgWgc63Cxng993gnUMjYLOd5tq6UFxitiJhQvx65Q5E1tfQpQxZbFq3FS+by23Y58anzBpTajbu9rMXPXX4Uh05ZutfqNP9L51iRozFdrhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=4OxJ1hA+cvUqeyyfmVv74EFqlJPYDWJGHmo1sOfaEIA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Q8ztQdjAARmKBG7jsthR5MEtjs50u23pDZn7U3F8/ZRe29TwCFdV+MyeV0inuNT6yO36qxtec8Pkf1KT/RDZ7Qh4z3PQywRmI5BLpZ3xxnNRkqgX5i2n4PAKKZkbB1JvTYYIZSKAn6jAoDAIwqsha3NBnigoAWTv2OZlLQ1NY8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fs77t22j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fs77t22j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 915AAC4CEFD; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643797; bh=4OxJ1hA+cvUqeyyfmVv74EFqlJPYDWJGHmo1sOfaEIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fs77t22j90PJfOo/4F3GBQZRPFeCyx269wD0cmskPny+S9K6dbofNwj3FlK1uJE+i NrsPlS9S6BX2jM8GWSY3i5TEF2HM0fpfXnGkB4vqW6BmqAujU72GNEl6sglMjwMMXX 1tQjQbEuV5wu4CSFcNJma4Wmx0zdM9/cst3w5Yvy+rtW4qXY+M84Oo+eObWcNYYo7Y 5TRZXpwcwSBxwVdep3to4KXnibWpLYF+HnbroecwxfS+xsu98hSHz63YuxRJA0HtHq 7U5N89WTF8kRtnmeAt+BO0aVfjhABmKECDrmI3j1DOhPaEGyfOWMeli1F3Z6jrePbW uJiswiZY0SpPg== Received: by pali.im (Postfix) id D3BFA1168; Sun, 31 Aug 2025 14:36:35 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 25/35] cifs: Add a new callback rename_opened_file() for renaming an opened file Date: Sun, 31 Aug 2025 14:35:52 +0200 Message-Id: <20250831123602.14037-26-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Implement it for all SMB dialects. It will be used by follow up changes. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsglob.h | 4 ++++ fs/smb/client/smb1ops.c | 18 ++++++++++++++++++ fs/smb/client/smb2ops.c | 13 +++++++++++++ fs/smb/client/smb2pdu.c | 28 ++++++++++++++++++++++++++++ fs/smb/client/smb2proto.h | 4 ++++ 5 files changed, 67 insertions(+) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 7162b9120198..ec5608924ce7 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -462,6 +462,10 @@ struct smb_version_operations { struct dentry *source_dentry, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb); + /* send rename request for opened file */ + int (*rename_opened_file)(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, const char *new_full_path, + bool overwrite, struct cifs_sb_info *cifs_sb); /* send create hardlink request */ int (*create_hardlink)(const unsigned int xid, struct cifs_tcon *tcon, diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index e37104d3c5d7..26798db5c00b 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -1086,6 +1086,23 @@ cifs_set_file_disp(const unsigned int xid, struct ci= fs_tcon *tcon, return CIFSSMBSetFileDisposition(xid, tcon, delete_pending, fid->netfid, = current->tgid); } =20 +static int +cifs_rename_opened_file(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, const char *new_full_path, + bool overwrite, struct cifs_sb_info *cifs_sb) +{ + const char *name; + + /* CIFSSMBRenameOpenFile() requires just new basename of the file */ + name =3D strrchr(new_full_path, CIFS_DIR_SEP(cifs_sb)); + if (name) + name++; + else + name =3D new_full_path; + return CIFSSMBRenameOpenFile(xid, tcon, fid->netfid, name, overwrite, + cifs_sb->local_nls, cifs_remap(cifs_sb)); +} + static int cifs_set_compression(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile) @@ -1407,6 +1424,7 @@ struct smb_version_operations smb1_operations =3D { .unlink =3D CIFSSMBDelFile, .rename_pending_delete =3D cifs_rename_pending_delete, .rename =3D CIFSSMBRename, + .rename_opened_file =3D cifs_rename_opened_file, .create_hardlink =3D CIFSCreateHardLink, .query_symlink =3D cifs_query_symlink, .get_reparse_point_buffer =3D cifs_get_reparse_point_buffer, diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 530e66fa4671..0ba15af86582 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -1522,6 +1522,15 @@ smb2_set_file_disp(const unsigned int xid, struct ci= fs_tcon *tcon, return SMB2_set_disp(xid, tcon, fid->persistent_fid, fid->volatile_fid, d= elete_pending); } =20 +static int +smb2_rename_opened_file(const unsigned int xid, struct cifs_tcon *tcon, + struct cifs_fid *fid, const char *new_full_path, + bool overwrite, struct cifs_sb_info *cifs_sb) +{ + return SMB2_set_full_path(xid, tcon, fid->persistent_fid, fid->volatile_f= id, + new_full_path, overwrite, cifs_sb); +} + static int SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, @@ -5324,6 +5333,7 @@ struct smb_version_operations smb20_operations =3D { .rmdir =3D smb2_rmdir, .unlink =3D smb2_unlink, .rename =3D smb2_rename_path, + .rename_opened_file =3D smb2_rename_opened_file, .create_hardlink =3D smb2_create_hardlink, .get_reparse_point_buffer =3D smb2_get_reparse_point_buffer, .query_mf_symlink =3D smb3_query_mf_symlink, @@ -5428,6 +5438,7 @@ struct smb_version_operations smb21_operations =3D { .rmdir =3D smb2_rmdir, .unlink =3D smb2_unlink, .rename =3D smb2_rename_path, + .rename_opened_file =3D smb2_rename_opened_file, .create_hardlink =3D smb2_create_hardlink, .get_reparse_point_buffer =3D smb2_get_reparse_point_buffer, .query_mf_symlink =3D smb3_query_mf_symlink, @@ -5536,6 +5547,7 @@ struct smb_version_operations smb30_operations =3D { .rmdir =3D smb2_rmdir, .unlink =3D smb2_unlink, .rename =3D smb2_rename_path, + .rename_opened_file =3D smb2_rename_opened_file, .create_hardlink =3D smb2_create_hardlink, .get_reparse_point_buffer =3D smb2_get_reparse_point_buffer, .query_mf_symlink =3D smb3_query_mf_symlink, @@ -5653,6 +5665,7 @@ struct smb_version_operations smb311_operations =3D { .rmdir =3D smb2_rmdir, .unlink =3D smb2_unlink, .rename =3D smb2_rename_path, + .rename_opened_file =3D smb2_rename_opened_file, .create_hardlink =3D smb2_create_hardlink, .get_reparse_point_buffer =3D smb2_get_reparse_point_buffer, .query_mf_symlink =3D smb3_query_mf_symlink, diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index e05ddd446467..a6c69b01ec6b 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5768,6 +5768,34 @@ SMB2_set_disp(const unsigned int xid, struct cifs_tc= on *tcon, SMB2_O_INFO_FILE, 0, 1, (void **)&buf, &len); } =20 +int +SMB2_set_full_path(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, const char *new_full_path, + bool overwrite, struct cifs_sb_info *cifs_sb) +{ + struct smb2_file_rename_info rename_info =3D {}; + unsigned int size[2]; + void *data[2]; + int rc; + + data[1] =3D cifs_convert_path_to_utf16(new_full_path, cifs_sb); + if (!data[1]) + return -ENOMEM; + size[1] =3D 2 * UniStrnlen((wchar_t *)data[1], PATH_MAX); + + rename_info.ReplaceIfExists =3D overwrite; + rename_info.RootDirectory =3D 0; + rename_info.FileNameLength =3D cpu_to_le32(size[1]); + data[0] =3D &rename_info; + size[0] =3D sizeof(rename_info); + + rc =3D send_set_info(xid, tcon, persistent_fid, volatile_fid, + current->tgid, FILE_RENAME_INFORMATION, + SMB2_O_INFO_FILE, 0, 2, data, size); + kfree(data[1]); + return rc; +} + int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, const u64 persistent_fid, const u64 volatile_fid, diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index d78ea3a6a5fb..7c300dd9ea4e 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -251,6 +251,10 @@ extern int SMB2_set_ea(const unsigned int xid, struct = cifs_tcon *tcon, struct smb2_file_full_ea_info *buf, int len); extern int SMB2_set_disp(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, bool delete_pending); +extern int SMB2_set_full_path(const unsigned int xid, struct cifs_tcon *tc= on, + u64 persistent_fid, u64 volatile_fid, + const char *name, bool overwrite, + struct cifs_sb_info *cifs_sb); extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *= tcon, u64 persistent_fid, u64 volatile_fid); extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tco= n, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 177A526E701; Sun, 31 Aug 2025 12:36:40 +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=1756643800; cv=none; b=R8mXl9kHu2kY5LIsn7pK2iOyWF6bpahJsAhCSIH7oEC9RdiQ8PlkED8tyqN6FnUhwI45KpgH95QRbrNdaHnIC+M123+Z8kDbZkH3191zFIaeGibYe/OO1bUW/Q6IOQdqroqGgGqHmgjhHY/Jf8RAjizPNZD584VRpmornhOb9Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643800; c=relaxed/simple; bh=kkY3dV4+g16/UFiBKJIvabwDCXuiAib+78j5fAdmQGk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WbAy0u6+LSdhuBrZmpxQ4X4BToW80nZ90Qzj5Miyu80X4BWztvEFyXRWgbkR0pHvYMqymgNYXYWzMPYBMeEOe4zpHfX5MxXPeVLMyx+FX6VZAPdLDpPZnbb64AIrawd2KmPASH1rXD0SukBKnV2RQ/B0shu0rnHWlsjdKjZlOSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZhUQU/nk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZhUQU/nk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99044C4CEED; Sun, 31 Aug 2025 12:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643799; bh=kkY3dV4+g16/UFiBKJIvabwDCXuiAib+78j5fAdmQGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZhUQU/nkFV1VGPa+BR723dyJm889IfogsIyd4x3KT69Ku0A24WNDuHz3j9n1aiQ7s FAYaLOGuyPZ968/itVi6IlJMLKinLr1sN2ZmBRWk/4bPxZKZXwFpe2uwhp6zjR+1wn btM+H1g9hSCNCu+LG0qJ7utoZ3XNUY7ARQ4yJ1j6tQlsBwPVcucTjwiAWz8wE90OjF T67s7K4dJNnN72fuCU1A9Q2vyhUHelq29vN1HrUxPUi4A9lS7jOJTVoZPeG3EAEj8U 5/1yOiSGF648h81skCiE6B/WohXCZOni7vU8jrUtvNgR0lvst271MzrBwUitz2mlVv IBx3bzMu/fqsQ== Received: by pali.im (Postfix) id 1BD58EB3; Sun, 31 Aug 2025 14:36:36 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 26/35] cifs: Add SMB2+ support into cifs_rename_pending_delete() function. Date: Sun, 31 Aug 2025 14:35:53 +0200 Message-Id: <20250831123602.14037-27-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Currently the cifs_rename_pending_delete() function calls directly the SMB1 functions and therefore cannot be used by SMB2+ dialects. Change cifs_rename_pending_delete() code to use tcon->ses->server->ops-> callbacks instead of direct SMB1 functions. This allows to use this function also by SMB2 and SMB3 dialects. Mark the function cifs_rename_pending_delete() as static in inode.c and calls it directly. As it is now dialect neutral, remove it from struct smb_version_operations callback list. This change allows to use silly rename in SMB2+ by follow up changes. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifsglob.h | 3 --- fs/smb/client/cifsproto.h | 3 --- fs/smb/client/inode.c | 56 +++++++++++++++++---------------------- fs/smb/client/smb1ops.c | 1 - 4 files changed, 24 insertions(+), 39 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index ec5608924ce7..592a4faa3440 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -453,9 +453,6 @@ struct smb_version_operations { /* unlink file */ int (*unlink)(const unsigned int, struct cifs_tcon *, const char *, struct cifs_sb_info *, struct dentry *); - /* open, rename and delete file */ - int (*rename_pending_delete)(const char *, struct dentry *, - const unsigned int); /* send rename request */ int (*rename)(const unsigned int xid, struct cifs_tcon *tcon, diff --git a/fs/smb/client/cifsproto.h b/fs/smb/client/cifsproto.h index f248b18f1cf3..a29662a4d83d 100644 --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -242,9 +242,6 @@ extern int cifs_get_inode_info_unix(struct inode **pino= de, struct super_block *sb, unsigned int xid); extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, const char *full_path, __u32 dosattr); -extern int cifs_rename_pending_delete(const char *full_path, - struct dentry *dentry, - const unsigned int xid); extern int sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, struct cifs_fattr *fattr, uint sidtype); extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 9a5504a3406d..c3f101d10488 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1684,7 +1684,6 @@ cifs_set_file_info(struct inode *inode, struct iattr = *attrs, unsigned int xid, return server->ops->set_file_info(inode, full_path, &info_buf, xid); } =20 -#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY /* * Open the given file (if it isn't already), set the DELETE_PENDING bit * and rename it to a random name that hopefully won't conflict with @@ -1697,9 +1696,11 @@ cifs_set_file_info(struct inode *inode, struct iattr= *attrs, unsigned int xid, #define SILLYNAME_LEN (SILLYNAME_PREFIX_LEN + \ SILLYNAME_FILEID_LEN + \ SILLYNAME_COUNTER_LEN) -int -cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, - const unsigned int xid) +static int +cifs_rename_pending_delete(const unsigned int xid, + struct cifs_tcon *tcon, + const char *full_path, + struct dentry *dentry) { int oplock =3D 0; int rc; @@ -1708,8 +1709,6 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, struct inode *inode =3D d_inode(dentry); struct cifsInodeInfo *cifsInode =3D CIFS_I(inode); struct cifs_sb_info *cifs_sb =3D CIFS_SB(inode->i_sb); - struct tcon_link *tlink; - struct cifs_tcon *tcon; __u32 dosattr, origattr; char *sillyname_full_path =3D NULL; bool can_rename_opened_file =3D true; @@ -1719,11 +1718,6 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, const char *dirpath_end; size_t dirpath_len; =20 - tlink =3D cifs_sb_tlink(cifs_sb); - if (IS_ERR(tlink)) - return PTR_ERR(tlink); - tcon =3D tlink_tcon(tlink); - /* construct random name ".smb" */ while (true) { static unsigned int sillycounter; /* globally unique */ @@ -1753,8 +1747,10 @@ cifs_rename_pending_delete(const char *full_path, st= ruct dentry *dentry, /* * We cannot rename the opened file if the SMB1 server doesn't * support CAP_INFOLEVEL_PASSTHRU. But we can rename file via path. + * SMB2+ always supports renaming of the opened file. */ - if (!(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)) + if (tcon->ses->server->vals->protocol_id =3D=3D SMB10_PROT_ID && + !(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)) can_rename_opened_file =3D false; =20 dirpath_end =3D strrchr(full_path, CIFS_DIR_SEP(cifs_sb)); @@ -1821,16 +1817,16 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, .fid =3D &fid, }; =20 - rc =3D CIFS_open(xid, &oparms, &oplock, NULL); + rc =3D tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL); if (rc !=3D 0) goto undo_rename_path; =20 /* rename the opened file (if it was not already renamed before the open)= */ if (can_rename_opened_file) { - rc =3D CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, sillyname, + rc =3D tcon->ses->server->ops->rename_opened_file( + xid, tcon, &fid, sillyname_full_path, false /* overwrite */, - cifs_sb->local_nls, - cifs_remap(cifs_sb)); + cifs_sb); if (rc !=3D 0) { rc =3D -EBUSY; goto undo_close; @@ -1839,8 +1835,7 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, =20 /* try to set DELETE_PENDING */ if (!test_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags)) { - rc =3D CIFSSMBSetFileDisposition(xid, tcon, true, fid.netfid, - current->tgid); + rc =3D tcon->ses->server->ops->set_file_disp(xid, tcon, &fid, true); /* * some samba versions return -ENOENT when we try to set the * file disposition here. Likely a samba bug, but work around @@ -1856,11 +1851,10 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, set_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags); } =20 - CIFSSMBClose(xid, tcon, fid.netfid); + tcon->ses->server->ops->close(xid, tcon, &fid); =20 out: kfree(sillyname_full_path); - cifs_put_tlink(tlink); return rc; =20 /* @@ -1870,14 +1864,16 @@ cifs_rename_pending_delete(const char *full_path, s= truct dentry *dentry, */ undo_rename_opened_file: if (can_rename_opened_file) - CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name, + tcon->ses->server->ops->rename_opened_file( + xid, tcon, &fid, full_path, true /* overwrite */, - cifs_sb->local_nls, cifs_remap(cifs_sb)); + cifs_sb); undo_close: - CIFSSMBClose(xid, tcon, fid.netfid); + tcon->ses->server->ops->close(xid, tcon, &fid); undo_rename_path: if (!can_rename_opened_file) - CIFSSMBRename(xid, tcon, dentry, + tcon->ses->server->ops->rename( + xid, tcon, dentry, sillyname_full_path, full_path, cifs_sb); @@ -1888,7 +1884,6 @@ cifs_rename_pending_delete(const char *full_path, str= uct dentry *dentry, } goto out; } -#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ =20 /* copied from fs/nfs/dir.c with small changes */ static void @@ -1981,13 +1976,10 @@ int cifs_unlink(struct inode *dir, struct dentry *d= entry) } else if (rc =3D=3D -ENOENT) { d_drop(dentry); } else if (rc =3D=3D -EBUSY) { - if (server->ops->rename_pending_delete) { - rc =3D server->ops->rename_pending_delete(full_path, - dentry, xid); - if (rc =3D=3D 0) { - cifs_mark_open_handles_for_deleted_file(inode, full_path); - cifs_drop_nlink(inode); - } + rc =3D cifs_rename_pending_delete(xid, tcon, full_path, dentry); + if (rc =3D=3D 0) { + cifs_mark_open_handles_for_deleted_file(inode, full_path); + cifs_drop_nlink(inode); } } else if ((rc =3D=3D -EACCES) && (dosattr =3D=3D 0) && inode) { attrs =3D kzalloc(sizeof(*attrs), GFP_KERNEL); diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c index 26798db5c00b..746dd9aa6b1b 100644 --- a/fs/smb/client/smb1ops.c +++ b/fs/smb/client/smb1ops.c @@ -1422,7 +1422,6 @@ struct smb_version_operations smb1_operations =3D { .mkdir_setinfo =3D cifs_mkdir_setinfo, .rmdir =3D CIFSSMBRmDir, .unlink =3D CIFSSMBDelFile, - .rename_pending_delete =3D cifs_rename_pending_delete, .rename =3D CIFSSMBRename, .rename_opened_file =3D cifs_rename_opened_file, .create_hardlink =3D CIFSCreateHardLink, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 3340A26981E; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=QL3yuKB6dceePquex0mjhKnZcHMPXNkaxyFpaQO5/OFry6dhDKmmixxSv4qK00k0174M22Q28a3iQr0r6ZgNGyUwUUnHWoZM/yUHMnv4miEwmMnOileLEOaj9voXxMHnga9ulWYgHXaM3rN2ePEnzSdSdGOcNBGXYgSLiatJNRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=j/DaCTz6Vnq2DWJalAYLoPLGNEyRjSFNsogDPZjeMB8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Y/WRAlP8igIC9ndX1OH5W3WLSl9KtQBB2HDjxsePc2Zvh87NnK9g18SjpYhI3Zk1UsEUxlKHCulDlNClzOEBv8cW8MnOEK0e3ffh5cd4U3+uv5x35v1JiYlkKeInIERin4UL6xFWnBa45Vo4nUHk5sHUxgnJnXHI4stPAWbXVT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WI0Hib0N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WI0Hib0N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA5CEC4CEFB; Sun, 31 Aug 2025 12:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=j/DaCTz6Vnq2DWJalAYLoPLGNEyRjSFNsogDPZjeMB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WI0Hib0N0EVd0e1DcfwmgKj34JvV6OVxhPopYNeaNbEKBVeqD8Uofzd8PAtPzSIen 3Z9wxVDolZ4UX78Ifs0fwoUCy+9IVxilM/mZzGYRmRZT1WmFrSUV34rVjAm/MjpuZq p/8Uo4vznmaOJNX+infVmrbPtVdSrp61g2cbKSVseX+IGdZCR/+NmS1nEIrIXH4EJh TL/6uFcZYnndGoO3RMYhwo2iznpUx4vFWohtM8gW2edzgGu7SoZqAv44/RSWwlMZMb 5VbXV2KDSYx+2uKjxoLifgOyLXaEI0Eu+lefhjzchV7eg+0wJl3iSC7Xau0RJ2Vj2J gI3mzkvHpug2w== Received: by pali.im (Postfix) id 5352511D8; Sun, 31 Aug 2025 14:36:36 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 27/35] cifs: Move SMB1 usage of CIFSPOSIXDelFile() from inode.c to cifssmb.c Date: Sun, 31 Aug 2025 14:35:54 +0200 Message-Id: <20250831123602.14037-28-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Special case of unlinking file via SMB1 UNIX extension is currently in the dialect agnostic function cifs_unlink() and hidden under the #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY. Cleanup the code and move this functionality into the SMB1 ->unlink() callback, which removes one #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY code block from inode.c Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 12 ++++++++++++ fs/smb/client/inode.c | 20 +++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index c09713ebdc7c..3a0452479a69 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -768,6 +768,18 @@ CIFSSMBDelFile(const unsigned int xid, struct cifs_tco= n *tcon, const char *name, int name_len; int remap =3D cifs_remap(cifs_sb); =20 + /* If UNIX extensions are available then use UNIX UNLINK call. */ + if (cap_unix(tcon->ses) && + (le64_to_cpu(tcon->fsUnixInfo.Capability) & CIFS_UNIX_POSIX_PATH_OPS_= CAP)) { + rc =3D CIFSPOSIXDelFile(xid, tcon, name, + SMB_POSIX_UNLINK_FILE_TARGET, + cifs_sb->local_nls, + cifs_remap(cifs_sb)); + cifs_dbg(FYI, "posix del rc %d\n", rc); + if (rc =3D=3D 0 || rc =3D=3D -ENOENT) + return rc; + } + DelFileRetry: rc =3D smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, (void **) &pSMBr); diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index c3f101d10488..545964cac9cd 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1947,27 +1947,13 @@ int cifs_unlink(struct inode *dir, struct dentry *d= entry) =20 netfs_wait_for_outstanding_io(inode); cifs_close_deferred_file_under_dentry(tcon, full_path); -#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY - if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & - le64_to_cpu(tcon->fsUnixInfo.Capability))) { - rc =3D CIFSPOSIXDelFile(xid, tcon, full_path, - SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls, - cifs_remap(cifs_sb)); - cifs_dbg(FYI, "posix del rc %d\n", rc); - if ((rc =3D=3D 0) || (rc =3D=3D -ENOENT)) - goto psx_del_no_retry; - } -#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ =20 retry_std_delete: - if (!server->ops->unlink) { + if (!server->ops->unlink) rc =3D -ENOSYS; - goto psx_del_no_retry; - } - - rc =3D server->ops->unlink(xid, tcon, full_path, cifs_sb, dentry); + else + rc =3D server->ops->unlink(xid, tcon, full_path, cifs_sb, dentry); =20 -psx_del_no_retry: if (!rc) { if (inode) { cifs_mark_open_handles_for_deleted_file(inode, full_path); --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 5309826A091; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=QhMJr+jIS5Z7sP9wBGwRR/Dik14wUgIsHqAzVM58wN+ly65UhNnmvJR2ZjLxBT6lrG+Pi2YhmCrcI1p4FSvbH940tbmA1jAW3axbHu2txL0c4LqOfIJJbfn/2eyXdPzCYo59HsTPQ7+e75D6sodXbNz1LxmXESTQyoCyqbf2Fes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=DTHD+PYP2YbpdTJYB1bY7oWsK3TejRcfICiywAvse/Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=rPZO/3XhUQSGAX3Nk+7TvejW9O2WJNSyhCXkcsGqscuTXKMVc+ng2FipXQepcw+41ut33CegRlsRJYYywzASABnNwN89HdG41rffCBpMIo+NiPk5USNVYgJxIhBdL4NQFrPVuXSIkMXTDKPL9J6ckNJzM1U88EB0ASuEVpI0B/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eqZ8sO2C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eqZ8sO2C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 173D7C4CEF8; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=DTHD+PYP2YbpdTJYB1bY7oWsK3TejRcfICiywAvse/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eqZ8sO2CLpxMSPo2ISNZtZaco5esZQ4MW2P+k7lvzzfJLs6vBOzPQUv+09IarRJVa VgO2QCZ++JQDa0fb46KGR6Ub9VopMzA5BtpV8y6PBDayfUzXlrjTqgHa+01aymFYUT fOPVrk5Sf1eWZByRf0iSjTllfa2BraLovGM9BTxD4OPLRxXZ32ppF346GGD/xNSF/Y mRMWXC9Ute9K0ZZ6LQ6QCobtLmCKNQSVkAjhVvZDNA1ZRZ+pVfoEEOJTRnXox8J2Ji CHN5vv2mjaJn4odBocokUkldzZ98mIXPjwENNjh0AjoQIcycTGk0/YdNFtJS1x7g93 LbZkfefgFYU1A== Received: by pali.im (Postfix) id 89D07129B; Sun, 31 Aug 2025 14:36:36 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 28/35] cifs: Fix smb2_unlink() to fail on directory Date: Sun, 31 Aug 2025 14:35:55 +0200 Message-Id: <20250831123602.14037-29-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable unlink() should fail on the directory with ENOTDIR error code. Flag CREATE_NOT_DIR handles that. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb2inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index c8b0e9b2438f..c69293fcf26c 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -1348,7 +1348,7 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon = *tcon, const char *name, =20 oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, FILE_OPEN, - CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, + CREATE_DELETE_ON_CLOSE | CREATE_NOT_DIR | OPEN_REPARSE_POINT, ACL_NO_MODE); int rc =3D smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, NULL, &(int){SMB2_OP_DELETE}, 1, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 5B2A826A0C7; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=RRwWM/IdNsm+oNcTHTDqhemRHdaJkGEP3+DbXQlrd78BO0NR09OaHLAHhUrJ+TYFlbh0ptby/r00KAWJi5cDziBwvYP75ROFeYsqvGd45s9ZSGJXvM2moJ2Q/gDXDNLoh4JRKnoVvPqJiEcD1MBkaOTWHFaZQGHZjd0xlwbzExY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=sFpDM8FK52/mxVHxZVDv7mb5QxtBQgGkmwUad9YdCTQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=FA2lasTT9F/q519euIIyU5RJVr7tMr4c5SlfyIq/rhzRknRO1EdE/Sck1V7UOc0O5VAI7nfcyLKtQg/JW4WmMeEXUITnNroVV1nYx0f4gw4Egy8Wo4pe0qeVTGuuhrk/65QBkbyop23mPdMKKyPUSIneGLLPd02fV6WIezrKPCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=utmcu6pR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="utmcu6pR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C6F8C4AF0C; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=sFpDM8FK52/mxVHxZVDv7mb5QxtBQgGkmwUad9YdCTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=utmcu6pRYBkYyu2x0i5fimlgRzvzl0xydkcn1bjlYd0oGV731wnNTUN73Y8uwMM+Y io08NMRF+xZvHeuzQv+fQ+mtuGghOISzPiOgqLSW+Z4Vnq19+/JU3ApiSOd2G8S75y jfLUeaGPlLq/+cQp/KLajkQYfKPGJR+RZGT6CO2MoK88FMetobXBe9CJuhTKEhBfsq Rpy4s8w/PgouRgLh7P2QrHOW1GP06HxEoE7EemI1op6t+PqcT4rz1Knbd0hxCHeR21 kT/vGXvA2sJp0sDAFmUjGbB2rWbvOXaBZ28C0GrPSKfwP4HndmmyB14YkAYXCSy+Qi IOIvJdu3NtvHw== Received: by pali.im (Postfix) id C0C3DF12; Sun, 31 Aug 2025 14:36:36 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 29/35] cifs: Fix smb2_rmdir() on reparse point Date: Sun, 31 Aug 2025 14:35:56 +0200 Message-Id: <20250831123602.14037-30-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable rmdir() should remove the directory node specified by the path and not the path where reparse point can point. Open flag OPEN_REPARSE_POINT cause to remove directory node itself. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb2inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index c69293fcf26c..59d73e01ccd2 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -1333,7 +1333,7 @@ smb2_rmdir(const unsigned int xid, struct cifs_tcon *= tcon, const char *name, =20 drop_cached_dir_by_name(xid, tcon, name, cifs_sb); oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, - FILE_OPEN, CREATE_NOT_FILE, ACL_NO_MODE); + FILE_OPEN, CREATE_NOT_FILE | OPEN_REPARSE_POINT, ACL_NO_MODE); return smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, NULL, &(int){SMB2_OP_RMDIR}, 1, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 5B22926A0C6; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=oGzrqqDX3eY1lcinddvHL5imGIY9BhUQajfbWnQxO53URBQByPR5RDkxbCVGAQA56ef3geCnQrhbHgZoNQP03iCeZL+3eG7Dbrzhz/Fi2WRY3HidLtyVVbipfZCVECnGtT+mAhRuELjebq4bfmrhxQ/g5wXLRJ1u9wBFYna4dPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=L+Fz/PQmKe5w+IjKQjmONfWxzNRhm8SNMsCPELs3dkU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nnZ2xTv4zXEwxm+F6ET+wOGhKqT43RIBnI+IdvZxgN6ejFCFDNByzlkKe1qG39RGn2y3kd5BJXYzVUI8YjO49Qc7fuUeMKngytuMM4uM0YMFzJmhGVQlOy9JFnsDHTMK0wUxuWzDpyQMD4Gt96vZ7wOaq8T9KPP2LYjJjHMIy94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MtcIanKN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MtcIanKN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D795C4CEFA; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=L+Fz/PQmKe5w+IjKQjmONfWxzNRhm8SNMsCPELs3dkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtcIanKNV2Tkhpo2R9yNTlXb90wPMtXajJjYFUG74uhB+I6k/sr0tFKfU+CTSlUkK p2iHq5jw39GqUpKUoNqEtZw78+6RjaA8lujuQk3o5G70Q6IyaNsBHu9w1KiETxhwof wGyRpQB6HBbwh3Osxa8ckkcuj2VswcK0ZFDTLwvRCgAIToLRXf0Vwkpwf8Ci1fcnIP flapPzddpa8zm+luNfx/oT8Lnx4/9HObyAcUh7pQjYxwvFfAJwRtfupxmRmj/OIdtm EyVtkLK4leerpyWqI4jBrb3sWq/JYjl0rpsGfKWHoL0kSUs+M4VAojogwcvdp1rIu+ VxMJO0g3cMjzg== Received: by pali.im (Postfix) id E8A3112DE; Sun, 31 Aug 2025 14:36:36 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 30/35] cifs: Simplify SMB2_OP_DELETE API usage Date: Sun, 31 Aug 2025 14:35:57 +0200 Message-Id: <20250831123602.14037-31-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Currently the caller of SMB2_OP_DELETE operation has to specify also the CREATE_DELETE_ON_CLOSE flag. Simplify API usage and let the callee smb2_compound_op() to automatically set this flag when issuing the SMB2_OP_DELETE operation. No functional change. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb2inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 59d73e01ccd2..a3b1ed53a860 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -255,6 +255,13 @@ static int smb2_compound_op(const unsigned int xid, st= ruct cifs_tcon *tcon, vars->oparms =3D *oparms; vars->oparms.fid =3D &fid; =20 + for (i =3D 0; i < num_cmds; i++) { + if (cmds[i] =3D=3D SMB2_OP_DELETE) { + vars->oparms.create_options |=3D CREATE_DELETE_ON_CLOSE; + break; + } + } + rqst[num_rqst].rq_iov =3D &vars->open_iov[0]; rqst[num_rqst].rq_nvec =3D SMB2_CREATE_IOV_SIZE; rc =3D SMB2_open_init(tcon, server, @@ -1348,7 +1355,7 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon = *tcon, const char *name, =20 oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, FILE_OPEN, - CREATE_DELETE_ON_CLOSE | CREATE_NOT_DIR | OPEN_REPARSE_POINT, + CREATE_NOT_DIR | OPEN_REPARSE_POINT, ACL_NO_MODE); int rc =3D smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, NULL, &(int){SMB2_OP_DELETE}, 1, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 769FF26F2A6; Sun, 31 Aug 2025 12:36:40 +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=1756643800; cv=none; b=A1mvEqWthVLIkPPd/JGyDIKRO4a86bl/wD0cl8KehCjXTrvgR4a4FIvgY+Qy8rgyC+q9fMVa14PaW0TywU3nDmi6SHOyYDKgDmH52CSZEPv/USnJt0U8A2DFXRJhyDECxAfbJA3YjUPDy7JueFdDBRmJa+IglRMu+mScguca8VA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643800; c=relaxed/simple; bh=uA/HDvBMaiWbGDSPGBQm5JB6alpNsa8hljEovxFjYFE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RzXUgDG5QyyZ7S8t8e2dUTSHIianLGHgR/2sNgXgSszbhYygv0aPw/VVmNk+9TDJAlpdF5+KsDsU/ctJevTWILrdh5P1vyNpa7CTxfEfFZxBPUzFCM8k9+J7N8d2diYEP+ZbcrtpITwrhUyOpIp3S/y2MZSlTXHNz3BJk0XRnhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xst19Egx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xst19Egx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB061C4CEF5; Sun, 31 Aug 2025 12:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643800; bh=uA/HDvBMaiWbGDSPGBQm5JB6alpNsa8hljEovxFjYFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xst19Egx39dh/ALGVIAgUA17QxKkzijLuU4k9BH6KNEi4Rcxe877rwbRpAMUDdo+M R4w+fStIarbJTYA81TYOGDmWFxk2ObZPhZ08PmppgJJBKdpnxlO1nKy2/P/2YiYTJi JlGiOvSaEXeAiTrnZscCK/e9yDCqfIU/8D9aC8POZ8HraAbwPkqS5tDPrbaCJbdKd+ 6e09IyrszbFGD/EEyYK+Q58Jel5kfMXTWnTjxEB6SWmlVRjUfZlhr6uvYtxVKzCnK3 6nMhUFoS4nCjpoUC5w3o6tXs6dWyxpEs9qUKrDWjlUlp/6lZ+8drYiOA0praCSLh1q DOIIAk8MuYBWw== Received: by pali.im (Postfix) id 217B912ED; Sun, 31 Aug 2025 14:36:37 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 31/35] cifs: Deduplicate smb2_unlink() and smb2_rmdir() into one common function Date: Sun, 31 Aug 2025 14:35:58 +0200 Message-Id: <20250831123602.14037-32-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable These two functions smb2_unlink() and smb2_rmdir() share lot of common logic. Deduplicate them into one common static function smb2_remove(). No functional change. All logic and handling stay same. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb2inode.c | 57 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index a3b1ed53a860..0dd4a77dfb64 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -1332,43 +1332,54 @@ smb2_mkdir_setinfo(struct inode *inode, const char = *name, cifs_i->cifsAttrs =3D dosattrs; } =20 -int -smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *nam= e, - struct cifs_sb_info *cifs_sb) +static int +smb2_remove(const unsigned int xid, struct cifs_tcon *tcon, const char *na= me, + struct cifs_sb_info *cifs_sb, struct dentry *dentry, bool is_dir) { struct cifs_open_parms oparms; + int op_flags; + int op; + int rc; =20 - drop_cached_dir_by_name(xid, tcon, name, cifs_sb); - oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, - FILE_OPEN, CREATE_NOT_FILE | OPEN_REPARSE_POINT, ACL_NO_MODE); - return smb2_compound_op(xid, tcon, cifs_sb, - name, &oparms, NULL, - &(int){SMB2_OP_RMDIR}, 1, - NULL, NULL, NULL, NULL); -} - -int -smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *na= me, - struct cifs_sb_info *cifs_sb, struct dentry *dentry) -{ - struct cifs_open_parms oparms; + if (is_dir) + drop_cached_dir_by_name(xid, tcon, name, cifs_sb); =20 + if (is_dir) { + op =3D SMB2_OP_RMDIR; + op_flags =3D CREATE_NOT_FILE; + } else { + op =3D SMB2_OP_DELETE; + op_flags =3D CREATE_NOT_DIR; + } oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, FILE_OPEN, - CREATE_NOT_DIR | OPEN_REPARSE_POINT, + OPEN_REPARSE_POINT | op_flags, ACL_NO_MODE); - int rc =3D smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, - NULL, &(int){SMB2_OP_DELETE}, 1, - NULL, NULL, NULL, dentry); - if (rc =3D=3D -EINVAL) { + rc =3D smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, + NULL, &op, 1, NULL, NULL, NULL, dentry); + if (rc =3D=3D -EINVAL && dentry) { cifs_dbg(FYI, "invalid lease key, resending request without lease"); rc =3D smb2_compound_op(xid, tcon, cifs_sb, name, &oparms, - NULL, &(int){SMB2_OP_DELETE}, 1, + NULL, &op, 1, NULL, NULL, NULL, NULL); } return rc; } =20 +int +smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *nam= e, + struct cifs_sb_info *cifs_sb) +{ + return smb2_remove(xid, tcon, name, cifs_sb, NULL, true /* is_dir */); +} + +int +smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *na= me, + struct cifs_sb_info *cifs_sb, struct dentry *dentry) +{ + return smb2_remove(xid, tcon, name, cifs_sb, dentry, false /* is_dir */); +} + static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tc= on, const char *from_name, const char *to_name, struct cifs_sb_info *cifs_sb, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 BB19C26B771; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=W/WBxiM+MUNn5fC0m+KnSj5ivjn5VRwLoU8dqqe9TDkeiyUtfh41s4uDx2Nv6lgaZetznqKlujYHMfpk+3rJilZ8869SZ3A0RdOb7ebM1VG+zTmLTDfyCVmadKOjDwTOuPqCBYplN9dL+9GJV1R5ErP6NzaK4v2qGGD7v1gP9Co= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=Evg3ZKUpfOo+CCek78zw3g7JYbEmPfCRAo9GGRXMLTw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=nx1JOYhXWfmUHv7heziQx9I+LLUjuVkBoprnU7u4gNHLRt+t1aLvuOMyWSbaMD4Zxv0oHYpPLkk/sOuEx+PveUOdcAKCbK/0tiHg0k33/GTLkBKFfyTB393HsDpJP8/oEA0mFc/bRAJP6l3jII2scePSi3SpEo+05beE9ALVoTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MYb5lgmR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MYb5lgmR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A0D2C4CEF9; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=Evg3ZKUpfOo+CCek78zw3g7JYbEmPfCRAo9GGRXMLTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MYb5lgmRvtWY30A8xQ33KjLRglLvOpPYDMTaw3jUz1gUtjDqbgHsNYyuO4PmoqMTp f8v4agv2MOU4cBodeybsBF7oHJE0Zt06P9cagsNA58dAxBoO+xS3WacTbvUpjaSQxH 5uiL4NYTNJX/ZjEQ7juPAt+lNLozEfmtunWTtjwuiS/Hm1kWScpTxHhnl2IDBgZkxW w1zFHsOD2YTAJyXohsmfMfofVXBXZjrJ/xrCwaDlBUcbfzArynKvMFRoZXJnIOlbVR RUVPq9iq10NOVoM8a7DiySuLdc47SQM+qkYYaVk+zkRdV8lW1x/XgjJNthqt3sIsgD DrtZDaXigdC2Q== Received: by pali.im (Postfix) id 51A591308; Sun, 31 Aug 2025 14:36:37 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 32/35] cifs: Use cifs_rename_pending_delete() fallback also for rmdir() Date: Sun, 31 Aug 2025 14:35:59 +0200 Message-Id: <20250831123602.14037-33-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable When ->rmdir() callback fails on the -EBUSY error then use the silly rename functionality fallback. Removing of directories has exactly same problem with DELETE_PENDING state as removal of the files. Empty directory which is opened on Windows server will stay in DELETE_PENDING state until the last user on server does not close it. Directory itself is not immediately unlinked at remove call, like file. Note that currently the ->rmdir() callbacks do not return -EBUSY error. This will be implemented in follow up changes. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 545964cac9cd..abe3108e4963 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -1700,6 +1700,7 @@ static int cifs_rename_pending_delete(const unsigned int xid, struct cifs_tcon *tcon, const char *full_path, + bool is_dir, struct dentry *dentry) { int oplock =3D 0; @@ -1811,7 +1812,8 @@ cifs_rename_pending_delete(const unsigned int xid, .tcon =3D tcon, .cifs_sb =3D cifs_sb, .desired_access =3D DELETE, - .create_options =3D cifs_create_options(cifs_sb, CREATE_NOT_DIR), + .create_options =3D cifs_create_options(cifs_sb, + is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR), .disposition =3D FILE_OPEN, .path =3D full_path, .fid =3D &fid, @@ -1962,7 +1964,7 @@ int cifs_unlink(struct inode *dir, struct dentry *den= try) } else if (rc =3D=3D -ENOENT) { d_drop(dentry); } else if (rc =3D=3D -EBUSY) { - rc =3D cifs_rename_pending_delete(xid, tcon, full_path, dentry); + rc =3D cifs_rename_pending_delete(xid, tcon, full_path, false /* is_dir = */, dentry); if (rc =3D=3D 0) { cifs_mark_open_handles_for_deleted_file(inode, full_path); cifs_drop_nlink(inode); @@ -2298,6 +2300,9 @@ int cifs_rmdir(struct inode *inode, struct dentry *di= rentry) } =20 rc =3D server->ops->rmdir(xid, tcon, full_path, cifs_sb); + if (rc =3D=3D -EBUSY) + rc =3D cifs_rename_pending_delete(xid, tcon, full_path, true /* is_dir *= /, direntry); + cifs_put_tlink(tlink); =20 if (!rc) { --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 8F99826B2CE; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=lc6yui3MF8wXwRNZfjeFcVHIRNIPLXja0U7flIBnVLz8MMz91rYMN3jqEulHtJnO+1pb9Fs84O/e9s0oRU+OIPSRcaEG2e5UaWIDYM+4Lhp9OQC8iXD2uK/XTEybPfph+isNyKXkNcvYCV+MElTykptgVhZwLn4SCyLzgSBw3BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=hOE+inZuHZaLIQCHjscJllPWfxWi/52CVw/HvGIY4Ek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=B36PpX05E9LWehGUcI43IgZfoiWFmaz21qcsO3meKcBkE5fdbQHd+DVm9xLMtKphLSAdP7zc2pr3RNiwhR4CyM5eCfASQetSE+QqbZEWxIqunEh+fKws/dfEcQjZwXU45Y78vfRh0oCxMDcmBlXL2XH3RqIb1rI/bczB6ZzTwQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YOKqoz04; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YOKqoz04" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52E78C4CEFC; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=hOE+inZuHZaLIQCHjscJllPWfxWi/52CVw/HvGIY4Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOKqoz041/IhI6ZjPYvY3Fx8W7DB/sCLuLhBamA5ihjZ+K/NPkE4bsrf9J7sAE61b /CkDxMmEJqCzgRnqCfomIVxN4kxXOyiVjAR7645vJpZ5y/gWYgVprVGs8+rh3FzA91 Sz8yYtlyLKgDUM6LNrZmTUsnRqKJDGgtsCgPC5TszvtUAHAYg1BrY01vrT1LOsYMRO xWeamE4+Fx6LIsudGnTj/4nOeDgYls1NFQvLkSwXUT/npm++p+OhuI82/YRFk5m2qa FM8x/3ar4sTW90xOHC3IyNZIEkX+LSf1nMnYlisv8GlfdwMzALnNUUMEdZ0gFku4oy quci1DWzdBIaw== Received: by pali.im (Postfix) id 7984013DE; Sun, 31 Aug 2025 14:36:37 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 33/35] cifs: Add a new open flag CREATE_OPTION_EXCLUSIVE to open with deny all shared reservation Date: Sun, 31 Aug 2025 14:36:00 +0200 Message-Id: <20250831123602.14037-34-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable This is just an internal flag for cifs.ko code, not exported to userspace. It allows cifs.ko code to take an exclusive open with deny all shared reservation. It is going to be used by the upcoming fixes for the unlink() and rmdir() silly rename support. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifspdu.h | 1 + fs/smb/client/cifssmb.c | 12 ++++++++++-- fs/smb/client/smb2pdu.c | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index cb1f99d22dd7..90b0b82e23b1 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -395,6 +395,7 @@ #define CREATE_OPTIONS_MASK 0x007FFFFF #define CREATE_OPTION_READONLY 0x10000000 #define CREATE_OPTION_SPECIAL 0x20000000 /* system. NB not sent over w= ire */ +#define CREATE_OPTION_EXCLUSIVE 0x40000000 /* exclusive open, NB not set= over wire */ =20 /* ImpersonationLevel flags */ #define SECURITY_ANONYMOUS 0 diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 3a0452479a69..37bc0541bc21 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -1125,7 +1125,11 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tc= on *tcon, pSMB->OpenFlags |=3D cpu_to_le16(REQ_MORE_INFO); =20 pSMB->Mode =3D cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); - pSMB->Mode |=3D cpu_to_le16(SMBOPEN_DENY_NONE); + + if (create_options & CREATE_OPTION_EXCLUSIVE) + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_DENY_ALL); + else + pSMB->Mode |=3D cpu_to_le16(SMBOPEN_DENY_NONE); =20 if (create_options & CREATE_WRITE_THROUGH) pSMB->Mode |=3D cpu_to_le16(SMBOPEN_WRITE_THROUGH); @@ -1281,7 +1285,11 @@ CIFS_open(const unsigned int xid, struct cifs_open_p= arms *oparms, int *oplock, if (create_options & CREATE_OPTION_READONLY) req->FileAttributes |=3D cpu_to_le32(ATTR_READONLY); =20 - req->ShareAccess =3D cpu_to_le32(FILE_SHARE_ALL); + if (create_options & CREATE_OPTION_EXCLUSIVE) + req->ShareAccess =3D cpu_to_le32(FILE_NO_SHARE); + else + req->ShareAccess =3D cpu_to_le32(FILE_SHARE_ALL); + req->CreateDisposition =3D cpu_to_le32(disposition); req->CreateOptions =3D cpu_to_le32(create_options & CREATE_OPTIONS_MASK); =20 diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index a6c69b01ec6b..8315213d699e 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3034,7 +3034,11 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Se= rver_Info *server, req->DesiredAccess =3D cpu_to_le32(oparms->desired_access); /* File attributes ignored on open (used in create though) */ req->FileAttributes =3D cpu_to_le32(file_attributes); - req->ShareAccess =3D FILE_SHARE_ALL_LE; + + if (oparms->create_options & CREATE_OPTION_EXCLUSIVE) + req->ShareAccess =3D cpu_to_le32(FILE_NO_SHARE); + else + req->ShareAccess =3D cpu_to_le32(FILE_SHARE_ALL); =20 req->CreateDisposition =3D cpu_to_le32(oparms->disposition); req->CreateOptions =3D cpu_to_le32(oparms->create_options & CREATE_OPTION= S_MASK); --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 9F7F526F462; Sun, 31 Aug 2025 12:36:40 +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=1756643800; cv=none; b=EPW4zV3Ec42n54Ul2mPohdO+P+E1IeGd33TnN6BgoPTnRcMmHgMbf8QDyzISTBBBkUUCYmr+0J4JMHdGSA4bwUgnEolaXwpXkV3R9PQ9EtvOKYojQEHSQL48FNQ8JI2dVBVjblsOdflZMo2UIzO60pcqLIYD59mop5LbjVDvP9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643800; c=relaxed/simple; bh=UJXNLpnVpXaGQJ6zhTJTdyv91uluTCE+NBjb7TBcAcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=rl3EzX8LADnjrzvAg6msRottzci361e82ifKMDdpY5l7l5Sko9SU7yyh+0Q+oxsHHYFtqJBtOEpXBKXiONkg9VS0zr+li0uewV7IFxjcYhLMmErQEY0heoaD1SyPxcwRJmj/QAWAN6Uea7Y8Mvr4bL4XKg58oqx/3CKZNgXkiXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fHsiVXXI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fHsiVXXI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 128BAC4CEF8; Sun, 31 Aug 2025 12:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643800; bh=UJXNLpnVpXaGQJ6zhTJTdyv91uluTCE+NBjb7TBcAcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fHsiVXXINRKNTbpuvedxPPYy3k8d6xI1iseS9FtDnVQ3TKXa1cr467rRK3b/O34R1 COMATIhRjG+zpT4tICv94QA/YSdJ3TqkHj2bkLIFkEJ68nig2ocVu+o1hSQk3Lc+XC wGWsT62xF3NxP+I3ec1Ywc39gNQYor6gxSfcG6Dh/Hth9YDfniRh7KdK0Oh/dCPv2F jSVXSaKxZ+7DP2uEwdZA0TqBY1p2Ezmp0VShyB6/h7UGL9h2aN25hj53yrSoBNyQm8 8UC9qfUQVtcCrgVCxL8ui5XneKn42NQH2zHLWzcvQtSZJJHB3dJ8HHSEbjAZaNjE8/ UyofhXJZ8M/Xg== Received: by pali.im (Postfix) id A056B14A3; Sun, 31 Aug 2025 14:36:37 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 34/35] cifs: Use CREATE_OPTION_EXCLUSIVE when opening file/dir for SMB2+ non-POSIX unlink/rmdir Date: Sun, 31 Aug 2025 14:36:01 +0200 Message-Id: <20250831123602.14037-35-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Using of CREATE_OPTION_EXCLUSIVE against non-POSIX SMB2+ server ensures that the smb2_remove() function either success and removes the directory entry or it returns an error that file or directory is in use by other SMB client and silly rename is required to use. POSIX-based SMB2+ servers do not have this problems as they should unlink the directory entry immediately and not transition them into delete pending state. This allows the cifs_unlink() and cifs_rmdir() functions against non-POSIX servers to detect these failures via -EBUSY error from smb2_unlink() and smb2_rmdir() calls and fallbacks to cifs_rename_pending_delete() which implements silly rename. This is the final change which enables the silly rename functionality for the unlink and rmdir calls in SMB2+ dialects on mounted exports from Windows servers. With this change Linux unlink() and rmdir() syscalls called on SMB2+ mounts from Windows servers cause that on success the path would not exist anymore and new file or directory with that path can be created. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/smb2inode.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 0dd4a77dfb64..727349ed76b9 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -1351,6 +1351,23 @@ smb2_remove(const unsigned int xid, struct cifs_tcon= *tcon, const char *name, op =3D SMB2_OP_DELETE; op_flags =3D CREATE_NOT_DIR; } + + /* + * CREATE_OPTION_EXCLUSIVE ensures exclusive access to the path. + * If some other client has that path opened then our open fails. + * So together with remove operation it cause that either the path + * is immediately unlinked or the command fails with -EBUSY. + * It should not let the path in the delete pending state. + * + * When using POSIX extensions then we do not need any exclusive + * access to the file or directory. + * In this case the path is unlinked immediately even if it is opened + * by other client. Unlink fails only in case path is directory and + * that directory is not empty. + */ + if (!tcon->posix_extensions) + op_flags |=3D CREATE_OPTION_EXCLUSIVE; + oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, FILE_OPEN, OPEN_REPARSE_POINT | op_flags, --=20 2.20.1 From nobody Fri Oct 3 13:21:32 2025 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 BEFF026B942; Sun, 31 Aug 2025 12:36:38 +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=1756643798; cv=none; b=VCDXENep3TK6dkWIVwEVmMo7CVHwC+pNCspr3fwaxslejPiCpJJBz22ZB7py0Vi3PKLd0NX6tAY9z3rVGZ6NaHX6MeJZhrZQHJTvaS9+ug6qM2qJ7nUoY/pndYDntoMW6hVJHziPBP88JgQxb0HxtODvHll4M7mK1e85w1yY3H0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756643798; c=relaxed/simple; bh=BndpzTZJgGQ5KAp6GobzpPt6z1nG2dr2yHF9QYRGqmo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=pE8Z8UH+WFs9jb6HuVUFzyNbbvDizc5MvbQxr05Hk/BPNreHGs79drUpu5yBz3/oIRu3lG1eb/LDy5LXSmXFIiMk9ZOrNUrQVxKZMs9NR4yjxw59s8GfZ5MK704UxBQCGiIXKfZhod4FMFIZgYuO5hQw/31Ht6LvDWZ02Vk3his= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pk5HlR9a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pk5HlR9a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82794C4CEED; Sun, 31 Aug 2025 12:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756643798; bh=BndpzTZJgGQ5KAp6GobzpPt6z1nG2dr2yHF9QYRGqmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pk5HlR9a3ZewV0KhjQxW0El0EfA02bYCIaaQE6m2cMlHR3Fk7D8gQQqUcqEmrVr+v 0GzvPJJ3nBv+HBziEMURGVXiLp15Bx1Ohk3/H/lWk5CJbnya+9NCoaBo8ajZkL+0d2 otFD8GkLihydpkJrsU7iWD6xRk9G2HySxz3C7lczg4L8Q0wsRJLJHaX2gpJj5e+sNy ATuzhXUsRz0IdoDIlwV49UNK9VvFbNF5kgIuI3gVZb+Z4J6KBh8zyxISVj0oYVdeEI yMYNJFUce/W1OaSvf3kYe4RPkaqg1JWMTpK5fayPYaE6y/Z5w7+sx7Pe7VC8wzQyME bIXV3L39WdtzQ== Received: by pali.im (Postfix) id C97641857; Sun, 31 Aug 2025 14:36:37 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Steve French , Paulo Alcantara , ronnie sahlberg Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 35/35] cifs: Use CREATE_OPTION_EXCLUSIVE when doing SMB1 rmdir on NT server Date: Sun, 31 Aug 2025 14:36:02 +0200 Message-Id: <20250831123602.14037-36-pali@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250831123602.14037-1-pali@kernel.org> References: <20250831123602.14037-1-pali@kernel.org> 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-Transfer-Encoding: quoted-printable Windows NT servers just set the DELETE_PENDING flag when executing the SMB1 SMB_COM_DELETE_DIRECTORY command. This is opposite of the SMB_COM_DELETE command (can be used only on files) which completely removes the file and not just transition it into DELETE_PENDING state. This means that the SMB1 rmdir against Windows NT servers has same issues as SMB2+ rmdir and silly rename needs to be used. As in SMB2+ rmdir, use the CREATE_OPTION_EXCLUSIVE logic for issuing SMB1 rmdir when communicating with NT-based SMB1 server. With this change Linux rmdir() syscall called on SMB1 mounts from Windows NT servers cause that on success the path would not exist anymore and new file or directory with that path can be created. Signed-off-by: Pali Roh=C3=A1r --- fs/smb/client/cifssmb.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 37bc0541bc21..31638b71ee0c 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -823,8 +823,53 @@ CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon = *tcon, const char *name, int bytes_returned; int name_len; int remap =3D cifs_remap(cifs_sb); + struct cifs_open_parms oparms; + struct cifs_fid fid; + int oplock; =20 cifs_dbg(FYI, "In CIFSSMBRmDir\n"); + + /* + * Do not send SMB_COM_DELETE_DIRECTORY to NT servers. NT servers just + * sets the DELETE PENDING state on the directory and in case that + * directory is opened by some other client, it stay in this state and + * direntry stay present in the parent directory. + * + * So for NT servers use NT OPEN in exclusive mode. It fails when some + * other SMB client has the directory opened, and it triggers the + * sillyrename code path. After successful NT OPEN in exclusive mode, + * sets the DELETE PENDING state and close the directory. + * + * Servers with UNIX extensions should support SMB_COM_DELETE_DIRECTORY + * with correct UNIX semantics, so use this NT OPEN + DELETE PENDING + * only against non-UNIX NT servers. + */ + if ((tcon->ses->capabilities & CAP_NT_SMBS) && + !(cap_unix(tcon->ses) && + (le64_to_cpu(tcon->fsUnixInfo.Capability) & CIFS_UNIX_POSIX_PATH_OP= S_CAP))) { + oparms =3D CIFS_OPARMS(cifs_sb, tcon, name, DELETE, FILE_OPEN, + CREATE_OPTION_EXCLUSIVE | CREATE_NOT_FILE | OPEN_REPARSE_POINT, + ACL_NO_MODE); + oparms.fid =3D &fid; + oplock =3D 0; + rc =3D CIFS_open(xid, &oparms, &oplock, NULL); + if (rc) + return rc; + rc =3D CIFSSMBSetFileDisposition(xid, tcon, true, fid.netfid, current->t= gid); + /* + * some samba versions return -ENOENT when we try to set the + * file disposition here. Likely a samba bug, but work around + * it for now. This means that some cifsXXX files may hang + * around after they shouldn't. + * + * BB: remove this hack after more servers have the fix + */ + if (rc =3D=3D -ENOENT) + rc =3D 0; + CIFSSMBClose(xid, tcon, fid.netfid); + return rc; + } + RmDirRetry: rc =3D smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, (void **) &pSMBr); --=20 2.20.1