[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHGf_=rPcUWc=YvR4YTQJH=+SSEQ40nSYmSQXX_aJLDMquiPGw@mail.gmail.com>
Date: Sun, 7 Apr 2013 23:52:34 -0400
From: KOSAKI Motohiro <kosaki.motohiro@...il.com>
To: Chen Gang <gang.chen@...anux.com>
Cc: "Eric W. Biederman" <ebiederm@...ssion.com>,
Frederic Weisbecker <fweisbec@...il.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] kernel: tsacct: strncpy, always be sure of NUL terminated.
On Sun, Apr 7, 2013 at 11:27 PM, Chen Gang <gang.chen@...anux.com> wrote:
>
> for NUL terminated string, always set '\0' at the end.
>
> Signed-off-by: Chen Gang <gang.chen@...anux.com>
> ---
> kernel/tsacct.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/tsacct.c b/kernel/tsacct.c
> index a1dd9a1..01bcc4e 100644
> --- a/kernel/tsacct.c
> +++ b/kernel/tsacct.c
> @@ -78,7 +78,8 @@ void bacct_add_tsk(struct user_namespace *user_ns,
> stats->ac_minflt = tsk->min_flt;
> stats->ac_majflt = tsk->maj_flt;
>
> - strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm));
> + strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm) - 1);
> + stats->ac_comm[sizeof(stats->ac_comm) - 1] = '\0';
sizeof(tsk->comm) is 16 and sizeof(stats->ac_comm) is 32. then this statement
is strange. and set_task_comm ensure tsk->comm is nul-terminated.
so your code never change the behavior, right?
And, If buggy driver change tsk->comm not to use set_task_comm and tsk->comm
is not nul-terminated, strncpy() still touch unrelated memory and ac_comm may
expose kernel internal info. that's bad.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists