From patchwork Sat Mar 13 05:08:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12136481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB6A6C433E0 for ; Sat, 13 Mar 2021 05:08:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 58E1B64F94 for ; Sat, 13 Mar 2021 05:08:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58E1B64F94 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EBFD46B0089; Sat, 13 Mar 2021 00:08:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E96096B008A; Sat, 13 Mar 2021 00:08:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D85786B008C; Sat, 13 Mar 2021 00:08:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id BCB816B0089 for ; Sat, 13 Mar 2021 00:08:05 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 82B07180238DF for ; Sat, 13 Mar 2021 05:08:05 +0000 (UTC) X-FDA: 77913669330.20.5C20D9D Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf18.hostedemail.com (Postfix) with ESMTP id 5940220001DC for ; Sat, 13 Mar 2021 05:08:06 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F9CD64E41; Sat, 13 Mar 2021 05:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1615612084; bh=Wi6CK4S8qvNeM9MEPQ16Q3IB5iWStis3UQzR38APEZ4=; h=Date:From:To:Subject:In-Reply-To:From; b=GO4xTX9nZPWszKYY/jdgqGY6VVU9eqUt4fB2ZuaoWU0a9B7+qz/90YFy5Hjm83vf+ sC978aGhRiU6JIrrDOwPJ9oHcocWh824Kg8TYIqOccZd8hpWR5CAqDQ3KJyuoBs9Nw to00u+a0Zg8MG4UEG4EsgFvhiitHY/Xq2zfPeJPs= Date: Fri, 12 Mar 2021 21:08:03 -0800 From: Andrew Morton To: akpm@linux-foundation.org, linmiaohe@huawei.com, linux-mm@kvack.org, mhocko@suse.com, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, willy@infradead.org Subject: [patch 18/29] include/linux/sched/mm.h: use rcu_dereference in in_vfork() Message-ID: <20210313050803.CFTW-ffYI%akpm@linux-foundation.org> In-Reply-To: <20210312210632.9b7d62973d72a56fb13c7a03@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Stat-Signature: ns5rcmhz5uicsgzc7yj19ouh8ow6e1qj X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5940220001DC Received-SPF: none (linux-foundation.org>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=mail.kernel.org; client-ip=198.145.29.99 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615612086-840200 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" Subject: include/linux/sched/mm.h: use rcu_dereference in in_vfork() Fix a sparse warning by using rcu_dereference(). Technically this is a bug and a sufficiently aggressive compiler could reload the `real_parent' pointer outside the protection of the rcu lock (and access freed memory), but I think it's pretty unlikely to happen. Link: https://lkml.kernel.org/r/20210221194207.1351703-1-willy@infradead.org Fixes: b18dc5f291c0 ("mm, oom: skip vforked tasks from being selected") Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Miaohe Lin Acked-by: Michal Hocko Signed-off-by: Andrew Morton --- include/linux/sched/mm.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/linux/sched/mm.h~mm-use-rcu_dereference-in-in_vfork +++ a/include/linux/sched/mm.h @@ -140,7 +140,8 @@ static inline bool in_vfork(struct task_ * another oom-unkillable task does this it should blame itself. */ rcu_read_lock(); - ret = tsk->vfork_done && tsk->real_parent->mm == tsk->mm; + ret = tsk->vfork_done && + rcu_dereference(tsk->real_parent)->mm == tsk->mm; rcu_read_unlock(); return ret;