From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753714AbbIWKIA (ORCPT ); Wed, 23 Sep 2015 06:08:00 -0400 Received: from mx2.parallels.com ([199.115.105.18]:41571 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753250AbbIWKH6 (ORCPT ); Wed, 23 Sep 2015 06:07:58 -0400 Date: Wed, 23 Sep 2015 13:07:40 +0300 From: Vladimir Davydov To: Michal Hocko , Sergey Senozhatsky CC: David Rientjes , Andrew Morton , Oleg Nesterov , Linus Torvalds , Kyle Walker , Christoph Lameter , Johannes Weiner , linux-mm , Linux Kernel Mailing List , Stanislav Kozina , Tetsuo Handa Subject: Re: [patch] mm, oom: remove task_lock protecting comm printing Message-ID: <20150923100740.GF12318@esperanza> References: <20150923080632.GD12318@esperanza> <20150923091354.GA640@swordfish> <20150923093021.GE12318@esperanza> <20150923094358.GB8644@dhcp22.suse.cz> <20150923095022.GB640@swordfish> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20150923095022.GB640@swordfish> X-ClientProxiedBy: US-EXCH.sw.swsoft.com (10.255.249.47) To US-EXCH2.sw.swsoft.com (10.255.249.46) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 23, 2015 at 06:50:22PM +0900, Sergey Senozhatsky wrote: > On (09/23/15 11:43), Michal Hocko wrote: > [..] > > > > 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? > > > > Not really: > > case PR_SET_NAME: > > comm[sizeof(me->comm) - 1] = 0; > > if (strncpy_from_user(comm, (char __user *)arg2, > > sizeof(me->comm) - 1) < 0) > > return -EFAULT; > > > > So it first writes the terminating 0 and only then starts copying. It writes 0 to a temporary buffer, not to tsk->comm, so I don't think it's related. However, reading tsk->comm w/o locking must be safe anyway, because tsk->comm[TASK_COMM_LEN-1] is always 0 (inherited from init_task) and it never gets overwritten, because __set_task_comm() uses strlcpy(). > > right. > > hm, shouldn't set_task_comm()->__set_task_comm() do the same? I don't think so - see above. Thanks, Vladimir