lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208062100.3268777-17-chenxiaosong.chenxiaosong@linux.dev>
Date: Mon,  8 Dec 2025 14:20:46 +0800
From: chenxiaosong.chenxiaosong@...ux.dev
To: sfrench@...ba.org,
	smfrench@...il.com,
	linkinjeon@...nel.org,
	linkinjeon@...ba.org
Cc: linux-cifs@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	liuzhengyuan@...inos.cn,
	huhai@...inos.cn,
	liuyun01@...inos.cn,
	ChenXiaoSong <chenxiaosong@...inos.cn>
Subject: [PATCH 16/30] smb/client: sort nt_errs array

From: ChenXiaoSong <chenxiaosong@...inos.cn>

Sort the array in ascending order, and then we can use binary search
algorithm to quickly find the target NT error code.

The array is sorted only once when cifs.ko is loaded.

Signed-off-by: ChenXiaoSong <chenxiaosong@...inos.cn>
---
 fs/smb/client/netmisc.c | 4 ++++
 fs/smb/client/nterr.c   | 5 ++++-
 fs/smb/client/nterr.h   | 3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 4e6312593d6f..c6fa1389683b 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -801,6 +801,8 @@ static unsigned int ntstatus_to_dos_num = sizeof(ntstatus_to_dos_map) /
 
 /* cmp_ntstatus_to_dos */
 DEFINE_CMP_FUNC(ntstatus_to_dos, ntstatus);
+/* cmp_nt_err_code_struct */
+DEFINE_CMP_FUNC(nt_err_code_struct, nt_errcode);
 
 /* search_in_ntstatus_to_dos_map */
 DEFINE_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
@@ -1075,6 +1077,8 @@ void smb_init_maperror(void)
 	/* Sort in ascending order */
 	sort(ntstatus_to_dos_map, ntstatus_to_dos_num,
 	     sizeof(struct ntstatus_to_dos), cmp_ntstatus_to_dos, NULL);
+	sort(nt_errs, nt_err_num, sizeof(struct nt_err_code_struct),
+	     cmp_nt_err_code_struct, NULL);
 }
 
 #if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
diff --git a/fs/smb/client/nterr.c b/fs/smb/client/nterr.c
index 77f84767b7df..8d0007db6af9 100644
--- a/fs/smb/client/nterr.c
+++ b/fs/smb/client/nterr.c
@@ -11,7 +11,7 @@
 #include <linux/fs.h>
 #include "nterr.h"
 
-const struct nt_err_code_struct nt_errs[] = {
+struct nt_err_code_struct nt_errs[] = {
 	{"NT_STATUS_OK", NT_STATUS_OK},
 	{"NT_STATUS_PENDING", NT_STATUS_PENDING},
 	{"NT_STATUS_MEDIA_CHANGED", NT_STATUS_MEDIA_CHANGED},
@@ -686,3 +686,6 @@ const struct nt_err_code_struct nt_errs[] = {
 	 NT_STATUS_NO_PREAUTH_INTEGRITY_HASH_OVERLAP},
 	{NULL, 0}
 };
+
+unsigned int nt_err_num = sizeof(nt_errs) /
+			  sizeof(struct nt_err_code_struct);
diff --git a/fs/smb/client/nterr.h b/fs/smb/client/nterr.h
index 81f1a78cf41f..e85e65278fb5 100644
--- a/fs/smb/client/nterr.h
+++ b/fs/smb/client/nterr.h
@@ -20,7 +20,8 @@ struct nt_err_code_struct {
 	__u32 nt_errcode;
 };
 
-extern const struct nt_err_code_struct nt_errs[];
+extern struct nt_err_code_struct nt_errs[];
+extern unsigned int nt_err_num;
 
 /* Win32 Status codes. */
 #define NT_STATUS_MORE_ENTRIES         0x0105
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