* [PATCH 0/2] smb/server: fix byte order issues on big-endian systems
@ 2026-11-24 7:56 ZhangGuoDong
2026-11-24 7:56 ` [PATCH 1/2] smb/server: fix little-endian values in diagnostic messages ZhangGuoDong
2026-11-24 7:56 ` [PATCH 2/2] smb/server: fix file name conversion on big-endian systems ZhangGuoDong
0 siblings, 2 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24 7:56 UTC (permalink / raw)
To: linkinjeon, tom, senozhatsky, chenxiaosong; +Cc: linux-cifs, ZhangGuoDong
From: ZhangGuoDong <zhangguodong@kylinos.cn>
ZhangGuoDong (2):
smb/server: fix little-endian values in diagnostic messages
smb/server: fix file name conversion on big-endian systems
fs/smb/server/auth.c | 2 +-
fs/smb/server/oplock.c | 12 ++++++----
fs/smb/server/smb2pdu.c | 47 ++++++++++++++++++++------------------
fs/smb/server/smb_common.c | 2 +-
fs/smb/server/smbacl.c | 4 ++--
fs/smb/server/unicode.c | 4 ++--
6 files changed, 38 insertions(+), 33 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] smb/server: fix little-endian values in diagnostic messages
2026-11-24 7:56 [PATCH 0/2] smb/server: fix byte order issues on big-endian systems ZhangGuoDong
@ 2026-11-24 7:56 ` ZhangGuoDong
2026-11-24 7:56 ` [PATCH 2/2] smb/server: fix file name conversion on big-endian systems ZhangGuoDong
1 sibling, 0 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24 7:56 UTC (permalink / raw)
To: linkinjeon, tom, senozhatsky, chenxiaosong
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/server/auth.c | 2 +-
fs/smb/server/oplock.c | 12 ++++++----
fs/smb/server/smb2pdu.c | 47 ++++++++++++++++++++------------------
fs/smb/server/smb_common.c | 2 +-
fs/smb/server/smbacl.c | 4 ++--
5 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/fs/smb/server/auth.c b/fs/smb/server/auth.c
index f16a782f8602..7d9675ccfcbf 100644
--- a/fs/smb/server/auth.c
+++ b/fs/smb/server/auth.c
@@ -670,7 +670,7 @@ static void generate_smb3encryptionkey(struct ksmbd_conn *conn,
sess->smb3decryptionkey, SMB3_ENC_DEC_KEY_SIZE);
ksmbd_debug(AUTH, "generated SMB3 encryption/decryption keys\n");
- ksmbd_debug(AUTH, "Cipher type %d\n", conn->cipher_type);
+ ksmbd_debug(AUTH, "Cipher type %d\n", le16_to_cpu(conn->cipher_type));
ksmbd_debug(AUTH, "Session Id %llu\n", sess->id);
}
diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c
index 7c567180dbe1..d66baf0a8624 100644
--- a/fs/smb/server/oplock.c
+++ b/fs/smb/server/oplock.c
@@ -487,7 +487,7 @@ int opinfo_write_to_read(struct oplock_info *opinfo)
opinfo->level == SMB2_OPLOCK_LEVEL_EXCLUSIVE)) {
pr_err("bad oplock(0x%x)\n", opinfo->level);
if (opinfo->is_lease)
- pr_err("lease state(0x%x)\n", lease->state);
+ pr_err("lease state(0x%x)\n", le32_to_cpu(lease->state));
return -EINVAL;
}
opinfo->level = SMB2_OPLOCK_LEVEL_II;
@@ -528,7 +528,7 @@ int opinfo_write_to_none(struct oplock_info *opinfo)
opinfo->level == SMB2_OPLOCK_LEVEL_EXCLUSIVE)) {
pr_err("bad oplock(0x%x)\n", opinfo->level);
if (opinfo->is_lease)
- pr_err("lease state(0x%x)\n", lease->state);
+ pr_err("lease state(0x%x)\n", le32_to_cpu(lease->state));
return -EINVAL;
}
opinfo->level = SMB2_OPLOCK_LEVEL_NONE;
@@ -552,7 +552,7 @@ int opinfo_read_to_none(struct oplock_info *opinfo)
if (opinfo->level != SMB2_OPLOCK_LEVEL_II) {
pr_err("bad oplock(0x%x)\n", opinfo->level);
if (opinfo->is_lease)
- pr_err("lease state(0x%x)\n", lease->state);
+ pr_err("lease state(0x%x)\n", le32_to_cpu(lease->state));
return -EINVAL;
}
opinfo->level = SMB2_OPLOCK_LEVEL_NONE;
@@ -574,7 +574,8 @@ int lease_read_to_write(struct oplock_info *opinfo)
struct lease *lease = opinfo->o_lease;
if (!(lease->state & SMB2_LEASE_READ_CACHING_LE)) {
- ksmbd_debug(OPLOCK, "bad lease state(0x%x)\n", lease->state);
+ ksmbd_debug(OPLOCK, "bad lease state(0x%x)\n",
+ le32_to_cpu(lease->state));
return -EINVAL;
}
@@ -596,7 +597,8 @@ static int lease_none_upgrade(struct oplock_info *opinfo, __le32 new_state)
struct lease *lease = opinfo->o_lease;
if (!(lease->state == SMB2_LEASE_NONE_LE)) {
- ksmbd_debug(OPLOCK, "bad lease state(0x%x)\n", lease->state);
+ ksmbd_debug(OPLOCK, "bad lease state(0x%x)\n",
+ le32_to_cpu(lease->state));
return -EINVAL;
}
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 25e19ae10ad5..82afd32a0246 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -1661,7 +1661,7 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn,
pneg_ctxt->Ciphers[i] == SMB2_ENCRYPTION_AES256_CCM ||
pneg_ctxt->Ciphers[i] == SMB2_ENCRYPTION_AES256_GCM) {
ksmbd_debug(SMB, "Cipher ID = 0x%x\n",
- pneg_ctxt->Ciphers[i]);
+ le16_to_cpu(pneg_ctxt->Ciphers[i]));
conn->cipher_type = pneg_ctxt->Ciphers[i];
break;
}
@@ -1776,7 +1776,7 @@ static void decode_sign_cap_ctxt(struct ksmbd_conn *conn,
if (pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_HMAC_SHA256_LE ||
pneg_ctxt->SigningAlgorithms[i] == SIGNING_ALG_AES_CMAC_LE) {
ksmbd_debug(SMB, "Signing Algorithm ID = 0x%x\n",
- pneg_ctxt->SigningAlgorithms[i]);
+ le16_to_cpu(pneg_ctxt->SigningAlgorithms[i]));
conn->signing_negotiated = true;
conn->signing_algorithm =
pneg_ctxt->SigningAlgorithms[i];
@@ -2015,7 +2015,7 @@ int smb2_handle_negotiate(struct ksmbd_work *work)
get_rfc1002_len(work->request_buf));
if (status != STATUS_SUCCESS) {
pr_err("deassemble_neg_contexts error(0x%x)\n",
- status);
+ le32_to_cpu(status));
rsp->hdr.Status = status;
rc = -EINVAL;
kfree(conn->preauth_info);
@@ -3338,7 +3338,8 @@ int smb2_tree_disconnect(struct ksmbd_work *work)
WORK_BUFFERS(work, req, rsp);
if (!tcon) {
- ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);
+ ksmbd_debug(SMB, "Invalid tid %d\n",
+ le32_to_cpu(req->hdr.Id.SyncId.TreeId));
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
err = -ENOENT;
@@ -3425,7 +3426,8 @@ int smb2_session_logoff(struct ksmbd_work *work)
ksmbd_session_rpc_clear_list(sess);
if (ksmbd_tree_conn_session_logoff(sess)) {
- ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);
+ ksmbd_debug(SMB, "Invalid tid %d\n",
+ le32_to_cpu(req->hdr.Id.SyncId.TreeId));
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
smb2_set_err_rsp(work);
err = -ENOENT;
@@ -4974,7 +4976,7 @@ int smb2_open(struct ksmbd_work *work)
S_ISDIR(d_inode(path.dentry)->i_mode) &&
!(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) {
ksmbd_debug(SMB, "open() argument is a directory: %s, %x\n",
- name, req->CreateOptions);
+ name, le32_to_cpu(req->CreateOptions));
rsp->hdr.Status = STATUS_FILE_IS_A_DIRECTORY;
rc = -EIO;
goto err_out;
@@ -5373,7 +5375,7 @@ int smb2_open(struct ksmbd_work *work)
req_op_level = smb2_map_lease_to_oplock(lc->req_state);
ksmbd_debug(SMB,
"lease req for(%s) req oplock state 0x%x, lease state 0x%x\n",
- name, req_op_level, lc->req_state);
+ name, req_op_level, le32_to_cpu(lc->req_state));
rc = find_same_lease_key(conn, fp->f_ci, lc);
if (rc)
goto err_out1;
@@ -5627,7 +5629,7 @@ int smb2_open(struct ksmbd_work *work)
struct create_context *lease_ccontext;
ksmbd_debug(SMB, "lease granted on(%s) lease state 0x%x\n",
- name, opinfo->o_lease->state);
+ name, le32_to_cpu(opinfo->o_lease->state));
rsp->OplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
lease_ccontext = (struct create_context *)rsp->Buffer;
@@ -5839,7 +5841,7 @@ int smb2_open(struct ksmbd_work *work)
}
}
smb2_set_err_rsp(work);
- ksmbd_debug(SMB, "Error response: %x\n", rsp->hdr.Status);
+ ksmbd_debug(SMB, "Error response: %x\n", le32_to_cpu(rsp->hdr.Status));
}
if (dh_info.replay)
@@ -7121,7 +7123,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
if (!(fp->daccess & FILE_READ_EA_LE)) {
pr_err("Not permitted to read ext attr : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -7286,7 +7288,7 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp,
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
pr_err("no right to read the attributes : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -7393,7 +7395,7 @@ static int get_file_all_info(struct ksmbd_work *work,
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
ksmbd_debug(SMB, "no right to read the attributes : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -7749,7 +7751,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp,
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
pr_err("no right to read the attributes : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -7855,7 +7857,7 @@ static int get_file_attribute_tag_info(struct smb2_query_info_rsp *rsp,
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
pr_err("no right to read the attributes : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -7888,7 +7890,7 @@ static int find_file_posix_info(struct ksmbd_work *work,
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
pr_err("no right to read the attributes : 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -9205,7 +9207,7 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,
unsigned int buf_len)
{
if (!(fp->daccess & FILE_DELETE_LE)) {
- pr_err("no right to delete : 0x%x\n", fp->daccess);
+ pr_err("no right to delete : 0x%x\n", le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -9227,7 +9229,7 @@ static int set_file_disposition_info(struct ksmbd_work *work,
int err;
if (!(fp->daccess & FILE_DELETE_LE)) {
- pr_err("no right to delete : 0x%x\n", fp->daccess);
+ pr_err("no right to delete : 0x%x\n", le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -9362,7 +9364,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
file_info = (struct smb2_file_link_info *)buffer;
if (file_info->ReplaceIfExists && !(fp->daccess & FILE_DELETE_LE)) {
- pr_err("no right to delete : 0x%x\n", fp->daccess);
+ pr_err("no right to delete : 0x%x\n", le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -9382,7 +9384,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
{
if (!(fp->daccess & FILE_WRITE_EA_LE)) {
pr_err("Not permitted to write ext attr: 0x%x\n",
- fp->daccess);
+ le32_to_cpu(fp->daccess));
return -EACCES;
}
@@ -10081,7 +10083,7 @@ int smb2_read(struct ksmbd_work *work)
goto out;
if (!(fp->daccess & (FILE_READ_DATA_LE | FILE_READ_ATTRIBUTES_LE))) {
- pr_err("Not permitted to read : 0x%x\n", fp->daccess);
+ pr_err("Not permitted to read : 0x%x\n", le32_to_cpu(fp->daccess));
err = -EACCES;
goto out;
}
@@ -10553,7 +10555,7 @@ int smb2_write(struct ksmbd_work *work)
}
if (!(fp->daccess & (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE))) {
- pr_err("Not permitted to write : 0x%x\n", fp->daccess);
+ pr_err("Not permitted to write : 0x%x\n", le32_to_cpu(fp->daccess));
err = -EACCES;
goto out;
}
@@ -12802,7 +12804,8 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)
rsp->hdr.Status = STATUS_REQUEST_NOT_ACCEPTED;
ksmbd_debug(OPLOCK,
"req lease state: 0x%x, expected state: 0x%x\n",
- req->LeaseState, lease->new_state);
+ le32_to_cpu(req->LeaseState),
+ le32_to_cpu(lease->new_state));
goto err_unlock;
}
diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
index e7a987af64ba..6595d40b06bc 100644
--- a/fs/smb/server/smb_common.c
+++ b/fs/smb/server/smb_common.c
@@ -692,7 +692,7 @@ static void smb_shared_mode_error(int error, struct ksmbd_file *prev_fp,
{
ksmbd_debug(SMB, "%s\n", shared_mode_errors[error]);
ksmbd_debug(SMB, "Current mode: 0x%x Desired mode: 0x%x\n",
- prev_fp->saccess, curr_fp->daccess);
+ le32_to_cpu(prev_fp->saccess), le32_to_cpu(curr_fp->daccess));
}
/*
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 49530198a2b6..91175cc496ce 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -956,8 +956,8 @@ int parse_sec_desc(const struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
dacloffset = le32_to_cpu(pntsd->dacloffset);
ksmbd_debug(SMB,
"revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n",
- pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset),
- le32_to_cpu(pntsd->gsidoffset),
+ le16_to_cpu(pntsd->revision), le16_to_cpu(pntsd->type),
+ le32_to_cpu(pntsd->osidoffset), le32_to_cpu(pntsd->gsidoffset),
le32_to_cpu(pntsd->sacloffset), dacloffset);
pntsd_type = le16_to_cpu(pntsd->type);
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] smb/server: fix file name conversion on big-endian systems
2026-11-24 7:56 [PATCH 0/2] smb/server: fix byte order issues on big-endian systems ZhangGuoDong
2026-11-24 7:56 ` [PATCH 1/2] smb/server: fix little-endian values in diagnostic messages ZhangGuoDong
@ 2026-11-24 7:56 ` ZhangGuoDong
1 sibling, 0 replies; 3+ messages in thread
From: ZhangGuoDong @ 2026-11-24 7:56 UTC (permalink / raw)
To: linkinjeon, tom, senozhatsky, chenxiaosong
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: 0c180317c654 ("ksmbd: add support for surrogate pair conversion")
Signed-off-by: ZhangGuoDong <zhangguodong@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/server/unicode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/smb/server/unicode.c b/fs/smb/server/unicode.c
index 85e6791745ec..8841f8a83026 100644
--- a/fs/smb/server/unicode.c
+++ b/fs/smb/server/unicode.c
@@ -80,7 +80,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;
@@ -404,7 +404,7 @@ int smbConvertToUTF16(__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:56 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:56 [PATCH 0/2] smb/server: fix byte order issues on big-endian systems ZhangGuoDong
2026-11-24 7:56 ` [PATCH 1/2] smb/server: fix little-endian values in diagnostic messages ZhangGuoDong
2026-11-24 7:56 ` [PATCH 2/2] smb/server: 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