From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754036AbdEFTvr (ORCPT ); Sat, 6 May 2017 15:51:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41572 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780AbdEFTvk (ORCPT ); Sat, 6 May 2017 15:51:40 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 53E22C04B332 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=oleg@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 53E22C04B332 Date: Sat, 6 May 2017 21:51:36 +0200 From: Oleg Nesterov To: Vegard Nossum Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Frederic Weisbecker , Jamie Iles , Peter Zijlstra , Thomas Gleixner , Andy Lutomirski Subject: Re: [PATCH] kthread: fix use-after-free if kthread fork fails Message-ID: <20170506195136.GB21726@redhat.com> References: <20170505162034.4338-1-vegard.nossum@oracle.com> <20170505164428.GA500@redhat.com> <939ac33e-ebe1-2b1e-425f-aced558ad5e3@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <939ac33e-ebe1-2b1e-425f-aced558ad5e3@oracle.com> 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.31]); Sat, 06 May 2017 19:51:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/05, Vegard Nossum wrote: > > On 05/05/17 18:44, Oleg Nesterov wrote: > > > >Can't we just move both > > > > p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; > > /* > > * Clear TID on mm_release()? > > */ > > p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL; > > > >lines here? > > clone_flags is not available in dup_task_struct(), but we could move > those lines higher in copy_process(). Yes, yes, this is what I meant. > The newly attached patch has been tested and seems to work, if you > prefer it. Yes, please, this loos a bit better simply because we do not need to set it twice. And I agree this needs cleanups. Even if we forget about this particular problem and the usage of set_child_tid, we should add copy_misc() which should absorb a lot of chaotic initializations from copy_process() imo. Oleg.