Skip to content

Commit 453382f

Browse files
ChenXiaoSongsmfrench
authored andcommitted
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>
1 parent c527e13 commit 453382f

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,11 @@ static int __init
19041904
init_cifs(void)
19051905
{
19061906
int rc = 0;
1907+
1908+
rc = smb2_init_maperror();
1909+
if (rc)
1910+
return rc;
1911+
19071912
cifs_proc_init();
19081913
INIT_LIST_HEAD(&cifs_tcp_ses_list);
19091914
/*

fs/smb/client/smb2maperror.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,20 @@ map_smb2_to_linux_error(char *buf, bool log_err)
7575
smb_EIO1(smb_eio_trace_smb2_received_error, le32_to_cpu(smb2err));
7676
return rc;
7777
}
78+
79+
int __init smb2_init_maperror(void)
80+
{
81+
unsigned int i;
82+
83+
/* Check whether the array is sorted in ascending order */
84+
for (i = 1; i < ARRAY_SIZE(smb2_error_map_table); i++) {
85+
if (smb2_error_map_table[i].smb2_status >=
86+
smb2_error_map_table[i - 1].smb2_status)
87+
continue;
88+
89+
pr_err("smb2_error_map_table array order is incorrect\n");
90+
return -EINVAL;
91+
}
92+
93+
return 0;
94+
}

fs/smb/client/smb2proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct smb_rqst;
2323
*****************************************************************
2424
*/
2525
int map_smb2_to_linux_error(char *buf, bool log_err);
26+
int smb2_init_maperror(void);
2627
int smb2_check_message(char *buf, unsigned int pdu_len, unsigned int len,
2728
struct TCP_Server_Info *server);
2829
unsigned int smb2_calc_size(void *buf);

0 commit comments

Comments
 (0)