Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp388355rdh; Thu, 26 Oct 2023 05:16:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYuAduQVUf78/jzGaNaEqGlQRQeNuWjfqZ+FfryeNoPxoWLT6PULuwMKIuvt264OlJKvmp X-Received: by 2002:a81:52d3:0:b0:5a7:a838:3fa with SMTP id g202-20020a8152d3000000b005a7a83803famr18117271ywb.3.1698322608118; Thu, 26 Oct 2023 05:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698322608; cv=none; d=google.com; s=arc-20160816; b=SEAgkpxcziaBuQC3CrjYZc3eYVjtnp+QEJnqNc5A4aWzyD10kscwEZbXEcLr/4ZqTp DdP/Q2t0uQ6uG3/P/+4bTd/6VX8LZBx3Y5Rul0o/xRQglMcIl9L0Wx0Ed90q5XDOZXYQ W5p2KJUVGsXHojH85IbXFTMbB0+ZYGm1i6wytxKmlAgM8VQ4BJ72lSmVVYnqOcWpfMl+ 5fmAzpwk2GtSbt7DXWQqDH02SKcspWswoMtgUW3kqsD//p8CMm/Cb7VD+1YdilHinSZj 63WcH3lwgWU9SMoMOj6mv8XPLyDG3BMwXLDfKVPKVskLnBt7brbjSICKpxsRwvg2iikN f9yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XO8QG8mtg640mQEHVkNaf9/uSEs9JeitYsu0UTItPaY=; fh=ROvTK7RSnlfQ3sgY3hs6DNis3XDYDhCpQgmHVDBtX74=; b=r5i1UDHpluJs1hZ3gTLlfLPeP7lqKiYTafie926baJhnoN7BsYhEabkq+aZn1cSFxA uhSxITZGKOOuuLwyPdobQ/vXtmG/8qmkAqhOpBidHWfSZDuBKeHC49MQ+LDBBMgAnDSD 3lmkHJ+GhCutCcsYJCx6OFIfLgX2tujciZnKeB837Im/RYqcusUZh5hgm3/sffZAjEwQ yZGdAIFWIQOqC3XUlOvAQTiGX7KFExAO5JTzvKzS0gpkUr8SvSco+St37A0u4HcrlwI+ eYlptFwDh0H9/ZGqTUYY13d3qMN7Rg8b/ehpYEjZUniZnYXLtqT+z726J/IzsCX/LXLS BexQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EYx9yii6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id t64-20020a818343000000b0059c267a488asi14188972ywf.314.2023.10.26.05.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 05:16:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EYx9yii6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9CF5E8253FE1; Thu, 26 Oct 2023 05:16:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230505AbjJZMQk (ORCPT + 99 others); Thu, 26 Oct 2023 08:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbjJZMQj (ORCPT ); Thu, 26 Oct 2023 08:16:39 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F01D8B9 for ; Thu, 26 Oct 2023 05:16:36 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c9d132d92cso1655075ad.0 for ; Thu, 26 Oct 2023 05:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698322596; x=1698927396; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XO8QG8mtg640mQEHVkNaf9/uSEs9JeitYsu0UTItPaY=; b=EYx9yii6b/rzXBx4KU4/nBrcHsWJJDsvR95ktWQNk5/13R79Jz625TL2w01wyfjl6q okJYH9N1nupXgBF7Agjt0nCaNRm35IZJOdttUtb+hks6gf+zpuYTQYlzZVveu6uV9eDR extzggeGHZs0SQdvj0383gl1jiaALrVSoT58oeu28F5p49TEJBtFw1dh8fM0F6QzUySo 3hfvfMTP9splfwBNi0zhoTs/pvQPlN39ctYGKTMlGP43tThv3h6aAcWlqp6+lAXqsjZE ESbLzG/4cDLlk4RiGjzBc4NPyz/LyWy/a8ryIPY38UJp7WMzJ1vmOJhG0GyY2Ay40hfh rt0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698322596; x=1698927396; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XO8QG8mtg640mQEHVkNaf9/uSEs9JeitYsu0UTItPaY=; b=IGGWe6h4yGBhbHkyxrAHncNk0RVyW2Y3a6J57j88ky7BHm8gOJk3lzx7zOhbIP3yHx lfW0cHY2k+0OVi+uBIQu94uRzhBUgp6tE+W5t5Pp0il5P/j6cw/HFeJDLTDvcwj7gHH8 yobrF6r4OAOhA24SkuAo9p2fqi2Z8NNiUX5B3wffO3zb/Qb87gd3NmPAWRvkEuCnYlkS rG98C70hZnDPgzBJisTS4noPlJ9/x/jUHYaUR/BprsVr/oC55jDtY7M1cwS/x5S2NWKP 9AnDQSwsXDg616d0FqKbU53WQUnWn3oBG+gv2lvS+g8AYYHgVjiK1wGN5HdAqDaNdaqz a8zw== X-Gm-Message-State: AOJu0YxN9XizcCMXsC+QquKqxCiCrnLYYgBFNolNsEtX7PE4DdKgp7xR AMmqnU4G9yFu0D1PRmHH52g= X-Received: by 2002:a17:903:41c7:b0:1bf:349f:b85c with SMTP id u7-20020a17090341c700b001bf349fb85cmr17553128ple.1.1698322596368; Thu, 26 Oct 2023 05:16:36 -0700 (PDT) Received: from abhinav.. ([103.75.161.208]) by smtp.gmail.com with ESMTPSA id i13-20020a170902eb4d00b001bde65894c8sm691439pli.268.2023.10.26.05.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 05:16:36 -0700 (PDT) From: Abhinav Singh To: 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, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Abhinav Singh Subject: [PATCH v2] Fixing directly deferencing a __rcu pointer warning Date: Thu, 26 Oct 2023 17:46:21 +0530 Message-Id: <20231026121621.358388-1-singhabhinav9051571833@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> References: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 05:16:45 -0700 (PDT) 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; } @@ -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