Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3992773ybi; Fri, 19 Jul 2019 12:45:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRv5Vdhs7XX0Klibp1ETYszCQczNHWdKG3Do0h8q6WAk+rAcBeQgT0ujiPhWOgGzEN7/w3 X-Received: by 2002:a65:62d7:: with SMTP id m23mr55879810pgv.358.1563565537912; Fri, 19 Jul 2019 12:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563565537; cv=none; d=google.com; s=arc-20160816; b=glIIDJtXjjitmNweVvcKphT09BzVrn+tq1BwCJ5UtU8QBXfuCCWWvoFWu0Iozok7S6 Dx2/grPVSrydxJfEZgLfcVn3zgsoHAV75SGp8FgyAK6oJMfZOgXNUkUBm1FtiaQazdlX cp4khsxzBa6Y2r7dWkF8Nc0vMGnLTlakXHRneoYsiIy/r9wXUy9ySqImdwQ5E/TIYM2s ElYeJ78ZeaFLunLkgnp91iWpOFqAIBzEm0WHBTzA9Q1AlAccX+KnvONpDpjuQ115XhJD XuwdA2ELxGIbo4LiF7cyR0bJMaPuyn2dvcg2B7LCtChfzmv5LqCG/hE58B//v9BjlDZ2 6qEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/d9rok+uziIchuNx4fir+IeDsIyz939n/QaTRJw2YiU=; b=KQntmmUqwGnBl12e838hGx77qZmpaXmWmYXE6tN5RgP5513/s+GF/GupZ4HQu93Iy2 NbAnW4unKsJC7xKuqFrjfIiJHdJx87ySl1vNe67D+dx/eDC2eNT82SNZuis6tZaTh5cl bHdsvYpTMgCRWMX4DPcd6z9NIh199iEONXnHVlmI/dmLTLLY8XwsNNH/PzAHobCwFw3x Jrd2dlbskC1bCh7hcaNLwyiVfdrdWLK/ih4oKQMTR4xwgnVqLOdu7ER3aJMbFi+EUkf+ D+eZFZ0o4jXloaVbpDUHpslSLWpAY3a33SyVd7yzp+1F1Enrg9yIyaJGPR9VdLzx+X7+ pN3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gW28s7Pt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m32si3362809pld.438.2019.07.19.12.45.22; Fri, 19 Jul 2019 12:45:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gW28s7Pt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729001AbfGSQd2 (ORCPT + 99 others); Fri, 19 Jul 2019 12:33:28 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38837 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727577AbfGSQd2 (ORCPT ); Fri, 19 Jul 2019 12:33:28 -0400 Received: by mail-wr1-f65.google.com with SMTP id g17so32870934wrr.5 for ; Fri, 19 Jul 2019 09:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/d9rok+uziIchuNx4fir+IeDsIyz939n/QaTRJw2YiU=; b=gW28s7PtRmRVP7DPR/hEKIrcn2rU0/TNPo6418yib5FT08XhoFOxC71p+Kcj/WoC8n lcBEaruSRKroxrvOB7w2hYmGeKxRZnX+k7FZgrXcAdx2Oc+8I9Q+ZJWrNhN3Tc+RkxDw hPesdRlFQwYjldwUDipsYi0QgyReMFoqq6CknHr9Wn0TLqSdK+/SscFbp+3xR3xIJ3BQ eWsD3OGtzrxLlRi8ZeshvFOCFuJDBJ0xDYTyzq+pI06OFWozlBNHhbyMTVmRbFAlZsbT jevqLLfuE0K1eBeZKv4RovrrCpIPC8Qd6Eycvm08/V3ijiYJhDWWGF8lbmNKHz5SkmO3 ndJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/d9rok+uziIchuNx4fir+IeDsIyz939n/QaTRJw2YiU=; b=NJI7p1o23cmdJfRuliEYSoRbSIX7d9MkcVK2czzLszBsMe6QAoQ3i9BTTgMhar6nRn aeX21daZ7jomCLlDNPmv52GQEAOIKp1wgh6gXED1NLCo9rC9FUjj2vzzWo2NBXRUQQGW MDWE+yr6qdSvs4p4aH448vNtCmASSdvTTns9hqxKIQ+XbzHnkB0/nNGcGYnvnvik/4wx hdKV8T1H4UF1btegvd01iY4DQJC+jMAAWHFX/2reJE8Ozi3Ce7U+KCGJH9AfU6u13BNg cgjBv4nSe4F9SmesqDpgxoj5UiPJ1BGojl34UYqwAoEJSNmVblcZAaetwr8Gxee19Axk WcVQ== X-Gm-Message-State: APjAAAWCpN26/zF2GjXrdpwRRHSbN7BCIYVzVC0RscREbGA61Tk9jC3P S5lNjK6Jo7Ig0KlAsbzwXx+gDfSyyGDSL8GWw0wr4YNZ28U= X-Received: by 2002:adf:e50c:: with SMTP id j12mr52974950wrm.117.1563554005652; Fri, 19 Jul 2019 09:33:25 -0700 (PDT) MIME-Version: 1.0 References: <20190717172100.261204-1-joel@joelfernandes.org> <20190719161404.GA24170@redhat.com> <20190719162726.u5fi5k3tqove6hgn@brauner.io> In-Reply-To: <20190719162726.u5fi5k3tqove6hgn@brauner.io> From: Suren Baghdasaryan Date: Fri, 19 Jul 2019 09:33:14 -0700 Message-ID: Subject: Re: [PATCH RFC v1] pidfd: fix a race in setting exit_state for pidfd polling To: Christian Brauner Cc: Oleg Nesterov , "Joel Fernandes (Google)" , LKML , kernel-team , Andrea Arcangeli , Andrew Morton , "Eric W. Biederman" , Tejun Heo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 19, 2019 at 9:27 AM Christian Brauner wrote: > > On Fri, Jul 19, 2019 at 06:14:05PM +0200, Oleg Nesterov wrote: > > it seems that I missed something else... > > > > On 07/17, Joel Fernandes (Google) wrote: > > > > > > @@ -1156,10 +1157,11 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) > > > ptrace_unlink(p); > > > > > > /* If parent wants a zombie, don't release it now */ > > > - state = EXIT_ZOMBIE; > > > + p->exit_state = EXIT_ZOMBIE; > > > if (do_notify_parent(p, p->exit_signal)) > > > - state = EXIT_DEAD; > > > - p->exit_state = state; > > > + p->exit_state = EXIT_DEAD; > > > + > > > + state = p->exit_state; > > > write_unlock_irq(&tasklist_lock); > > > > why do you think we also need to change wait_task_zombie() ? > > > > pidfd_poll() only needs the exit_state != 0 check, we know that it > > is not zero at this point. Why do we need to change exit_state before > > do_notify_parent() ? > > Oh, because of?: > > /* > * Move the task's state to DEAD/TRACE, only one thread can do this. > */ > state = (ptrace_reparented(p) && thread_group_leader(p)) ? > EXIT_TRACE : EXIT_DEAD; > if (cmpxchg(&p->exit_state, EXIT_ZOMBIE, state) != EXIT_ZOMBIE) > return 0; > > So exit_state will definitely be set in this scenario. Good point. > Yes, I think you are right. AFAIU in this code path p->exit_state should always be equal to EXIT_TRACE because of the earlier cmpxchg() call and the if condition before do_notify_parent(). That's of course unless there is a chance that p->exit_state gets changed by some other thread after cmpxchg() call and before do_notify_parent()... I'm not that familiar with this code to say for sure that it's impossible. If that can't happen I think we can remove this one but the change in exit_notify() should definitely stay. Thanks, Suren. > Christian > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >