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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 948E2ECAAD3 for ; Wed, 14 Sep 2022 22:35:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10B0B6B0073; Wed, 14 Sep 2022 18:35:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BAAF6B0074; Wed, 14 Sep 2022 18:35:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEADC8D0001; Wed, 14 Sep 2022 18:35:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E00236B0073 for ; Wed, 14 Sep 2022 18:35:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B2E14C0245 for ; Wed, 14 Sep 2022 22:35:46 +0000 (UTC) X-FDA: 79912149492.27.2E9E7DF Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf07.hostedemail.com (Postfix) with ESMTP id 394B540090 for ; Wed, 14 Sep 2022 22:35:46 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7AC64B81CEC; Wed, 14 Sep 2022 22:35:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4F73C433C1; Wed, 14 Sep 2022 22:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1663194943; bh=V3UnjH8r8/HZCf/bUXEv6LLNwHtF7DQP1lCGuLGnSdc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BuIdCB2Dng/VZh/rE6kuH/hBzh9AoNuhbKvfiKDY76Tsl76mj9UVm+7dE7qLi0fqT X8WEcEkV5ma5YeYJP+ZkT+5+gAg7jodnZakuRY66tb/J2kAdVOSnvZafZJ1TKgy1qU 0wU9+nOA78D4kzV6UZL6EgRZszStVxVumn2JCTnQ= Date: Wed, 14 Sep 2022 15:35:42 -0700 From: Andrew Morton To: Shuai Xue Cc: naoya.horiguchi@nec.com, linmiaohe@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cuibixuan@linux.alibaba.com, baolin.wang@linux.alibaba.com, zhuo.song@linux.alibaba.com, Huang Ying Subject: Re: [PATCH] mm,hwpoison: check mm when killing accessing process Message-Id: <20220914153542.285f870f728c6129a479a69d@linux-foundation.org> In-Reply-To: <20220914064935.7851-1-xueshuai@linux.alibaba.com> References: <20220914064935.7851-1-xueshuai@linux.alibaba.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663194946; a=rsa-sha256; cv=none; b=PWkBUjLpH1Ia72AMoiT2niEW5BZkgdvhpzzt4PpxvSKHDtky3WE1ZM8SPqsh/VbZFuFDc7 IeqbG9vGfsI1fYqn3zQAtSuT6Louy10ji/eO6OWU2VIcF2x2soi+qYqr4spBAwqCOCwn9O wob4nYxuvhU65EllgbH/Exix3PorWs8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=BuIdCB2D; dmarc=none; spf=pass (imf07.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663194946; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3M6Rx47eVZFkw6BYdlIzCxzWQ8Movj35erGXuZD4gLE=; b=1wfINfcj8PODHgNfN3rZDoiMuwfpthSqh19b12acOWJgHZPa0l7ilddHGemkMbIHLCme+m B8xgZ7RdQFjGAa+ZrLXDmgXe7NzjSWwAl/IXNd4D3yCrLYQoRrMXYHnDdJA6pLswQ7XklB 3VNDnKZ83iSqaFt52Xy0/rpv6CLLAME= X-Rspam-User: X-Rspamd-Queue-Id: 394B540090 X-Rspamd-Server: rspam05 X-Stat-Signature: kd1rtqiz3hpgfp9qwe5rhjupu6gtq18r Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=BuIdCB2D; dmarc=none; spf=pass (imf07.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1663194946-527801 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 Wed, 14 Sep 2022 14:49:35 +0800 Shuai Xue wrote: > The GHES code calls memory_failure_queue() from IRQ context to queue work > into workqueue and schedule it on the current CPU. Then the work is > processed in memory_failure_work_func() by kworker and calls > memory_failure(). > > When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send > SIGBUS with error virutal address") make memory_failure() call > kill_accessing_process() that: > > - holds mmap locking of current->mm > - does pagetable walk to find the error virtual address > - and sends SIGBUS to the current process with error info. > > However, the mm of kworker is not valid. Therefore, check mm when killing > accessing process. Thanks. When fixing a bug, please always describe the user-visible effects of tha bug. I'm thinking "null pointer deref crashes the kernel". > Fixes: a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") > Signed-off-by: Shuai Xue I'll add cc:stable. > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, > }; > priv.tk.tsk = p; > > + if (!p->mm) > + return -EFAULT; > + > mmap_read_lock(p->mm); > ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops, > (void *)&priv); > @@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, > else > ret = 0; > mmap_read_unlock(p->mm); > + > return ret > 0 ? -EHWPOISON : -EFAULT; > } This is an unrelated change which doesn't appear to match the style in memory-failure.c, so I'll drop this hunk.