Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] smb/client: fix byte order issues on big-endian systems
@ 2026-11-24  7:59 ZhangGuoDong
  2026-11-24  7:59 ` [PATCH 1/2] smb/client: fix little-endian values in diagnostic messages ZhangGuoDong
  2026-11-24  7:59 ` [PATCH 2/2] smb/client: fix file name conversion on big-endian systems ZhangGuoDong
  0 siblings, 2 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24  7:59 UTC (permalink / raw)
  To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze
  Cc: linux-cifs, ZhangGuoDong

From: ZhangGuoDong <zhangguodong@kylinos.cn>

ZhangGuoDong (2):
  smb/client: fix little-endian values in diagnostic messages
  smb/client: fix file name conversion on big-endian systems

 fs/smb/client/cifs_unicode.c  | 6 +++---
 fs/smb/client/cifsacl.c       | 3 ++-
 fs/smb/client/sess.c          | 2 +-
 fs/smb/client/smb1debug.c     | 5 +++--
 fs/smb/client/smb1misc.c      | 4 ++--
 fs/smb/client/smb2ops.c       | 5 +++--
 fs/smb/client/smb2pdu.c       | 4 ++--
 fs/smb/client/smb2transport.c | 6 +++---
 fs/smb/client/transport.c     | 2 +-
 9 files changed, 20 insertions(+), 17 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] smb/client: fix little-endian values in diagnostic messages
  2026-11-24  7:59 [PATCH 0/2] smb/client: fix byte order issues on big-endian systems ZhangGuoDong
@ 2026-11-24  7:59 ` ZhangGuoDong
  2026-11-24  7:59 ` [PATCH 2/2] smb/client: fix file name conversion on big-endian systems ZhangGuoDong
  1 sibling, 0 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24  7:59 UTC (permalink / raw)
  To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze
  Cc: linux-cifs, ZhangGuoDong, ChenXiaoSong

From: ZhangGuoDong <zhangguodong@kylinos.cn>

Convert to CPU byte order to avoid incorrect debug log
on big-endian architectures.

Signed-off-by: ZhangGuoDong <zhangguodong@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/cifsacl.c       | 3 ++-
 fs/smb/client/sess.c          | 2 +-
 fs/smb/client/smb1debug.c     | 5 +++--
 fs/smb/client/smb1misc.c      | 4 ++--
 fs/smb/client/smb2ops.c       | 5 +++--
 fs/smb/client/smb2pdu.c       | 4 ++--
 fs/smb/client/smb2transport.c | 6 +++---
 fs/smb/client/transport.c     | 2 +-
 8 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/fs/smb/client/cifsacl.c b/fs/smb/client/cifsacl.c
index d8f30c35cbe5..b23cb226c4d3 100644
--- a/fs/smb/client/cifsacl.c
+++ b/fs/smb/client/cifsacl.c
@@ -1375,7 +1375,8 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
 	gsidoffset = le32_to_cpu(pntsd->gsidoffset);
 	dacloffset = le32_to_cpu(pntsd->dacloffset);
 	cifs_dbg(NOISY, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n",
-		 pntsd->revision, pntsd->type, osidoffset, gsidoffset,
+		 le16_to_cpu(pntsd->revision), le16_to_cpu(pntsd->type),
+		 osidoffset, gsidoffset,
 		 le32_to_cpu(pntsd->sacloffset), dacloffset);
 	fattr->cf_uid = cifs_sb->ctx->linux_uid;
 	fattr->cf_gid = cifs_sb->ctx->linux_gid;
diff --git a/fs/smb/client/sess.c b/fs/smb/client/sess.c
index fe006e9f2e10..468bdeae2de6 100644
--- a/fs/smb/client/sess.c
+++ b/fs/smb/client/sess.c
@@ -672,7 +672,7 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	}
 	if (pblob->MessageType != NtLmChallenge) {
 		cifs_dbg(VFS, "Incorrect message type %d\n",
-			 pblob->MessageType);
+			 le32_to_cpu(pblob->MessageType));
 		return -EINVAL;
 	}
 
diff --git a/fs/smb/client/smb1debug.c b/fs/smb/client/smb1debug.c
index e2d013e751e5..f4a08acd7242 100644
--- a/fs/smb/client/smb1debug.c
+++ b/fs/smb/client/smb1debug.c
@@ -15,8 +15,9 @@ void cifs_dump_detail(void *buf, size_t buf_len, struct TCP_Server_Info *server)
 	struct smb_hdr *smb = buf;
 
 	cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d Wct: %d\n",
