Re: [PATCH] sanitize task->comm to avoid leaking escape codes

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Oleg Nesterov
Date: Tuesday, June 29, 2010 - 10:18 am

On 06/29, Paul E. McKenney wrote:

Ah, sorry for confusion.

No, we are not trying to invent the lockless get_task_comm(). I'd say
it is not needed, if we really care about the precise ->comm we can
take task->alloc_lock.

The only problem is that I believe that set_task_comm() wrongly pretends
wmb() can help the lockless reader, it does:

	task_lock(tsk);

	/*
	 * Threads may access current->comm without holding
	 * the task lock, so write the string carefully.
	 * Readers without a lock may see incomplete new
	 * names but are safe from non-terminating string reads.
	 */
	memset(tsk->comm, 0, TASK_COMM_LEN);
	wmb();
	strlcpy(tsk->comm, buf, sizeof(tsk->comm));
	task_unlock(tsk);

but afaics this wmb() buys absolutely nothing if we race with the
reader doing, say,

	printk("my name is %s\n", current->comm);

Afaics, this wmb()

	- can't prevent from printing the mixture of the old/new data

	- is not needed to make strcpy(somewhere, task->comm) safe,
	  the final char is always '0', we never change it.

	- adds the unnecessary confusion


Thanks a lot, Paul ;)

Oleg.

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] sanitize task->comm to avoid leaking escape codes, Oleg Nesterov, (Tue Jun 29, 10:18 am)