lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250831123602.14037-26-pali@kernel.org>
Date: Sun, 31 Aug 2025 14:35:52 +0200
From: Pali Rohár <pali@...nel.org>
To: Steve French <sfrench@...ba.org>,
	Paulo Alcantara <pc@...guebit.com>,
	ronnie sahlberg <ronniesahlberg@...il.com>
Cc: linux-cifs@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 25/35] cifs: Add a new callback rename_opened_file() for renaming an opened file

Implement it for all SMB dialects. It will be used by follow up changes.

Signed-off-by: Pali Rohár <pali@...nel.org>
---
 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 cifs_tcon *tcon,
 	return CIFSSMBSetFileDisposition(xid, tcon, delete_pending, fid->netfid, current->tgid);
 }
 
+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 = strrchr(new_full_path, CIFS_DIR_SEP(cifs_sb));
+	if (name)
+		name++;
+	else
+		name = 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 = {
 	.unlink = CIFSSMBDelFile,
 	.rename_pending_delete = cifs_rename_pending_delete,
 	.rename = CIFSSMBRename,
+	.rename_opened_file = cifs_rename_opened_file,
 	.create_hardlink = CIFSCreateHardLink,
 	.query_symlink = cifs_query_symlink,
 	.get_reparse_point_buffer = 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 cifs_tcon *tcon,
 	return SMB2_set_disp(xid, tcon, fid->persistent_fid, fid->volatile_fid, delete_pending);
 }
 
+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_fid,
+				  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 = {
 	.rmdir = smb2_rmdir,
 	.unlink = smb2_unlink,
 	.rename = smb2_rename_path,
+	.rename_opened_file = smb2_rename_opened_file,
 	.create_hardlink = smb2_create_hardlink,
 	.get_reparse_point_buffer = smb2_get_reparse_point_buffer,
 	.query_mf_symlink = smb3_query_mf_symlink,
@@ -5428,6 +5438,7 @@ struct smb_version_operations smb21_operations = {
 	.rmdir = smb2_rmdir,
 	.unlink = smb2_unlink,
 	.rename = smb2_rename_path,
+	.rename_opened_file = smb2_rename_opened_file,
 	.create_hardlink = smb2_create_hardlink,
 	.get_reparse_point_buffer = smb2_get_reparse_point_buffer,
 	.query_mf_symlink = smb3_query_mf_symlink,
@@ -5536,6 +5547,7 @@ struct smb_version_operations smb30_operations = {
 	.rmdir = smb2_rmdir,
 	.unlink = smb2_unlink,
 	.rename = smb2_rename_path,
+	.rename_opened_file = smb2_rename_opened_file,
 	.create_hardlink = smb2_create_hardlink,
 	.get_reparse_point_buffer = smb2_get_reparse_point_buffer,
 	.query_mf_symlink = smb3_query_mf_symlink,
@@ -5653,6 +5665,7 @@ struct smb_version_operations smb311_operations = {
 	.rmdir = smb2_rmdir,
 	.unlink = smb2_unlink,
 	.rename = smb2_rename_path,
+	.rename_opened_file = smb2_rename_opened_file,
 	.create_hardlink = smb2_create_hardlink,
 	.get_reparse_point_buffer = smb2_get_reparse_point_buffer,
 	.query_mf_symlink = 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_tcon *tcon,
 			     SMB2_O_INFO_FILE, 0, 1, (void **)&buf, &len);
 }
 
+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 = {};
+	unsigned int size[2];
+	void *data[2];
+	int rc;
+
+	data[1] = cifs_convert_path_to_utf16(new_full_path, cifs_sb);
+	if (!data[1])
+		return -ENOMEM;
+	size[1] = 2 * UniStrnlen((wchar_t *)data[1], PATH_MAX);
+
+	rename_info.ReplaceIfExists = overwrite;
+	rename_info.RootDirectory = 0;
+	rename_info.FileNameLength = cpu_to_le32(size[1]);
+	data[0] = &rename_info;
+	size[0] = sizeof(rename_info);
+
+	rc = 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 *tcon,
+			      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 *tcon,
-- 
2.20.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