Skip to content

Commit 010ad1e

Browse files
tangyoulingsmfrench
authored andcommitted
smb/client: check if ntstatus_to_dos_map is sorted
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. We are going to define 3 functions to check the sort results, introduce the macro DEFINE_CHECK_SORT_FUNC() to reduce duplicate code. Signed-off-by: Youling Tang <tangyouling@kylinos.cn> Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3c6c23e commit 010ad1e

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,12 @@ init_cifs(void)
19111911
{
19121912
int rc = 0;
19131913

1914+
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
1915+
rc = smb1_init_maperror();
1916+
if (rc)
1917+
return rc;
1918+
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
1919+
19141920
rc = smb2_init_maperror();
19151921
if (rc)
19161922
return rc;

fs/smb/client/smb1maperror.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,35 @@ map_and_check_smb_error(struct TCP_Server_Info *server,
256256

257257
return rc;
258258
}
259+
260+
#define DEFINE_CHECK_SORT_FUNC(__array, __field) \
261+
static int __init __array ## _is_sorted(void) \
262+
{ \
263+
unsigned int i; \
264+
\
265+
/* Check whether the array is sorted in ascending order */ \
266+
for (i = 1; i < ARRAY_SIZE(__array); i++) { \
267+
if (__array[i].__field >= \
268+
__array[i - 1].__field) \
269+
continue; \
270+
\
271+
pr_err(#__array " array order is incorrect\n"); \
272+
return -EINVAL; \
273+
} \
274+
\
275+
return 0; \
276+
}
277+
278+
/* ntstatus_to_dos_map_is_sorted */
279+
DEFINE_CHECK_SORT_FUNC(ntstatus_to_dos_map, ntstatus);
280+
281+
int __init smb1_init_maperror(void)
282+
{
283+
int rc;
284+
285+
rc = ntstatus_to_dos_map_is_sorted();
286+
if (rc)
287+
return rc;
288+
289+
return rc;
290+
}

fs/smb/client/smb1proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ int cifs_verify_signature(struct smb_rqst *rqst,
234234
* smb1maperror.c
235235
*/
236236
int map_smb_to_linux_error(char *buf, bool logErr);
237+
int smb1_init_maperror(void);
237238
int map_and_check_smb_error(struct TCP_Server_Info *server,
238239
struct mid_q_entry *mid, bool logErr);
239240

0 commit comments

Comments
 (0)