From 9c7e3fedd9fdd0afa981444f7e689c6696b76380 Mon Sep 17 00:00:00 2001 From: Kris Van Hees Date: Wed, 14 Oct 2015 05:33:08 -0400 Subject: [PATCH] dtrace: remove trailing space in psargs Due to an implementation error, the psargs string contained a trailing space that was not meant to be there. This has been corrected. Orabug: 21974606 Signed-off-by: Kris Van Hees Acked-by: Nick Alcock --- include/linux/dtrace_psinfo.h | 1 + kernel/dtrace/dtrace_os.c | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/linux/dtrace_psinfo.h b/include/linux/dtrace_psinfo.h index 050d91f1d9b4..0151fd8679ee 100644 --- a/include/linux/dtrace_psinfo.h +++ b/include/linux/dtrace_psinfo.h @@ -17,6 +17,7 @@ typedef struct dtrace_psinfo { struct dtrace_psinfo *next; }; char **argv; + unsigned long envc; char **envp; char psargs[PR_PSARGS_SZ]; } dtrace_psinfo_t; diff --git a/kernel/dtrace/dtrace_os.c b/kernel/dtrace/dtrace_os.c index c8076468d709..577933abf824 100644 --- a/kernel/dtrace/dtrace_os.c +++ b/kernel/dtrace/dtrace_os.c @@ -113,25 +113,30 @@ void dtrace_psinfo_alloc(struct task_struct *tsk) mm = get_task_mm(tsk); if (mm) { size_t len = mm->arg_end - mm->arg_start; - int i, envc = 0; + int i = 0; char *p; /* * Construct the psargs string. */ - if (len >= PR_PSARGS_SZ) - len = PR_PSARGS_SZ - 1; + if (len > 0) { + if (len >= PR_PSARGS_SZ) + len = PR_PSARGS_SZ - 1; + + i = access_process_vm(tsk, mm->arg_start, + psinfo->psargs, len, 0); + if (i < len) + len = i; + + for (i = 0, --len; i < len; i++) { + if (psinfo->psargs[i] == '\0') + psinfo->psargs[i] = ' '; + } + } - i = access_process_vm(tsk, mm->arg_start, psinfo->psargs, - len, 0); while (i < PR_PSARGS_SZ) psinfo->psargs[i++] = 0; - for (i = 0; i < len; i++) { - if (psinfo->psargs[i] == '\0') - psinfo->psargs[i] = ' '; - } - /* * Determine the number of arguments. */ @@ -169,8 +174,9 @@ void dtrace_psinfo_alloc(struct task_struct *tsk) /* * Determine the number of environment variables. */ + psinfo->envc = 0; for (p = (char *)mm->env_start; p < (char *)mm->env_end; - envc++) { + psinfo->envc++) { size_t l = strnlen_user(p, MAX_ARG_STRLEN); if (!l) @@ -182,7 +188,7 @@ void dtrace_psinfo_alloc(struct task_struct *tsk) /* * Limit the number of stored environment pointers. */ - if ((len = envc) >= PR_ENVP_SZ) + if ((len = psinfo->envc) >= PR_ENVP_SZ) len = PR_ENVP_SZ - 1; psinfo->envp = kmalloc((len + 1) * sizeof(char *), @@ -218,6 +224,7 @@ void dtrace_psinfo_alloc(struct task_struct *tsk) psinfo->argc = 0; psinfo->argv = kmalloc(sizeof(char *), GFP_KERNEL); psinfo->argv[0] = NULL; + psinfo->envc = 0; psinfo->envp = kmalloc(sizeof(char *), GFP_KERNEL); psinfo->envp[0] = NULL; } -- 2.50.1