Add support for getting and setting long user thread names with PR_{SET,GET}_EXT_NAME. Signed-off-by: André Almeida --- include/linux/sched.h | 2 +- include/uapi/linux/prctl.h | 3 +++ kernel/sys.c | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 6a48517f01cc..0f1b40a5dbc6 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2018,7 +2018,7 @@ extern void kick_process(struct task_struct *tsk); extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec); #define set_task_comm(tsk, from) ({ \ - BUILD_BUG_ON(sizeof(from) != TASK_COMM_LEN); \ + BUILD_BUG_ON(sizeof(from) < TASK_COMM_LEN); \ __set_task_comm(tsk, from, false); \ }) diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index b6ec6f693719..a07f8edadd65 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -56,6 +56,9 @@ #define PR_SET_NAME 15 /* Set process name */ #define PR_GET_NAME 16 /* Get process name */ +#define PR_SET_EXT_NAME 17 /* Set extended process name */ +#define PR_GET_EXT_NAME 18 /* Get extended process name */ + /* Get/set process endian */ #define PR_GET_ENDIAN 19 #define PR_SET_ENDIAN 20 diff --git a/kernel/sys.c b/kernel/sys.c index 3c37b5c1c072..26d5026f9590 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2535,7 +2535,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { struct task_struct *me = current; - unsigned char comm[TASK_COMM_LEN]; + unsigned char comm[TASK_COMM_EXT_LEN]; long error; error = security_task_prctl(option, arg2, arg3, arg4, arg5); @@ -2613,6 +2613,19 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3, if (copy_to_user((char __user *)arg2, comm, TASK_COMM_LEN)) return -EFAULT; break; + case PR_SET_EXT_NAME: + comm[TASK_COMM_EXT_LEN - 1] = 0; + if (strncpy_from_user(comm, (char __user *)arg2, + TASK_COMM_EXT_LEN - 1) < 0) + return -EFAULT; + set_task_comm(me, comm); + proc_comm_connector(me); + break; + case PR_GET_EXT_NAME: + strscpy_pad(comm, me->comm, TASK_COMM_EXT_LEN); + if (copy_to_user((char __user *)arg2, comm, TASK_COMM_EXT_LEN)) + return -EFAULT; + break; case PR_GET_ENDIAN: error = GET_ENDIAN(me, arg2); break; -- 2.55.0