lkml.org 
[lkml]   [2015]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] mm, oom: remove task_lock protecting comm printing
On Wed, Sep 23, 2015 at 06:13:54PM +0900, Sergey Senozhatsky wrote:
> On (09/23/15 11:06), Vladimir Davydov wrote:
> > Hi,
> >
> > On Tue, Sep 22, 2015 at 04:30:13PM -0700, David Rientjes wrote:
> > > The oom killer takes task_lock() in a couple of places solely to protect
> > > printing the task's comm.
> > >
> > > A process's comm, including current's comm, may change due to
> > > /proc/pid/comm or PR_SET_NAME.
> > >
> > > The comm will always be NULL-terminated, so the worst race scenario would
> > > only be during update. We can tolerate a comm being printed that is in
> > > the middle of an update to avoid taking the lock.
> > >
> > > Other locations in the kernel have already dropped task_lock() when
> > > printing comm, so this is consistent.
> >
> > Without the protection, can't reading task->comm race with PR_SET_NAME
> > as described below?
>
> the previous name was already null terminated,

Yeah, but if the old name is shorter than the new one, set_task_comm()
overwrites the terminating null of the old name before writing the new
terminating null, so there is a short time window during which tsk->comm
might be not null-terminated, no?

Thanks,
Vladimir

> so it should be
>
> [name\0old_name\0]
>
> -ss
>
> >
> > Let T->comm[16] = "name\0rubbish1234"
> >
> > CPU1 CPU2
> > ---- ----
> > set_task_comm(T, "longname\0")
> > T->comm[0] = 'l'
> > T->comm[1] = 'o'
> > T->comm[2] = 'n'
> > T->comm[3] = 'g'
> > T->comm[4] = 'n'
> > printk("%s\n", T->comm)
> > T->comm = "longnrubbish1234"
> > OOPS: the string is not
> > nil-terminated!
> > T->comm[5] = 'a'
> > T->comm[6] = 'm'
> > T->comm[7] = 'e'
> > T->comm[8] = '\0'
>


\
 
 \ /
  Last update: 2015-09-23 12:01    [W:0.095 / U:0.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site