parent b01543dfe67bb1d191998e90d20534dc354de059 (v3.3-rc4)
commit 726ff573fe3f2722ec7bd765b84750ceda5e518e
Author: Jan Engelhardt <jengelh@medozas.de>
Date:   Tue Feb 21 06:21:38 2012 +0100

task: provide a larger task command buffer
---
 fs/exec.c             |   11 ++++++++++-
 fs/proc/array.c       |    8 ++++----
 include/linux/sched.h |   17 ++++++++++++++++-
 kernel/exit.c         |    4 ++--
 kernel/kthread.c      |    2 +-
 5 files changed, 33 insertions(+), 9 deletions(-)

Index: linux-4.11-rc8/fs/exec.c
===================================================================
--- linux-4.11-rc8.orig/fs/exec.c
+++ linux-4.11-rc8/fs/exec.c
@@ -1224,6 +1224,15 @@ char *get_task_comm(char *buf, struct ta
 }
 EXPORT_SYMBOL_GPL(get_task_comm);
 
+char *get_task_comm_ex(char *buf, size_t z, struct task_struct *tsk)
+{
+	task_lock(tsk);
+	strlcpy(buf, tsk->comm_ex, z);
+	task_unlock(tsk);
+	return buf;
+}
+EXPORT_SYMBOL_GPL(get_task_comm_ex);
+
 /*
  * These functions flushes out all traces of the currently running executable
  * so that a new one can be started
@@ -1233,7 +1242,7 @@ void __set_task_comm(struct task_struct
 {
 	task_lock(tsk);
 	trace_task_rename(tsk, buf);
-	strlcpy(tsk->comm, buf, sizeof(tsk->comm));
+	strlcpy(tsk->comm_ex, buf, sizeof(tsk->comm_ex));
 	task_unlock(tsk);
 	perf_event_comm(tsk, exec);
 }
Index: linux-4.11-rc8/fs/proc/array.c
===================================================================
--- linux-4.11-rc8.orig/fs/proc/array.c
+++ linux-4.11-rc8/fs/proc/array.c
@@ -97,10 +97,10 @@ static inline void task_name(struct seq_
 {
 	char *buf;
 	size_t size;
-	char tcomm[sizeof(p->comm)];
+	char tcomm[sizeof(p->comm_ex)];
 	int ret;
 
-	get_task_comm(tcomm, p);
+	get_task_comm_ex(tcomm, sizeof(tcomm), p);
 
 	seq_puts(m, "Name:\t");
 
@@ -408,7 +408,7 @@ static int do_task_stat(struct seq_file
 	u64 cutime, cstime, utime, stime;
 	u64 cgtime, gtime;
 	unsigned long rsslim = 0;
-	char tcomm[sizeof(task->comm)];
+	char tcomm[sizeof(task->comm_ex)];
 	unsigned long flags;
 
 	state = *get_task_state(task);
@@ -424,7 +424,7 @@ static int do_task_stat(struct seq_file
 		 */
 	}
 
-	get_task_comm(tcomm, task);
+	get_task_comm_ex(tcomm, sizeof(tcomm), task);
 
 	sigemptyset(&sigign);
 	sigemptyset(&sigcatch);
Index: linux-4.11-rc8/include/linux/sched.h
===================================================================
--- linux-4.11-rc8.orig/include/linux/sched.h
+++ linux-4.11-rc8/include/linux/sched.h
@@ -722,7 +722,21 @@ struct task_struct {
 	 * - access it with [gs]et_task_comm()
 	 * - lock it with task_lock()
 	 */
-	char				comm[TASK_COMM_LEN];
+	union {
+		/*
+		 * Executable name excluding path. Access it with
+		 * [gs]et_task_comm (which lock it with task_lock()).
+		 * Initialized normally by setup_new_exec.
+		 */
+		char comm[TASK_COMM_LEN];
+		/*
+		 * The .comm member is kept, while we try to identify the codes
+		 * that unfortunately rely on its exact size of 16. Apparently
+		 * not all those sites have been spotted in previous attempts
+		 * of mine to enlarge comm.
+		 */
+		char comm_ex[32];
+	};
 
 	struct nameidata		*nameidata;
 
@@ -1404,6 +1418,7 @@ static inline void set_task_comm(struct
 }
 
 extern char *get_task_comm(char *to, struct task_struct *tsk);
+extern char *get_task_comm_ex(char *to, size_t z, struct task_struct *tsk);
 
 #ifdef CONFIG_SMP
 void scheduler_ipi(void);
Index: linux-4.11-rc8/kernel/exit.c
===================================================================
--- linux-4.11-rc8.orig/kernel/exit.c
+++ linux-4.11-rc8/kernel/exit.c
@@ -764,7 +764,7 @@ static void check_stack_usage(void)
 	spin_lock(&low_water_lock);
 	if (free < lowest_to_date) {
 		pr_info("%s (%d) used greatest stack depth: %lu bytes left\n",
-			current->comm, task_pid_nr(current), free);
+			current->comm_ex, task_pid_nr(current), free);
 		lowest_to_date = free;
 	}
 	spin_unlock(&low_water_lock);
@@ -836,7 +836,7 @@ void __noreturn do_exit(long code)
 
 	if (unlikely(in_atomic())) {
 		pr_info("note: %s[%d] exited with preempt_count %d\n",
-			current->comm, task_pid_nr(current),
+			current->comm_ex, task_pid_nr(current),
 			preempt_count());
 		preempt_count_set(PREEMPT_ENABLED);
 	}
Index: linux-4.11-rc8/kernel/kthread.c
===================================================================
--- linux-4.11-rc8.orig/kernel/kthread.c
+++ linux-4.11-rc8/kernel/kthread.c
@@ -311,7 +311,7 @@ struct task_struct *__kthread_create_on_
 	if (!IS_ERR(task)) {
 		static const struct sched_param param = { .sched_priority = 0 };
 
-		vsnprintf(task->comm, sizeof(task->comm), namefmt, args);
+		vsnprintf(task->comm_ex, sizeof(task->comm_ex), namefmt, args);
 		/*
 		 * root may have changed our (kthreadd's) priority or CPU mask.
 		 * The kernel thread should not inherit these properties.
