summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChenXiaoSong <chenxiaosong@kylinos.cn>2025-12-24 04:33:28 +0300
committerSteve French <stfrench@microsoft.com>2026-02-09 06:24:41 +0300
commit453382f15b0e9b74fc83d364ffa68fa5e4806485 (patch)
treee70915c23695d601f8a4fa4661805a912e4ac7de
parentc527e13a7a6628176655d70ff166f0f594a77984 (diff)
downloadlinux-453382f15b0e9b74fc83d364ffa68fa5e4806485.tar.xz
smb/client: check whether smb2_error_map_table is sorted in ascending order
Although the array is sorted at build time, verify the ordering again when cifs.ko is loaded to avoid potential regressions introduced by future script changes. Suggested-by: David Howells <dhowells@redhat.com> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Reviewed-by: David Howells <dhowells@redhat.com> Link: https://lore.kernel.org/linux-cifs/20260106071507.1420900-4-chenxiaosong.chenxiaosong@linux.dev/ Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
-rw-r--r--fs/smb/client/cifsfs.c5
-rw-r--r--fs/smb/client/smb2maperror.c17
-rw-r--r--fs/smb/client/smb2proto.h1
3 files changed, 23 insertions, 0 deletions
diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index c96d09be11a5..87d8c93fcff4 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -1904,6 +1904,11 @@ static int __init
init_cifs(void)
{
int rc = 0;
+
+ rc = smb2_init_maperror();
+ if (rc)
+ return rc;
+
cifs_proc_init();
INIT_LIST_HEAD(&cifs_tcp_ses_list);
/*
diff --git a/fs/smb/client/smb2maperror.c b/fs/smb/client/smb2maperror.c
index 42fec9abeac7..c36cfe707bf1 100644
--- a/fs/smb/client/smb2maperror.c
+++ b/fs/smb/client/smb2maperror.c
@@ -75,3 +75,20 @@ map_smb2_to_linux_error(char *buf, bool log_err)
smb_EIO1(smb_eio_trace_smb2_received_error, le32_to_cpu(smb2err));
return rc;
}
+
+int __init smb2_init_maperror(void)
+{
+ unsigned int i;
+
+ /* Check whether the array is sorted in ascending order */
+ for (i = 1; i < ARRAY_SIZE(smb2_error_map_table); i++) {
+ if (smb2_error_map_table[i].smb2_status >=
+ smb2_error_map_table[i - 1].smb2_status)
+ continue;
+
+ pr_err("smb2_error_map_table array order is incorrect\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h
index abd62cb2cecd..c7759e37d975 100644
--- a/fs/smb/client/smb2proto.h
+++ b/fs/smb/client/smb2proto.h
@@ -23,6 +23,7 @@ struct smb_rqst;
*****************************************************************
*/
int map_smb2_to_linux_error(char *buf, bool log_err);
+int smb2_init_maperror(void);
int smb2_check_message(char *buf, unsigned int pdu_len, unsigned int len,
struct TCP_Server_Info *server);
unsigned int smb2_calc_size(void *buf);