From nobody Mon Oct 6 04:59:04 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2482EFC0A; Thu, 24 Jul 2025 12:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360604; cv=none; b=qz92a7xtbZO0f0CCviF5MgPiUUyYNNGUjhuGpCZ8p8sXJ7869UKh1LpcSsI36Mx59CSB9AgEe0JfSA9BmkZsrUQ8AGIL/INyYf5D44/eNW7tPjCWriCdFLC2jfcahofUNTV8NLzs/NQOnDE0ewXoasUDDjp392cCl65oWRE9kc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360604; c=relaxed/simple; bh=AjuX5GQKdCxnVkjJPLl/Hxdx7MmDba3MhmtbvUVlrhI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=okf1sUgSUrTECFMcBKVmfnczt8B+KSUCjG6Kbxa2JruVVanjHB2JSEsN8WSrnoHtvzp0xxpYSk6d9IdAnFFwhyFBUsOAStSo+IvStL5atIfrQ8fBGvLEx42+JiwxfguoQaScQkv+DepG+TDhsrH8IIJXC0zw71pnj5jlI9iw2jc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=JKghUDp+; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="JKghUDp+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=rtmwqIefmP9hgVB4nAr4h+0uRDWTQ0QL2qUbei8qyDk=; b=JKghUDp+HlUWPn2vpYAlkohY7x BeZtFdce8x1hSGI+f5rk/JAfjYlz/Zaaf87zzqMgTzkL77GgzjkIDUD72+Hp9TkbBz33/9MAAJ6lS tCUMtin1AOvtSvtjPo5Mfd9Zpp0Bwj0EMtJHmtnH3D59cwzM3NGX6t3PZiygjazK9841aaG8eKGvP uG8A1Ikyt4U1B01846CkucnCUV5t8TiciEYtu8WYp+rV5MtTE4miQZN0uf9wBZ+gJYgqXbkHhThy4 Ro0wtfX3OimP+UFRKorBabHkzlIDIcejBbqJO3kZisOr3pfcjQUN19WRQaQ+GqtN6Fav5fLCJ4YQ0 YyxgPeTQ==; Received: from [223.233.78.24] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uevBY-003BPU-SL; Thu, 24 Jul 2025 14:36:33 +0200 From: Bhupesh To: akpm@linux-foundation.org Cc: bhupesh@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, laoar.shao@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-trace-kernel@vger.kernel.org, kees@kernel.org, torvalds@linux-foundation.org Subject: [PATCH v6 1/3] exec: Remove obsolete comments Date: Thu, 24 Jul 2025 18:06:10 +0530 Message-Id: <20250724123612.206110-2-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250724123612.206110-1-bhupesh@igalia.com> References: <20250724123612.206110-1-bhupesh@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Patch 3a3f61ce5e0b ("exec: Make sure task->comm is always NUL-terminated"), replaced 'strscpy_pad()' with 'memcpy()' implementations inside '__set_task_comm()'. However a few left-over comments are still there, which mention the usage of 'strscpy_pad()' inside '__set_task_comm()'. Remove those obsolete comments. While at it, also remove an obsolete comment regarding 'task_lock()' usage while handing 'task->comm'. Signed-off-by: Bhupesh Reviewed-by: Kees Cook --- include/linux/sched.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 84449f847256..8bbd03f1b978 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1156,10 +1156,8 @@ struct task_struct { * * - normally initialized begin_new_exec() * - set it with set_task_comm() - * - strscpy_pad() to ensure it is always NUL-terminated and + * - logic inside set_task_comm() will ensure it is always NUL-terminat= ed and * zero-padded - * - task_lock() to ensure the operation is atomic and the name is - * fully updated. */ char comm[TASK_COMM_LEN]; =20 @@ -1965,7 +1963,7 @@ extern void __set_task_comm(struct task_struct *tsk, = const char *from, bool exec * User space can randomly change their names anyway, so locking for rea= ders * doesn't make sense. For writers, locking is probably necessary, as a = race * condition could lead to long-term mixed results. - * The strscpy_pad() in __set_task_comm() can ensure that the task comm = is + * The logic inside __set_task_comm() should ensure that the task comm is * always NUL-terminated and zero-padded. Therefore the race condition b= etween * reader and writer is not an issue. * --=20 2.38.1 From nobody Mon Oct 6 04:59:04 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20F832D12EE; Thu, 24 Jul 2025 12:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360605; cv=none; b=s1hEFg8eDqaeljut9M/e9mjjWP+7qB2kU8DxrdbwjQckmO5Og38f8dAK79a3/IFT1hgOD3cybMj0JII+FRiZbQ+A9Mz/k6AZCjNEnlOUTU3rzhM6RkPwM+IkGCcZgNw/YBtQdT3qqsmgRXO9Bb8/snAsbHdEYAd4nCvYlKMNmdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360605; c=relaxed/simple; bh=VeT5v2Pw40XZeBkH1YcAjtHPzVong+m1lV6lLWLBH3Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T0WZZPyn0tz1vmGQGI/JRApPsnVfPQR9PJGnaih8HMw3HXgE5igtiYXqlyScXEvD3S6cbgU5DGcP5KiFt/nyt5XTinOZz7HjyG5Zjg7nGH11eHghxjz2gwdZVhiqjqw/O1S3SSXQiNKZ6ys3QL0z3Hgy8zZnrzlc6Bc296NClHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=GT053E1g; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="GT053E1g" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=xxJuMzxUwX/3/4eueFKaBfV57kSJFTkqTcDBwOHRShE=; b=GT053E1gz6CXBmsRuLUeeUOtpZ 6eA3D/mixw8gzo+maEv5+OIfU9l6l1zpm7hNcECcQc97Y2Uo6qNtBbI9bu7B2qeu4nP2+DbqCect7 +zjIq1AQLb+dEZgY7qaQ2t2VyspHqmP2HsMoVM5BdOlERpTPwBCWEBlgc3/qNCUZ8n9qCihzT9LOi lksslbdaMs5Jqe0IdN1K2iRcqgnMKEunvX7/isGlu7tuUm64o3scA1BrNZUnEgAT3Tdz0XxirNtel jMh2a+QbAIEaP9yGzd0xamYvUdg2OP7Rsa5ZEk4cuNdocvwP1xQ9FqXMie0rBszM3c5oXfuc2GzRD biNb+Xcw==; Received: from [223.233.78.24] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uevBf-003BPU-Qi; Thu, 24 Jul 2025 14:36:40 +0200 From: Bhupesh To: akpm@linux-foundation.org Cc: bhupesh@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, laoar.shao@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-trace-kernel@vger.kernel.org, kees@kernel.org, torvalds@linux-foundation.org Subject: [PATCH v6 2/3] treewide: Switch memcpy() users of 'task->comm' to a more safer implementation Date: Thu, 24 Jul 2025 18:06:11 +0530 Message-Id: <20250724123612.206110-3-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250724123612.206110-1-bhupesh@igalia.com> References: <20250724123612.206110-1-bhupesh@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As Linus mentioned in [1], currently we have several memcpy() use-cases which use 'current->comm' to copy the task name over to local copies. For an example: ... char comm[TASK_COMM_LEN]; memcpy(comm, current->comm, TASK_COMM_LEN); ... These should be modified so that we can later implement approaches to handle the task->comm's 16-byte length limitation (TASK_COMM_LEN) in a more modular way (follow-up patch does the same): ... char comm[TASK_COMM_LEN]; memcpy(comm, current->comm, TASK_COMM_LEN); comm[TASK_COMM_LEN - 1] =3D '\0'; ... The relevant 'memcpy()' users were identified using the following search pattern: $ git grep 'memcpy.*->comm\>' [1]. https://lore.kernel.org/all/CAHk-=3DwjAmmHUg6vho1KjzQi2=3DpsR30+CogFd4= aXrThr2gsiS4g@mail.gmail.com/ Signed-off-by: Bhupesh --- include/linux/coredump.h | 3 ++- include/trace/events/block.h | 5 +++++ include/trace/events/oom.h | 1 + include/trace/events/osnoise.h | 1 + include/trace/events/signal.h | 1 + include/trace/events/task.h | 2 ++ 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/coredump.h b/include/linux/coredump.h index 68861da4cf7c..988b233dcc09 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -54,7 +54,8 @@ extern void vfs_coredump(const kernel_siginfo_t *siginfo); do { \ char comm[TASK_COMM_LEN]; \ /* This will always be NUL terminated. */ \ - memcpy(comm, current->comm, sizeof(comm)); \ + memcpy(comm, current->comm, TASK_COMM_LEN); \ + comm[TASK_COMM_LEN - 1] =3D '\0'; \ printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n", \ task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__); \ } while (0) \ diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 6aa79e2d799c..dfc20fbe389c 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -214,6 +214,7 @@ DECLARE_EVENT_CLASS(block_rq, blk_fill_rwbs(__entry->rwbs, rq->cmd_flags); __get_str(cmd)[0] =3D '\0'; memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; ), =20 TP_printk("%d,%d %s %u (%s) %llu + %u %s,%u,%u [%s]", @@ -352,6 +353,7 @@ DECLARE_EVENT_CLASS(block_bio, __entry->nr_sector =3D bio_sectors(bio); blk_fill_rwbs(__entry->rwbs, bio->bi_opf); memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; ), =20 TP_printk("%d,%d %s %llu + %u [%s]", @@ -435,6 +437,7 @@ TRACE_EVENT(block_plug, =20 TP_fast_assign( memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; ), =20 TP_printk("[%s]", __entry->comm) @@ -454,6 +457,7 @@ DECLARE_EVENT_CLASS(block_unplug, TP_fast_assign( __entry->nr_rq =3D depth; memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; ), =20 TP_printk("[%s] %d", __entry->comm, __entry->nr_rq) @@ -505,6 +509,7 @@ TRACE_EVENT(block_split, __entry->new_sector =3D new_sector; blk_fill_rwbs(__entry->rwbs, bio->bi_opf); memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; ), =20 TP_printk("%d,%d %s %llu / %llu [%s]", diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index 9f0a5d1482c4..a5641ed4285f 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -24,6 +24,7 @@ TRACE_EVENT(oom_score_adj_update, TP_fast_assign( __entry->pid =3D task->pid; memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; __entry->oom_score_adj =3D task->signal->oom_score_adj; ), =20 diff --git a/include/trace/events/osnoise.h b/include/trace/events/osnoise.h index 3f4273623801..0321b3f8d532 100644 --- a/include/trace/events/osnoise.h +++ b/include/trace/events/osnoise.h @@ -117,6 +117,7 @@ TRACE_EVENT(thread_noise, =20 TP_fast_assign( memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; __entry->pid =3D t->pid; __entry->start =3D start; __entry->duration =3D duration; diff --git a/include/trace/events/signal.h b/include/trace/events/signal.h index 1db7e4b07c01..7f490e553db5 100644 --- a/include/trace/events/signal.h +++ b/include/trace/events/signal.h @@ -68,6 +68,7 @@ TRACE_EVENT(signal_generate, __entry->sig =3D sig; TP_STORE_SIGINFO(__entry, info); memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; __entry->pid =3D task->pid; __entry->group =3D group; __entry->result =3D result; diff --git a/include/trace/events/task.h b/include/trace/events/task.h index af535b053033..4ddf21b69372 100644 --- a/include/trace/events/task.h +++ b/include/trace/events/task.h @@ -22,6 +22,7 @@ TRACE_EVENT(task_newtask, TP_fast_assign( __entry->pid =3D task->pid; memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __entry->comm[TASK_COMM_LEN - 1] =3D '\0'; __entry->clone_flags =3D clone_flags; __entry->oom_score_adj =3D task->signal->oom_score_adj; ), @@ -45,6 +46,7 @@ TRACE_EVENT(task_rename, =20 TP_fast_assign( memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN); + entry->oldcomm[TASK_COMM_LEN - 1] =3D '\0'; strscpy(entry->newcomm, comm, TASK_COMM_LEN); __entry->oom_score_adj =3D task->signal->oom_score_adj; ), --=20 2.38.1 From nobody Mon Oct 6 04:59:04 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC48D2D238B; Thu, 24 Jul 2025 12:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360612; cv=none; b=pCXLCpwvWG1J9CTYYdLgURSxzZCruVmQL8ecs7YRQGyjf3/pei33Go2NrvSYs7Y3WTH24N4V47ehw9cnKDsAtGbbuEA1WVQ19O/E1NPWJcOiSCqOfdTkrJQAA8Qd7j2C7k94qpF7Hnu+vVCm5VA3CsTdMcqjdfl0TGVE5s3lBak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753360612; c=relaxed/simple; bh=ZTxbfBR4e9g+Vo8kn1KwzFv9oZCibHXpEedTrwXLllA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rmhBZpsUZRS6/H24u0WDALz+8dwDAwOezpsnuzKER54F2TQOss5iBv74OXDGX+NhCJV3h512wF6OGHQFYEvY0PCH4CGGHzLOsNAIfvg3wQxclGpr0ou9uyqZoxTL+RA/c/U4D8gA7jwHCz4UOSH1+x5qYL2HbAteM4ZL4q68tzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=YmObt6aa; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="YmObt6aa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ay/n4segqzBtdJcxqD3V5D84mQe9aCStMnYXrz6ny88=; b=YmObt6aaSGJMlOElGiwShkA2s/ x+rR+nIVtETN4fxSYbthlIKDkyjCfgR7qOqA2UrOGd6LqO9gw+PYxxgZeFBICgr7qUdtBFjLfFM7W Nv6FYxDlDTRkKpz7GL0fSTbio5vcycsCc4PJA8PCHRR1bHBai76XHK/b43JKemwkCIWlhbbfMAkTb gqSIPF5a/3ltQT2Oof/c5JVFCWpFY3GVTi9kubC7jULyNgI/FYDBiLBzkTqvdzXSqfrewsSh5ATab kwkzlCsK1mZ1XhkC/u2qTga8BFUrn9aoaENc/c1pPMTM8oBR6w0dtJKqrpK08kecCVUjhPzt7lpqE YouuGFPg==; Received: from [223.233.78.24] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uevBm-003BPU-Nn; Thu, 24 Jul 2025 14:36:47 +0200 From: Bhupesh To: akpm@linux-foundation.org Cc: bhupesh@igalia.com, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, laoar.shao@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-trace-kernel@vger.kernel.org, kees@kernel.org, torvalds@linux-foundation.org Subject: [PATCH v6 3/3] include: Set tsk->comm length to 64 bytes Date: Thu, 24 Jul 2025 18:06:12 +0530 Message-Id: <20250724123612.206110-4-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250724123612.206110-1-bhupesh@igalia.com> References: <20250724123612.206110-1-bhupesh@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Historically due to the 16-byte length of TASK_COMM_LEN, the users of 'tsk->comm' are restricted to use a fixed-size target buffer also of TASK_COMM_LEN for 'memcpy()' like use-cases. To fix the same, we now use a 64-byte TASK_COMM_EXT_LEN and set the comm element inside 'task_struct' to the same length: struct task_struct { ..... char comm[TASK_COMM_EXT_LEN]; ..... }; where TASK_COMM_EXT_LEN is 64-bytes. Now, in order to maintain existing ABI, we ensure that: - Existing users of 'get_task_comm'/ 'set_task_comm' will get 'tsk->comm' truncated to a maximum of 'TASK_COMM_LEN' (16-bytes) to maintain ABI, - New / Modified users of 'get_task_comm'/ 'set_task_comm' will get 'tsk->comm' supported up to the maximum of 'TASK_COMM_EXT_LEN' (64-bytes). Note, that the existing users have not been modified to migrate to 'TASK_COMM_EXT_LEN', in case they have hard-coded expectations of dealing with only a 'TASK_COMM_LEN' long 'tsk->comm'. Signed-off-by: Bhupesh --- include/linux/sched.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 8bbd03f1b978..b6abb759292c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -317,6 +317,7 @@ struct user_event_mm; */ enum { TASK_COMM_LEN =3D 16, + TASK_COMM_EXT_LEN =3D 64, }; =20 extern void sched_tick(void); @@ -1159,7 +1160,7 @@ struct task_struct { * - logic inside set_task_comm() will ensure it is always NUL-terminat= ed and * zero-padded */ - char comm[TASK_COMM_LEN]; + char comm[TASK_COMM_EXT_LEN]; =20 struct nameidata *nameidata; =20 @@ -1954,7 +1955,7 @@ extern void kick_process(struct task_struct *tsk); =20 extern void __set_task_comm(struct task_struct *tsk, const char *from, boo= l exec); #define set_task_comm(tsk, from) ({ \ - BUILD_BUG_ON(sizeof(from) !=3D TASK_COMM_LEN); \ + BUILD_BUG_ON(sizeof(from) < TASK_COMM_LEN); \ __set_task_comm(tsk, from, false); \ }) =20 @@ -1974,6 +1975,10 @@ extern void __set_task_comm(struct task_struct *tsk,= const char *from, bool exec #define get_task_comm(buf, tsk) ({ \ BUILD_BUG_ON(sizeof(buf) < TASK_COMM_LEN); \ strscpy_pad(buf, (tsk)->comm); \ + if ((sizeof(buf)) =3D=3D TASK_COMM_LEN) \ + buf[TASK_COMM_LEN - 1] =3D '\0'; \ + else \ + buf[TASK_COMM_EXT_LEN - 1] =3D '\0'; \ buf; \ }) =20 --=20 2.38.1