Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1116241rdh; Fri, 27 Oct 2023 05:24:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF91apbmWpWetuln0xB42gnrm4ZwcsbzZZnbV4OWxG71TAf1vx/JzacjtRQRtu3Ob1jRvuT X-Received: by 2002:a81:8b44:0:b0:5a7:af89:c4a0 with SMTP id e4-20020a818b44000000b005a7af89c4a0mr2708576ywk.23.1698409472285; Fri, 27 Oct 2023 05:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698409472; cv=none; d=google.com; s=arc-20160816; b=ZWhRXIbYUm6txo2U+68ylQZQ2O9Dg85HEnOfX3U8YQn1c/c9hcIU5eeYZOK3n67xMk l+BvTWkcp6xuZVxIF1FAQ1bxjtNWwBoc4Ws87/ZOdNzaakw8WUMf+kCdB+pwES5WiDlO 7RLypKAjzvi1nfHSqAusGSzM48Ifmv+otStRwqhY5RgYFxuFHZ76F8a5hAna71djfbCZ JjXnrJAVZZ4IjW9GqXJrJUOCVLKUTrxZVVf02BiXOOYCmhZTDySwpYu79hEy+aZpo48S D9CsT8huPQT6vyqoSlDv2M1x31XNfQv4Kuw+VwojDzItHaPdzCF6NBTdDb1nBUjYR7OY Av4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=tkI6B2xxBoNMxixcFLfMBk3z+VWHlMmRd9oe0BnBgsM=; fh=BEVR3gEtedHFo9d+Y5OBlQVAwuIhRow4g9eHCvPpdP8=; b=Z2viNckxzvGewCCpmsTYg/ESjtPYjmtqCbS9G0C7L2QKqBXywhEA2sG1udq7eSTYUU MFC0YNleS0JgI8yo6Teetukvs78tzXxs3lahbmIusxXQOAy+qFYk6Xa33c8kF/ReQjX4 /qPdYKguc3SeCvSNoCxGHvczV2oMC8WRN3L1jJLyaBkDdPau/ZodmMBD74Tw01+vtXwd H9yh5kAnnnU/CoioB+wBcmSn/iGs4GH88Ruwp5SN5sSgLjtk+A8BQ+TZ+1054xHXSNJn ZWWLuhaUowu+jqBmzMR1Igvm5x+rqG2wYK+HZcK6JHNlxfZKcoxZJuwELzzcOFOXwlFH e7hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EUbBWhcn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id r63-20020a818142000000b0059ef05231e7si2333537ywf.263.2023.10.27.05.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 05:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EUbBWhcn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3C2E0833E951; Fri, 27 Oct 2023 05:24:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231386AbjJ0MYW (ORCPT + 99 others); Fri, 27 Oct 2023 08:24:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjJ0MYV (ORCPT ); Fri, 27 Oct 2023 08:24:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8925C0 for ; Fri, 27 Oct 2023 05:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698409412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tkI6B2xxBoNMxixcFLfMBk3z+VWHlMmRd9oe0BnBgsM=; b=EUbBWhcnySq8ZvKQsDB5zjgRJ/Muwkbo9n2ouStUovZz5oiFJVSePKmhV2543qmhdYH229 ijsz1jD31eXxiK1dMgJYUVdPdCyZSzL90hVNnBrCUwI5pOCO6pT5XIqvgCUuTYCwUlPN0c KiXH3EAzAwwsb05/HfazM2B2Kw56Iec= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-qQUfIefFO4Wj4C4LLyDvuw-1; Fri, 27 Oct 2023 08:23:27 -0400 X-MC-Unique: qQUfIefFO4Wj4C4LLyDvuw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E336828AC9; Fri, 27 Oct 2023 12:23:27 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.76]) by smtp.corp.redhat.com (Postfix) with SMTP id EA3221C060AE; Fri, 27 Oct 2023 12:23:23 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 27 Oct 2023 14:22:26 +0200 (CEST) Date: Fri, 27 Oct 2023 14:22:22 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: Abhinav Singh , akpm@linux-foundation.org, brauner@kernel.org, surenb@google.com, mst@redhat.com, michael.christie@oracle.com, mathieu.desnoyers@efficios.com, mjguzik@gmail.com, npiggin@gmail.com, shakeelb@google.com, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, dhowells@redhat.com Subject: Re: [PATCH] Fixing directly deferencing a __rcu pointer warning Message-ID: <20231027122221.GA24128@redhat.com> References: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> <20231026122748.359162-1-singhabhinav9051571833@gmail.com> <20231026150326.GA33303@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026150326.GA33303@noisy.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 05:24:29 -0700 (PDT) On 10/26, Peter Zijlstra wrote: > > > kernel/fork.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/fork.c b/kernel/fork.c > > index 10917c3e1f03..802b7bbe3d92 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -2369,7 +2369,7 @@ __latent_entropy struct task_struct *copy_process( > > > > retval = -EAGAIN; > > if (is_rlimit_overlimit(task_ucounts(p), UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC))) { > > - if (p->real_cred->user != INIT_USER && > > + if (rcu_dereference(p->real_cred)->user != INIT_USER && > > !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) > > goto bad_fork_cleanup_count; > > } > > This seems entirely misguided and only makes the code more confusing. > > AFAICT at this point @p is not life, we're constructing the new task, > but it's not yet published, therefore no concurrency possible. > Additionally we're not actually in an RCU critical section afaict. > > > @@ -2692,7 +2692,7 @@ __latent_entropy struct task_struct *copy_process( > > */ > > p->signal->has_child_subreaper = p->real_parent->signal->has_child_subreaper || > > p->real_parent->signal->is_child_subreaper; > > - list_add_tail(&p->sibling, &p->real_parent->children); > > + list_add_tail(&p->sibling, &(rcu_dereference(p->real_parent)->children)); > > list_add_tail_rcu(&p->tasks, &init_task.tasks); > > attach_pid(p, PIDTYPE_TGID); > > attach_pid(p, PIDTYPE_PGID); > > As to the real_parent, we hold the tasklist lock, which is the write > side lock for parent stuff, so rcu dereference is pointless here. Agreed. Plus I don't think this change is correct, iiuc rcu_dereference() will trigger the run-time "suspicious rcu_dereference_check() usage" warning, it is called without rcu_read_lock(). Oleg.