linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] get_task_comm: use strlcpy instead of strncpy
@ 2009-06-14 16:57 Evgeni Golov
  2009-06-14 16:57 ` [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm) Evgeni Golov
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeni Golov @ 2009-06-14 16:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Evgeni Golov

it's used in set_task_comm too and as far as I understand it should
be used everywhere.

Signed-off-by: Evgeni Golov <sargentd@die-welt.net>
---
 fs/exec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index e639957..6f1eeb8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -913,7 +913,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 {
 	/* buf must be at least sizeof(tsk->comm) in size */
 	task_lock(tsk);
-	strncpy(buf, tsk->comm, sizeof(tsk->comm));
+	strlcpy(buf, tsk->comm, sizeof(tsk->comm));
 	task_unlock(tsk);
 	return buf;
 }
-- 
1.6.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm)
  2009-06-14 16:57 [PATCH 1/2] get_task_comm: use strlcpy instead of strncpy Evgeni Golov
@ 2009-06-14 16:57 ` Evgeni Golov
  2009-06-14 23:14   ` Alan Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeni Golov @ 2009-06-14 16:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Evgeni Golov

sizeof(tsk->comm) == TASK_COMM_LEN, always, so why not use it?

Signed-off-by: Evgeni Golov <sargentd@die-welt.net>
---
 fs/exec.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 6f1eeb8..14fd909 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -911,9 +911,9 @@ static void flush_old_files(struct files_struct * files)
 
 char *get_task_comm(char *buf, struct task_struct *tsk)
 {
-	/* buf must be at least sizeof(tsk->comm) in size */
+	/* buf must be at least sizeof(tsk->comm) (=TASK_COMM_LEN) in size */
 	task_lock(tsk);
-	strlcpy(buf, tsk->comm, sizeof(tsk->comm));
+	strlcpy(buf, tsk->comm, TASK_COMM_LEN);
 	task_unlock(tsk);
 	return buf;
 }
@@ -921,7 +921,7 @@ char *get_task_comm(char *buf, struct task_struct *tsk)
 void set_task_comm(struct task_struct *tsk, char *buf)
 {
 	task_lock(tsk);
-	strlcpy(tsk->comm, buf, sizeof(tsk->comm));
+	strlcpy(tsk->comm, buf, TASK_COMM_LEN);
 	task_unlock(tsk);
 	perf_counter_comm(tsk);
 }
@@ -930,7 +930,7 @@ int flush_old_exec(struct linux_binprm * bprm)
 {
 	char * name;
 	int i, ch, retval;
-	char tcomm[sizeof(current->comm)];
+	char tcomm[TASK_COMM_LEN];
 
 	/*
 	 * Make sure we have a private signal table and that
-- 
1.6.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm)
  2009-06-14 16:57 ` [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm) Evgeni Golov
@ 2009-06-14 23:14   ` Alan Cox
  2009-06-15  5:56     ` Evgeni Golov
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Cox @ 2009-06-14 23:14 UTC (permalink / raw)
  To: Evgeni Golov; +Cc: linux-kernel, Evgeni Golov

On Sun, 14 Jun 2009 18:57:48 +0200
Evgeni Golov <sargentd@die-welt.net> wrote:

> sizeof(tsk->comm) == TASK_COMM_LEN, always, so why not use it?

Because if the size ever changes the existing code will remain correct
and your changes will become a dangerous buffer overrun ?

Alan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm)
  2009-06-14 23:14   ` Alan Cox
@ 2009-06-15  5:56     ` Evgeni Golov
  0 siblings, 0 replies; 4+ messages in thread
From: Evgeni Golov @ 2009-06-15  5:56 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

On Mon, Jun 15, 2009 at 12:14:10AM +0100, Alan Cox wrote:
> On Sun, 14 Jun 2009 18:57:48 +0200
> Evgeni Golov <sargentd@die-welt.net> wrote:
> 
> > sizeof(tsk->comm) == TASK_COMM_LEN, always, so why not use it?
> 
> Because if the size ever changes the existing code will remain correct
> and your changes will become a dangerous buffer overrun ?

But shouldn't TASK_COMM_LEN change then too?
Just wondering, in the end it's a cosmetic cange, but looking at the 
code, we rely on TASK_COMM_LEN in other places often enough to break 
something when a task->comm is not TASK_COMM_LEM big.

Regards
Evgeni

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-06-15  6:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-14 16:57 [PATCH 1/2] get_task_comm: use strlcpy instead of strncpy Evgeni Golov
2009-06-14 16:57 ` [PATCH 2/2] use the TASK_COMM_LEN macro instead of sizeof(tsk->comm) Evgeni Golov
2009-06-14 23:14   ` Alan Cox
2009-06-15  5:56     ` Evgeni Golov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).