From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751891AbdJBPDu (ORCPT ); Mon, 2 Oct 2017 11:03:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43510 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751856AbdJBPDt (ORCPT ); Mon, 2 Oct 2017 11:03:49 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13C797F3F0 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=oleg@redhat.com Date: Mon, 2 Oct 2017 17:03:46 +0200 From: Oleg Nesterov To: Gargi Sharma Cc: linux-kernel@vger.kernel.org, Rik van Riel , Julia Lawall , akpm@linux-foundation.org, mingo@kernel.org, pasha.tatashin@oracle.com, ktkhai@virtuozzo.com, Eric Biederman Subject: Re: [PATCH v2 2/2] pid: Remove pidhash Message-ID: <20171002150346.GA9481@redhat.com> References: <20170927154543.GA3788@redhat.com> <20170927162808.GA5680@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 02 Oct 2017 15:03:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/30, Gargi Sharma wrote: > > On Wed, Sep 27, 2017 at 9:58 PM, Oleg Nesterov wrote: > > If I was not clear... > > > > in short, after this patch the very first idr_alloc_cyclic() is already > > wrong. Because, once again, the new not-fully-initialized pid can be found > > by find_pid_ns(). > > If the PIDNS_ADDING check fails, I jump to the flag that performs > this > while (++i <= ns->level) > idr_remove(&ns->idr, (pid->numbers + i)->nr); > So when find_pid_ns() is called, it will not find this pid. You misunderstood. OK, to simplify lets forget about namespaces, locking, everything. So after this patch alloc_pid() roughly does: pid = kmem_cache_alloc(); nr = idr_alloc_cyclic(idr, pid); // lets suppose it returns 1234 /* WINDOW */ for (type = 0; type < PIDTYPE_MAX; ++type) INIT_HLIST_HEAD(&pid->tasks[type]); now suppose that in that WINDOW above another CPU does, just for example, sys_tkill(1234, SIG) which implies find_task_by_vpid(1234) which does pid_task(find_pid_ns(1234)). find_pid_ns() returns the non-initialized pid above, because with this patch it is idr_find() and this pid was already added by idr_alloc_cyclic(). Then pid_task(pid) returns garbage because pid->tasks[] was not initialised yet. And of course we have the same problems with pid->count/numbers/etc. See? > > perhaps you should chane the previous patch to do > > idr_alloc_cyclic(ptr = NULL) and use idr_replace() in this patch after > > the PIDNS_HASH_ADDING check. > > I'm not sure if I understand this. Do we want to do this to make sure > the pid namespace is > initialized before the first process enters into > the namespace? If yes, No, > how does idr_alloc_cyclic(ptr = NULL) help? In this case find_pid_ns/idr_find will return NULL until we do idr_replace(idr, pid) when this pid is fully initialized. Oleg.