-		 smb->Command, smb->Status.CifsError, smb->Flags,
-		 smb->Flags2, smb->Mid, smb->Pid, smb->WordCount);
+		 smb->Command, le32_to_cpu(smb->Status.CifsError), smb->Flags,
+		 le16_to_cpu(smb->Flags2), le16_to_cpu(smb->Mid),
+		 le16_to_cpu(smb->Pid), smb->WordCount);
 	if (!server->ops->check_message(buf, buf_len, server->total_read, server)) {
 		cifs_dbg(VFS, "smb buf %p len %u\n", smb,
 			 server->ops->calc_smb_size(smb));
diff --git a/fs/smb/client/smb1misc.c b/fs/smb/client/smb1misc.c
index cdfbbff24b72..4005a97c0ac5 100644
--- a/fs/smb/client/smb1misc.c
+++ b/fs/smb/client/smb1misc.c
@@ -95,14 +95,14 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
 			pnotify = (struct file_notify_information *)
 				((char *)&pSMBr->hdr.Protocol + data_offset);
 			cifs_dbg(FYI, "dnotify on %s Action: 0x%x\n",
-				 pnotify->FileName, pnotify->Action);
+				 pnotify->FileName, le32_to_cpu(pnotify->Action));
 			/*   cifs_dump_mem("Rcvd notify Data: ",buf,
 				sizeof(struct smb_hdr)+60); */
 			return true;
 		}
 		if (pSMBr->hdr.Status.CifsError) {
 			cifs_dbg(FYI, "notify err 0x%x\n",
-				 pSMBr->hdr.Status.CifsError);
+				 le32_to_cpu(pSMBr->hdr.Status.CifsError));
 			return true;
 		}
 		return false;
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 298f549bd7ed..9c16839576e9 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -454,8 +454,9 @@ smb2_dump_detail(void *buf, size_t buf_len, struct TCP_Server_Info *server)
 	struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
 
 	cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
-		 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
-		 shdr->Id.SyncId.ProcessId);
+		 le16_to_cpu(shdr->Command), le32_to_cpu(shdr->Status),
+		 le32_to_cpu(shdr->Flags), le64_to_cpu(shdr->MessageId),
+		 le32_to_cpu(shdr->Id.SyncId.ProcessId));
 	if (!server->ops->check_message(buf, buf_len, server->total_read, server)) {
 		cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
 				server->ops->calc_smb_size(buf));
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index b26bfb4bd91a..21e8a78f6104 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -278,7 +278,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 		if (smb2_command != SMB2_TREE_DISCONNECT) {
 			spin_unlock(&tcon->tc_lock);
 			cifs_tcon_dbg(FYI, "can not send cmd %d while umounting\n",
-				      smb2_command);
+				      le16_to_cpu(smb2_command));
 			return -ENODEV;
 		}
 	}
@@ -1294,7 +1294,7 @@ SMB2_negotiate(const unsigned int xid,
 		goto neg_exit;
 	}
 
