Skip to content

Commit 23aebe1

Browse files
oleg-nesterovtorvalds
authored andcommitted
exec: kill bprm->tcomm[], simplify the "basename" logic
Starting from commit c4ad8f9 ("execve: use 'struct filename *' for executable name passing") bprm->filename can not go away after flush_old_exec(), so we do not need to save the binary name in bprm->tcomm[] added by 96e02d1 ("exec: fix use-after-free bug in setup_new_exec()"). And there was never need for filename_to_taskname-like code, we can simply do set_task_comm(kbasename(filename). This patch has to change set_task_comm() and trace_task_rename() to accept "const char *", but I think this change is also good. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 32ed74a commit 23aebe1

File tree

4 files changed

+4
-22
lines changed

4 files changed

+4
-22
lines changed

fs/exec.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ EXPORT_SYMBOL_GPL(get_task_comm);
10461046
* so that a new one can be started
10471047
*/
10481048

1049-
void set_task_comm(struct task_struct *tsk, char *buf)
1049+
void set_task_comm(struct task_struct *tsk, const char *buf)
10501050
{
10511051
task_lock(tsk);
10521052
trace_task_rename(tsk, buf);
@@ -1055,21 +1055,6 @@ void set_task_comm(struct task_struct *tsk, char *buf)
10551055
perf_event_comm(tsk);
10561056
}
10571057

1058-
static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
1059-
{
1060-
int i, ch;
1061-
1062-
/* Copies the binary name from after last slash */
1063-
for (i = 0; (ch = *(fn++)) != '\0';) {
1064-
if (ch == '/')
1065-
i = 0; /* overwrite what we wrote */
1066-
else
1067-
if (i < len - 1)
1068-
tcomm[i++] = ch;
1069-
}
1070-
tcomm[i] = '\0';
1071-
}
1072-
10731058
int flush_old_exec(struct linux_binprm * bprm)
10741059
{
10751060
int retval;
@@ -1083,8 +1068,6 @@ int flush_old_exec(struct linux_binprm * bprm)
10831068
goto out;
10841069

10851070
set_mm_exe_file(bprm->mm, bprm->file);
1086-
1087-
filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
10881071
/*
10891072
* Release all of the old mmap stuff
10901073
*/
@@ -1127,7 +1110,7 @@ void setup_new_exec(struct linux_binprm * bprm)
11271110
else
11281111
set_dumpable(current->mm, suid_dumpable);
11291112

1130-
set_task_comm(current, bprm->tcomm);
1113+
set_task_comm(current, kbasename(bprm->filename));
11311114

11321115
/* Set the new mm task size. We have to do that late because it may
11331116
* depend on TIF_32BIT which is only updated in flush_thread() on

include/linux/binfmts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct linux_binprm {
4444
unsigned interp_flags;
4545
unsigned interp_data;
4646
unsigned long loader, exec;
47-
char tcomm[TASK_COMM_LEN];
4847
};
4948

5049
#define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, i
23572357
struct task_struct *fork_idle(int);
23582358
extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
23592359

2360-
extern void set_task_comm(struct task_struct *tsk, char *from);
2360+
extern void set_task_comm(struct task_struct *tsk, const char *from);
23612361
extern char *get_task_comm(char *to, struct task_struct *tsk);
23622362

23632363
#ifdef CONFIG_SMP

include/trace/events/task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TRACE_EVENT(task_newtask,
3232

3333
TRACE_EVENT(task_rename,
3434

35-
TP_PROTO(struct task_struct *task, char *comm),
35+
TP_PROTO(struct task_struct *task, const char *comm),
3636

3737
TP_ARGS(task, comm),
3838

0 commit comments

Comments
 (0)