From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by kanga.kvack.org (Postfix) with ESMTP id 706AB6B0253 for ; Wed, 23 Sep 2015 06:41:37 -0400 (EDT) Received: by wicfx3 with SMTP id fx3so62700067wic.0 for ; Wed, 23 Sep 2015 03:41:37 -0700 (PDT) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com. [209.85.212.169]) by mx.google.com with ESMTPS id bd6si10289433wib.116.2015.09.23.03.41.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2015 03:41:36 -0700 (PDT) Received: by wicgb1 with SMTP id gb1so199299549wic.1 for ; Wed, 23 Sep 2015 03:41:36 -0700 (PDT) Date: Wed, 23 Sep 2015 12:41:34 +0200 From: Michal Hocko Subject: Re: [patch] mm, oom: remove task_lock protecting comm printing Message-ID: <20150923104133.GD8644@dhcp22.suse.cz> References: <20150923080632.GD12318@esperanza> <20150923091354.GA640@swordfish> <20150923093021.GE12318@esperanza> <20150923094358.GB8644@dhcp22.suse.cz> <20150923095022.GB640@swordfish> <20150923100740.GF12318@esperanza> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150923100740.GF12318@esperanza> Sender: owner-linux-mm@kvack.org List-ID: To: Vladimir Davydov Cc: Sergey Senozhatsky , David Rientjes , Andrew Morton , Oleg Nesterov , Linus Torvalds , Kyle Walker , Christoph Lameter , Johannes Weiner , linux-mm , Linux Kernel Mailing List , Stanislav Kozina , Tetsuo Handa On Wed 23-09-15 13:07:40, Vladimir Davydov wrote: > 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 you are! I am blind obviously... Thought we are copying directly to the task->comm. -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org