-	cifs_dbg(FYI, "mode 0x%x\n", rsp->SecurityMode);
+	cifs_dbg(FYI, "mode 0x%x\n", le16_to_cpu(rsp->SecurityMode));
 
 	switch (dialect) {
 	case SMB20_PROT_ID:
diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c
index 080864b24a0c..51dca16463d8 100644
--- a/fs/smb/client/smb2transport.c
+++ b/fs/smb/client/smb2transport.c
@@ -380,7 +380,7 @@ generate_smb3signingkey(struct cifs_ses *ses,
 	 */
 	cifs_dbg(VFS, "Session Id    %*ph\n", (int)sizeof(ses->Suid),
 			&ses->Suid);
-	cifs_dbg(VFS, "Cipher type   %d\n", server->cipher_type);
+	cifs_dbg(VFS, "Cipher type   %d\n", le16_to_cpu(server->cipher_type));
 	cifs_dbg(VFS, "Session Key   %*ph\n",
 		 (int)ses->auth_key.len, ses->auth_key.response);
 	cifs_dbg(VFS, "Signing Key   %*ph\n",
@@ -570,7 +570,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 	/* Do not need to verify session setups with signature "BSRSPYL " */
 	if (memcmp(shdr->Signature, "BSRSPYL ", 8) == 0)
 		cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
-			 shdr->Command);
+			 le16_to_cpu(shdr->Command));
 
 	/*
 	 * Save off the original signature so we can modify the smb and check
@@ -588,7 +588,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
 	if (crypto_memneq(server_response_sig, shdr->Signature,
 			  SMB2_SIGNATURE_SIZE)) {
 		cifs_dbg(VFS, "sign fail cmd 0x%x message id 0x%llx\n",
-			shdr->Command, shdr->MessageId);
+			 le16_to_cpu(shdr->Command), le64_to_cpu(shdr->MessageId));
 		return -EACCES;
 	} else
 		return 0;
diff --git a/fs/smb/client/transport.c b/fs/smb/client/transport.c
index c51f99d7be4b..cbeead6e522b 100644
--- a/fs/smb/client/transport.c
+++ b/fs/smb/client/transport.c
@@ -101,7 +101,7 @@ void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *midEntry)
 			       midEntry->when_sent, midEntry->when_received);
 		if (cifsFYI & CIFS_TIMER) {
 			pr_debug("slow rsp: cmd %d mid %llu A: 0x%lx S: 0x%lx R: 0x%lx\n",
-				 midEntry->command, midEntry->mid,
+				 smb_cmd, midEntry->mid,
 				 now - midEntry->when_alloc,
 				 now - midEntry->when_sent,
 				 now - midEntry->when_received);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] smb/client: fix file name conversion on big-endian systems
  2026-11-24  7:59 [PATCH 0/2] smb/client: fix byte order issues on big-endian systems ZhangGuoDong
  2026-11-24  7:59 ` [PATCH 1/2] smb/client: fix little-endian values in diagnostic messages ZhangGuoDong
@ 2026-11-24  7:59 ` ZhangGuoDong
  1 sibling, 0 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24  7:59 UTC (permalink / raw)
  To: linkinjeon, pc, ronniesahlberg, sprasad, tom, bharathsm, metze
  Cc: linux-cifs, ZhangGuoDong, ChenXiaoSong

From: ZhangGuoDong <zhangguodong@kylinos.cn>

Use CPU byte order for temporary UTF-16 buffers to avoid incorrect
file name conversion on big-endian architectures.

Fixes: b29103076bec ("Fix to convert SURROGATE PAIR")
Signed-off-by: ZhangGuoDong <zhangguodong@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/cifs_unicode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/smb/client/cifs_unicode.c b/fs/smb/client/cifs_unicode.c
index 4a8a591f4bca..264595633b1e 100644
--- a/fs/smb/client/cifs_unicode.c
+++ b/fs/smb/client/cifs_unicode.c
@@ -92,7 +92,7 @@ convert_sfm_char(const __u16 src_char, char *target)
 /*
  * cifs_mapchar - convert a host-endian char to proper char in codepage
  * @target - where converted character should be copied
- * @src_char - 2 byte host-endian source character
+ * @from - 2 byte host-endian source character
  * @cp - codepage to which character should be converted
  * @map_type - How should the 7 NTFS/SMB reserved characters be mapped to UCS2?
  *
@@ -126,7 +126,7 @@ cifs_mapchar(char *target, const __u16 *from, const struct nls_table *cp,
 	/* convert SURROGATE_PAIR and IVS */
 	if (strcmp(cp->charset, "utf8"))
 		goto unknown;
-	len = utf16s_to_utf8s(from, 3, UTF16_LITTLE_ENDIAN, target, 6);
+	len = utf16s_to_utf8s(from, 3, UTF16_HOST_ENDIAN, target, 6);
 	if (len <= 0)
 		goto unknown;
 	return len;
@@ -518,7 +518,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
 			} else
 				goto unknown;
 			ret  = utf8s_to_utf16s(source + i, charlen,
-					       UTF16_LITTLE_ENDIAN,
+					       UTF16_HOST_ENDIAN,
 					       wchar_to, 6);
 			if (ret < 0)
 				goto unknown;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24  7:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  7:59 [PATCH 0/2] smb/client: fix byte order issues on big-endian systems ZhangGuoDong
2026-11-24  7:59 ` [PATCH 1/2] smb/client: fix little-endian values in diagnostic messages ZhangGuoDong
2026-11-24  7:59 ` [PATCH 2/2] smb/client: fix file name conversion on big-endian systems ZhangGuoDong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox