Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp505036rdh; Thu, 26 Oct 2023 08:04:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAzmoFIIxlq83oyW93fnicK/SCF1Yr8zO9JYK4n6i8ThkK1TEQtUlHB2TjruVCQaO6BEDJ X-Received: by 2002:a1f:ac83:0:b0:493:5420:f20c with SMTP id v125-20020a1fac83000000b004935420f20cmr35946vke.10.1698332682142; Thu, 26 Oct 2023 08:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698332682; cv=none; d=google.com; s=arc-20160816; b=uV6KcLxXwE/dfeLlXQZyN4Z4Un1MJ5A47ELYCjVMIErbaKlrTy7PQj+M6or3tgGaDm 0QgBIoQPdJt8sW+Y2H/n0TVwXZP/qmNfIhEzla6NoywNyb0hDuDGqiuP/IRdO06FRH/p yS2ABcSjSeHiUkqI3z8LH3I3YfF/tEQtlFqYSE+/OatfaBLiDfOACFVCwUk+MMHmj8dT zb3Ecf1jImmmn2GfFVv8B29bX4EWkHtNZG8eFDfPt0yfnbdRduYUlgfxGVrQ8w6vtJJD n+a8UEZFOtQwasgNdt16L8SQHOErdEysUfTh/+4/aUgRode8DPxV7UmPrGe0ECeLWhKG nu9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9JXxaYRYmSkXZPyr8is9yL820vMXmViHhclzJzT9u/0=; fh=Sdk/8eEUdWJ9x7q0Vt41DZE50PG7DdO8mBCbrU/DnW8=; b=fzBMu9ryh3Pfy313e/FQwkN3XH3UvqTf2iLR7IVt52j7CxKXGRmWxI06UVaBUHCFSR 8ffnfCGP231gnAEqGxTxpoRmj/0uzWJLP8GxWVmLG0/fzefsNwEVsdiqhNW+7yUZ/UgX BzW0EktvqmjBMvxb8oZtLU7IGiUZQVAndrfk0ELI2pWGOne1MVxbz+ocWVxARudiUzq2 Zc08ilorXaMySZOEUV01RNBb/aJETFzjyDvX0f/pFQk9ifRP2gZHuZ5d2KNcO6vtfErq Yze179yiVzAy/TJ6Sed85Qv2MnnLGQZleq7BVSJaKiXkLZj+wEB7zBu+C+i9zcu+J9f6 ArnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=gBpFbiWz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id c124-20020a1f4e82000000b0048f884dc2acsi409924vkb.306.2023.10.26.08.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 08:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=gBpFbiWz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 39F5B8044804; Thu, 26 Oct 2023 08:04:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231630AbjJZPEE (ORCPT + 99 others); Thu, 26 Oct 2023 11:04:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345381AbjJZPDy (ORCPT ); Thu, 26 Oct 2023 11:03:54 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A20C129 for ; Thu, 26 Oct 2023 08:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=9JXxaYRYmSkXZPyr8is9yL820vMXmViHhclzJzT9u/0=; b=gBpFbiWzvbN93E3gafQXCGxQBO ZSRav/VBD5HLDT8ZoEjvC6BQx9M8rOSPOl3QEL2PxZUica4i+xwjVcn61jv2Jx2gZfK1q0foO3Lo3 Oiypa5M9U9YPf+fSJx49QNhrGHCSW4bZi3PDLdVfh1eP6sabdCH0WNYIoW/iplHVq31ZtUdXFe7ir M3edVB7Rp+rv3K3V2yPu3pG8/v0iWRs7lui6RKLdd0ZNHVXDWnwfwcoWsFCYKh/FqvZzvC+1EZKja L1LFoF4WrZX2K+RdI3adZpZsKsMB/6MVURIeoSKdNGqSQp5dSTJxdSHyuYxycLNdlEagrQyB+NcXP hHT0qaPQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qw1tP-00HPi2-0s; Thu, 26 Oct 2023 15:03:27 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id E9257300473; Thu, 26 Oct 2023 17:03:26 +0200 (CEST) Date: Thu, 26 Oct 2023 17:03:26 +0200 From: Peter Zijlstra To: Abhinav Singh Cc: 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, Oleg Nesterov , dhowells@redhat.com Subject: Re: [PATCH] Fixing directly deferencing a __rcu pointer warning Message-ID: <20231026150326.GA33303@noisy.programming.kicks-ass.net> References: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> <20231026122748.359162-1-singhabhinav9051571833@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026122748.359162-1-singhabhinav9051571833@gmail.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 26 Oct 2023 08:04:38 -0700 (PDT) $Subject should indicate a subsystem, also you seem to have a somewhat random collection of Cc. It looks like dhowells is the cred guy and he's not on. On Thu, Oct 26, 2023 at 05:57:48PM +0530, Abhinav Singh wrote: > This patch fixes the warning about directly dereferencing a pointer > tagged with __rcu annotation. > > Dereferencing the pointers tagged with __rcu directly should > always be avoided according to the docs. There is a rcu helper > functions rcu_dereference(...) to use when dereferencing a __rcu > pointer. This functions returns the non __rcu tagged pointer which > can be dereferenced just like a normal pointers. > > Signed-off-by: Abhinav Singh > --- > 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.