From mboxrd@z Thu Jan 1 00:00:00 1970 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.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 EB607C433DB for ; Mon, 22 Feb 2021 01:45:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 65A9D601FA for ; Mon, 22 Feb 2021 01:45:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65A9D601FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9879B6B0006; Sun, 21 Feb 2021 20:45:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 936D16B006C; Sun, 21 Feb 2021 20:45:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8739B6B006E; Sun, 21 Feb 2021 20:45:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 71E186B0006 for ; Sun, 21 Feb 2021 20:45:02 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2DA2D180ACEFC for ; Mon, 22 Feb 2021 01:45:02 +0000 (UTC) X-FDA: 77844210444.14.886A7DD Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf22.hostedemail.com (Postfix) with ESMTP id 62681C0001EE for ; Mon, 22 Feb 2021 01:44:58 +0000 (UTC) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DkQ1G0XTMzMccn; Mon, 22 Feb 2021 09:42:58 +0800 (CST) Received: from [10.174.179.140] (10.174.179.140) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Mon, 22 Feb 2021 09:44:53 +0800 Subject: Re: [PATCH] mm: Use rcu_dereference in in_vfork To: "Matthew Wilcox (Oracle)" CC: , Michal Hocko , , Andrew Morton References: <20210221194207.1351703-1-willy@infradead.org> From: Miaohe Lin Message-ID: <28850db2-687d-e604-2bd3-3a72344c1e7d@huawei.com> Date: Mon, 22 Feb 2021 09:44:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210221194207.1351703-1-willy@infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.140] X-CFilter-Loop: Reflected X-Stat-Signature: rmy1n7xysqhwcimfuz8oy3opbiu44a9e X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 62681C0001EE Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=szxga05-in.huawei.com; client-ip=45.249.212.191 X-HE-DKIM-Result: none/none X-HE-Tag: 1613958298-555116 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: On 2021/2/22 3:42, Matthew Wilcox (Oracle) wrote: > 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. > > Fixes: b18dc5f291c0 ("mm, oom: skip vforked tasks from being selected") > Signed-off-by: Matthew Wilcox (Oracle) Looks good to me. Thanks! Reviewed-by: Miaohe Lin > --- > include/linux/sched/mm.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > index 1ae08b8462a4..90b2a0bce11c 100644 > --- a/include/linux/sched/mm.h > +++ b/include/linux/sched/mm.h > @@ -140,7 +140,8 @@ static inline bool in_vfork(struct task_struct *tsk) > * 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; >