Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp429073rdh; Thu, 26 Oct 2023 06:17:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgAxxMqZRJzrFIsdpKfUz02Cqx861ScqlWx6hoW3ixa0iak/Gnk7sBfHG79XeypwsDiaux X-Received: by 2002:a05:690c:f0b:b0:5a7:f002:4fe4 with SMTP id dc11-20020a05690c0f0b00b005a7f0024fe4mr24533178ywb.23.1698326230549; Thu, 26 Oct 2023 06:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698326230; cv=none; d=google.com; s=arc-20160816; b=nffmaa/7Qwc1sWjemBCvOoc1ZZPgKB5Zmz8yiLwVyIyfbtLwIDWRftxHma820twltG 2eN2kbZgZVQmiJwUTcJC3ePgahjNmzXBdk5Z2nllTb8QW3p5pFZuNlO+wWrL7USxgt6e 9ORaANj0qIwHSEc/5Wra+xYW3g40irs32+6+uVOJQB5dgjJuWLtGHtoPwKzuFPITNAKU 6Qz35kAtOp+OJbDC76voXi1SC6JsGx3wkQkdQVKAq6NK0+LdlhWXFl6Dp0l+nVS0hEXH KnK6OhHbHtjdVI0r8Bb8BFd/TtwHYvbFhY4wUTpqQhT+2uu2KmaA06yQd/cbNVLXsRF2 CfvQ== 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=ITxJfATsg1xPCVF9l8R+7SuGMBL1Ri8aZSO801+6WD8=; fh=+HpAxL+5ldwrD7x1xx+BlBm6eoyrtNEMKIByXNEvHDs=; b=TnOq/7TA3ddW3pEvo36uvQiOh8ANKZGefX4tuq4jiJ7hRxEFYiRhnw116iRjTVNonh Ijvxmit4RqAezNzvlanRg4O544+HSZdU1/VWeBNhwd7OzI0+z6/cbCct0EZEfn84muVp aZgtvf00y0yqMisd1Sj7FUth6gkVWDQO3rch8cRzm6EwYbcH4GgRCYpMp48zjMtnrBZ6 fO8FAwS/uiNE4aKHAlmJSvhAXpo5cAG3jly51XFUe7xjCWIKgMblp9atgSNsnaV0LhTu 6nOezu0TV49rV0HkUNlXyr3LsXDZHmnrO4D9NhSAWpVTxj6S4Gu9Qu8bXagbDQrGc7HK OWcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KgAPhmWC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t184-20020a0dd1c1000000b0056949de0ad3si14293961ywd.404.2023.10.26.06.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 06:17:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KgAPhmWC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 854F38069F30; Thu, 26 Oct 2023 06:15:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344950AbjJZNPV (ORCPT + 99 others); Thu, 26 Oct 2023 09:15:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbjJZNPU (ORCPT ); Thu, 26 Oct 2023 09:15:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029A4196 for ; Thu, 26 Oct 2023 06:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698326071; 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=ITxJfATsg1xPCVF9l8R+7SuGMBL1Ri8aZSO801+6WD8=; b=KgAPhmWCvdmoqFOGJ3gvTXI/BJmPa45Gq4Pi0hyS0m+9ZAiTfsSi9jVvZuT6t5+kZs3Ry0 cS0bdhWlyLMFsU4vHJzo3kTEBoS8qtiLJltL/nmDYojfPbSZYnB6N1qDZDebp9IKl10UjN 3PXUTViqZDNAy+0qKTBddQk3VJBerv0= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-FCMroX2NNjS2WDGfLJdQDA-1; Thu, 26 Oct 2023 09:14:29 -0400 X-MC-Unique: FCMroX2NNjS2WDGfLJdQDA-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-9c7558b89ccso60399766b.3 for ; Thu, 26 Oct 2023 06:14:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698326068; x=1698930868; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ITxJfATsg1xPCVF9l8R+7SuGMBL1Ri8aZSO801+6WD8=; b=e6cSPKqym+FTgB9PANpH2f1sdAlJHUDjbIggHFTu2xRMMaZnvLOBVVD6DPS9Rpj/Az armL7uo8c9yftIjtcG8Jxf7bNALKfFAVMpiu9U/umXmRc08JtceMnqLLS3yAWBPWapnS OmE9a8f6o6SS0vwQFbqlzQJGH084dZfW08n6gyNRSgvHgt8xrHme+Wtx4zJVvw83wfgN rrS+zHGUi9XJ7RKZ90qGH95aaHHyeIU3PyDDfPrSgGgp+zV/fm06jP7gPDDSGrfPnEFP aPPj8HnHzls7LE+pFw0qbBbnCLkE/Y5qys5M71DpgUuCNpXnEOYcW5cOoLWLL5R1SyZI S2nQ== X-Gm-Message-State: AOJu0Ywd31m9apHPeI4rZjOBmtAmEGrzDqKxiJZzHVdBEUnNnhJFTAcQ LnZoGUCtnRh4GLOo0Gd6FSnq/h6kiwiRaeC2tAc8xlp41rkXvHlmHsIFdWgwpEplZtfPhY0Extl Dn7GinI+TYWig9QfbzdzcrcdX X-Received: by 2002:a17:906:9c83:b0:9a1:bd33:4389 with SMTP id fj3-20020a1709069c8300b009a1bd334389mr13653856ejc.74.1698326068175; Thu, 26 Oct 2023 06:14:28 -0700 (PDT) X-Received: by 2002:a17:906:9c83:b0:9a1:bd33:4389 with SMTP id fj3-20020a1709069c8300b009a1bd334389mr13653833ejc.74.1698326067742; Thu, 26 Oct 2023 06:14:27 -0700 (PDT) Received: from redhat.com ([2a02:14f:17b:37eb:8e1f:4b3b:22c7:7722]) by smtp.gmail.com with ESMTPSA id 26-20020a170906011a00b009ae587ce128sm11636345eje.216.2023.10.26.06.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 06:14:27 -0700 (PDT) Date: Thu, 26 Oct 2023 09:14:21 -0400 From: "Michael S. Tsirkin" To: Abhinav Singh Cc: akpm@linux-foundation.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, mathieu.desnoyers@efficios.com, mjguzik@gmail.com, npiggin@gmail.com, shakeelb@google.com, peterz@infradead.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [PATCH v2] Fixing directly deferencing a __rcu pointer warning Message-ID: <20231026091222-mutt-send-email-mst@kernel.org> References: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> <20231026121621.358388-1-singhabhinav9051571833@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026121621.358388-1-singhabhinav9051571833@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 06:15:28 -0700 (PDT) On Thu, Oct 26, 2023 at 05:46:21PM +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 Well yes but these need to be called under rcu_read_lock. Who does it here? If no one then maybe you found an actual bug and we need to fix it not paper over it. > --- > 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; > } > @@ -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); > -- > 2.39.2