From nobody Sun Feb 8 03:31:10 2026 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 CB16F230BC5; Wed, 21 May 2025 06:23:59 +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=1747808642; cv=none; b=Qz7xCdPqtn1fajz2VmP1QyXdEKE012n5Hm6luwgmw7qHaDqrFl6oBsLSlSdsy3QQxTdNnjQunYiInltanyBWX/K1TblFOs9A5aKxb8tK9zzc/Wkl4dUAridQvULLG3EPT2iNF2y/+LlJ+0xi7Ko1FaDXlnC9yKSGzFtF5+DxV0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747808642; c=relaxed/simple; bh=I8faleen+YlYRwQJOEFwvKHjEj3VGyqU4/5IQ3Xn7Zg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A0uGrIcyid0aPITaXf0krC3OfcoubTJvO8psb4d/jLDxmSTJszUu4Z9VgOBqKr2BZS245jbvi1DJn4CXa69di3lEHqjuuDTy86qg51Uk3JyTxWLsT0byNpIT2Rv76zRsw6KfPVCybYwQOmspJj8pVfB1Z+rgIirioys/cVBN3zY= 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=lPzMBE1P; 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="lPzMBE1P" 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=Mj1L8UT5keBFToIFmCVn4vf03lSCBcagktZ7oeGryzY=; b=lPzMBE1PrVethON7w5jSglZ0xH doMttCtEHa3eE5f+fCV168lQsBT2/z+SSX6WM6u1qcTFFAQZbVT4KEKYq3P/aZcfSvHFoFAGM2tE7 luHTWLJ1z3bG/Q0B4+YnNDNufb24FcogBUnxL1gTq6DggcJOuoQZT35uA61x8TkmUrU1i42nIC43N eLDbKGfDDQQIVEhr4Dnk3EtISFTwWezSPLTCZ59CvgIzNp9b6cQny6eTNcsQ82ixKM9jeguTVvcBg TmIaHE19jBMUvyhf6ezdOBl8N1czNhiqPIDMErkVMbNDquDobWCOfzAb2TfR7cMJMX4qzES5jePmV STdRxYgw==; Received: from [223.233.70.209] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uHcrs-00B3oN-DJ; Wed, 21 May 2025 08:23:56 +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 Subject: [PATCH v4 1/3] exec: Remove obsolete comments Date: Wed, 21 May 2025 11:53:35 +0530 Message-Id: <20250521062337.53262-2-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250521062337.53262-1-bhupesh@igalia.com> References: <20250521062337.53262-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 Acked-by: Yafang Shao --- 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 8c60a42f9d00..704222114dcc 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1162,10 +1162,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 @@ -1997,7 +1995,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 Sun Feb 8 03:31:10 2026 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 C3238235049; Wed, 21 May 2025 06:24:05 +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=1747808648; cv=none; b=FTL77p91KSdNpMrNNyUOR00hAG3DWJcXUcKyR0G0tjZpPDMCYuFrlkJDysLs9MXQTqp/8yqOXkCJwf9IyfBIMCg9toYnGdB5Nj77VQDtxBnv/3TYnLWwqKUgUb6Wzi2SU1iSUZlH0eyBj7TWoJ1e7pQiXs8G/1vdemK12RfiMzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747808648; c=relaxed/simple; bh=DtIhSG+eMDrB9z0amxyQUxZAA8kvUIc6nU10K2gv5oM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A+kxD3OmgWjsFV+VoQuPMliy9m39MngWSdwlUO0TatTl0RL22FjCVTzu7THdnX3Ggr5Cl9ZY0Qi1vmVD9dwYNERXfBqN+TFUdTFJswBGgUfVS8wdPhhQ9Ggfg/f4Ll4TdNts+/jAcJMnKmeDW8Tdy6gSbFz8hI1gE/1kc6BQ4qQ= 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=JNO5+HGL; 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="JNO5+HGL" 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=pU6bSpYB8CPj1DDuT5mIS//XBcxXY2wc6q2aPeo4HGQ=; b=JNO5+HGL1Dc1zYmWHmB1rUUSLj piJFD554YV1qAOBwm3wP6JD+5CfsNkMhT+XL82pn9BmIorkyu77UykXUJcZ2bHjnswyiiAqn9FIBV 84XLl24D6Z0Z13jPHWgTXdEQU4oJoQ5Oo5CjE/RSEmSqaK2pKhZUMWfOgZqPlocycfS0+U0B1OzS7 ovvNEES1S0qW+oYB10H6pXwyF+4hehZZpsQEupxgUUrKaR/sZ8D9vOGY/YXvYhhLiMl/CRYT/T3K/ dtRbhaqm+v6wcuH9m6mh1Wj6iqBggjjGMPrbE26GoBA0XXBqqVkoMzvZl/M3uzAoJ6kdaAJJ4NT2/ KMNoufIw==; Received: from [223.233.70.209] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uHcry-00B3oN-Ij; Wed, 21 May 2025 08:24:02 +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 Subject: [PATCH v4 2/3] treewide: Switch memcpy() users of 'task->comm' to a more safer implementation Date: Wed, 21 May 2025 11:53:36 +0530 Message-Id: <20250521062337.53262-3-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250521062337.53262-1-bhupesh@igalia.com> References: <20250521062337.53262-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) is a more modular way (follow-up patches do 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 76e41805b92d..468abc308c24 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -54,7 +54,8 @@ extern void do_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] =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 ad36e73b8579..11aa0b58176d 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]", @@ -424,6 +426,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) @@ -443,6 +446,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) @@ -494,6 +498,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 Sun Feb 8 03:31:10 2026 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 AEE83232392; Wed, 21 May 2025 06:24:11 +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=1747808653; cv=none; b=QgbWpgKbTzz4TPEH8ykSqFvhfBk1w2TXUpFOO4Y+s1hWjOiUjK6wHYgv4uEZ+tLaoy0jhwLWPL2UOg+/6lUXuiWhLV99PZvMAs2GYIgrRyV2PAWhaEBofA180vErf8IhMv4InDDum7zKJN1DBEx9AnsZUeKHUSre9L5XZmTJlE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747808653; c=relaxed/simple; bh=Uv1ghNSaGNfo9bLBlcnVeQUqJDAm9OedV6fo1rEZFrc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BBHuAwyr86jAt8vK7ZAfiflgp22UCU3FUEAzlgQUye/1MLMsxm2YEyKNv/1uLECl2YkQVoZNCLxhSe52BqsljbAyGIiTEws1qAmDwvG4ReG6rBq497XTQQPyrjo7I8kRMWr9sTnR/dp9BFrcumgmQqAwYlog5BxUIS9HW7fBv+k= 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=Mxe5soRx; 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="Mxe5soRx" 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=FLnlNaHrEaw8H+WX1bi4GYpuBsRULfbnbCOgBsPrKvQ=; b=Mxe5soRx264DMUPK1JWNdwLPXq Rc0m42aIbWFiKQUIOURK8pq9srnIElIwgHAq7LKN2EpVwchaVyX4fJ3X//9EiLTrvomEW4EbqrgJe Fid5k4RG3Tyd+DJNgOrPPtYnnHrFxQ3UQFjVD3/rbS1h7YJThFGcfwyNBG6FV6Uiv+g7fGxrAZjlM i1xEn1VKgAoi2i21zAZlZ6wXw1fxEmnpOYBXuTGJGNsuapRmTszTeT47VZc+ayEBR7/R6GuV1/lPj HfMp0evtjenf3bRvx25pdSBp/6VncScW1rSM1Vo4t4DGDD0sXJZAcMO6lrPraAqzSiOLaKfaPaKiK DaO4j4lQ==; Received: from [223.233.70.209] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uHcs4-00B3oN-O7; Wed, 21 May 2025 08:24:09 +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 Subject: [PATCH v4 3/3] exec: Add support for 64 byte 'tsk->comm_ext' Date: Wed, 21 May 2025 11:53:37 +0530 Message-Id: <20250521062337.53262-4-bhupesh@igalia.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20250521062337.53262-1-bhupesh@igalia.com> References: <20250521062337.53262-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, Linus suggested in [1] that we can add the following union inside 'task_struct': union { char comm[TASK_COMM_LEN]; char comm_ext[TASK_COMM_EXT_LEN]; }; and then modify '__set_task_comm()' to pass 'tsk->comm_ext' to the existing users. This would mean that: (1) The old common pattern of just printing with '%s' and tsk->comm would just continue to work (as it is): pr_alert("BUG: Bad page state in process %s pfn:%05lx\n", current->comm, page_to_pfn(page)); (2) And, the memcpy() users of 'tsk->comm' would need to be made more stable by ensuring that the destination buffer always has a closing NUL character (done already in the preceding patch in this series). So, eventually: - users who want the existing 'TASK_COMM_LEN' behavior will get it (existing ABIs would continue to work), - users who just print out 'tsk->comm' as a string will get the longer new "extended comm", - users who do 'sizeof(->comm)' will continue to get the old value because of the union. [1]. https://lore.kernel.org/all/CAHk-=3DwjAmmHUg6vho1KjzQi2=3DpsR30+CogFd4= aXrThr2gsiS4g@mail.gmail.com Signed-off-by: Bhupesh --- fs/exec.c | 6 +++--- include/linux/sched.h | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 1f5fdd2e096e..3b39fbfc8fe4 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1077,11 +1077,11 @@ static int unshare_sighand(struct task_struct *me) */ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) { - size_t len =3D min(strlen(buf), sizeof(tsk->comm) - 1); + size_t len =3D min(strlen(buf), sizeof(tsk->comm_ext) - 1); =20 trace_task_rename(tsk, buf); - memcpy(tsk->comm, buf, len); - memset(&tsk->comm[len], 0, sizeof(tsk->comm) - len); + memcpy(tsk->comm_ext, buf, len); + memset(&tsk->comm_ext[len], 0, sizeof(tsk->comm_ext) - len); perf_event_comm(tsk, exec); } =20 diff --git a/include/linux/sched.h b/include/linux/sched.h index 704222114dcc..2605207170b4 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -316,6 +316,7 @@ struct user_event_mm; */ enum { TASK_COMM_LEN =3D 16, + TASK_COMM_EXT_LEN =3D 64, }; =20 extern void sched_tick(void); @@ -1165,7 +1166,10 @@ struct task_struct { * - logic inside set_task_comm() will ensure it is always NUL-terminat= ed and * zero-padded */ - char comm[TASK_COMM_LEN]; + union { + char comm[TASK_COMM_LEN]; + char comm_ext[TASK_COMM_EXT_LEN]; + }; =20 struct nameidata *nameidata; =20 @@ -2005,7 +2009,7 @@ 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); \ + strscpy_pad(buf, (tsk)->comm_ext); \ buf; \ }) =20 --=20 2.38.1