From 9acbc4b1d2b0b93876b5d279cffdeb1e336033ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=82=A3=E5=87=A0?= <2078634206@qq.com> Date: Fri, 21 Aug 2026 00:44:59 +0800 Subject: [PATCH] tkernel: killblock/killprotect: fix W=1 warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rule parsers copy tokens with strncpy() using a bound derived from strlen() of the source, which triggers -Wstringop-truncation, and the two match helpers lack a prototype declaration, triggering -Wmissing-prototypes under W=1 builds. Replace the strncpy() plus manual NUL termination pairs with strscpy(), which has identical truncation semantics, and make kill_block_whitelist_match() and kill_protect_blacklist_match() static since they have no callers outside their translation units. Upstream status: downstream-only Signed-off-by: 陈那几 <2078634206@qq.com> --- kernel/tkernel/killblock/kill_block.c | 14 ++++---------- kernel/tkernel/killprotect/kill_protect.c | 10 +++------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/kernel/tkernel/killblock/kill_block.c b/kernel/tkernel/killblock/kill_block.c index 50e8484bd51d..9d4a95eea56d 100644 --- a/kernel/tkernel/killblock/kill_block.c +++ b/kernel/tkernel/killblock/kill_block.c @@ -91,15 +91,9 @@ static ssize_t whitelist_write(struct file *file, const char __user *ubuf, if (!rule) return -ENOMEM; - cnt = min_t(size_t, TASK_COMM_LEN - 1, strlen(token[1])); - strncpy(rule->src_comm, token[1], cnt); - rule->src_comm[cnt] = '\0'; - cnt = min_t(size_t, TASK_COMM_LEN - 1, strlen(token[2])); - strncpy(rule->dst_comm, token[2], cnt); - rule->dst_comm[cnt] = '\0'; - cnt = min_t(size_t, KILL_BLOCK_CGRP_LEN - 1, strlen(token[3])); - strncpy(rule->dst_cgrp, token[3], cnt); - rule->dst_cgrp[cnt] = '\0'; + strscpy(rule->src_comm, token[1], sizeof(rule->src_comm)); + strscpy(rule->dst_comm, token[2], sizeof(rule->dst_comm)); + strscpy(rule->dst_cgrp, token[3], sizeof(rule->dst_cgrp)); write_lock(&whitelist_lock); list_for_each_entry(tmp, &whitelist_list, node) { if (!strcasecmp(tmp->src_comm, rule->src_comm) && @@ -213,7 +207,7 @@ static unsigned int kill_block_get_podid_len(char *podid_start) return podid_len; } -bool kill_block_whitelist_match(struct task_struct *p, int sig, +static bool kill_block_whitelist_match(struct task_struct *p, int sig, char *src_cgrp_path, char *src_cgrp_name, char *dst_cgrp_path, char *dst_cgrp_name) { diff --git a/kernel/tkernel/killprotect/kill_protect.c b/kernel/tkernel/killprotect/kill_protect.c index 4474cad05b14..386014342cb0 100644 --- a/kernel/tkernel/killprotect/kill_protect.c +++ b/kernel/tkernel/killprotect/kill_protect.c @@ -87,9 +87,7 @@ static ssize_t blacklist_write(struct file *file, const char __user *ubuf, if (!rule) return -ENOMEM; - cnt = min_t(size_t, TASK_COMM_LEN - 1, strlen(token[1])); - strncpy(rule->comm, token[1], cnt); - rule->comm[cnt] = '\0'; + strscpy(rule->comm, token[1], sizeof(rule->comm)); write_lock(&blacklist_lock); list_for_each_entry(tmp, &blacklist_list, node) { @@ -103,9 +101,7 @@ static ssize_t blacklist_write(struct file *file, const char __user *ubuf, write_unlock(&blacklist_lock); atomic_inc(&kp_rule_cnt); } else if (strcmp(token[0], "del") == 0) { - cnt = min_t(size_t, TASK_COMM_LEN - 1, strlen(token[1])); - strncpy(comm, token[1], cnt); - comm[cnt] = '\0'; + strscpy(comm, token[1], sizeof(comm)); write_lock(&blacklist_lock); list_for_each_entry_safe(rule, tmp, &blacklist_list, node) { @@ -183,7 +179,7 @@ static int stat_proc_show(struct seq_file *m, void *v) return 0; } -bool kill_protect_blacklist_match(struct task_struct *p, int sig) +static bool kill_protect_blacklist_match(struct task_struct *p, int sig) { struct kp_blacklist_rule *rule; bool curr_match = false; -- Gitee