[PATCH v2 22/22] devtools: check for some reentrant function

Jie Hai haijie1 at huawei.com
Tue Nov 14 09:41:33 CET 2023


Multiple threads calling the same function may cause condition
race issues, which often leads to abnormal behavior and can cause
more serious vulnerabilities such as abnormal termination, denial
of service, and compromised data integrity.

This patch adds check in checkpatches.sh for strtok, which is
non-reentrant.

Signed-off-by: Jie Hai <haijie1 at huawei.com>
---
 devtools/checkpatches.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 066449d147e8..0a936219c069 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -119,6 +119,14 @@ check_forbidden_additions() { # <patch>
 		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
 		"$1" || res=1
 
+	# refrain from using some non-reentrant functions
+	awk -v FOLDERS="lib drivers app examples" \
+		-v EXPRESSIONS="strtok\\\(" \
+		-v RET_ON_FAIL=1 \
+		-v MESSAGE='Using non-reentrant function strtok, prefer strtok_s' \
+		-f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \
+		"$1" || res=1
+
 	# refrain from using some pthread functions
 	awk -v FOLDERS="lib drivers app examples" \
 		-v EXPRESSIONS="pthread_(create|join|detach|set(_?name_np|affinity_np)|attr_set(inheritsched|schedpolicy))\\\(" \
-- 
2.30.0



More information about the dev mailing list