From patchwork Tue Aug 23 03:23:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12951678 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 2F695C32789 for ; Tue, 23 Aug 2022 03:24:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1ED398D0007; Mon, 22 Aug 2022 23:24:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12A788D0006; Mon, 22 Aug 2022 23:24:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E96E98D0007; Mon, 22 Aug 2022 23:24:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D66A98D0006 for ; Mon, 22 Aug 2022 23:24:24 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B0EC0160677 for ; Tue, 23 Aug 2022 03:24:24 +0000 (UTC) X-FDA: 79829414448.28.7D3DA75 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf09.hostedemail.com (Postfix) with ESMTP id 8039E14003C for ; Tue, 23 Aug 2022 03:24:23 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MBZHm3PTVzgYpk; Tue, 23 Aug 2022 11:20:52 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 23 Aug 2022 11:24:20 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH v2 4/6] mm, hwpoison: fix possible use-after-free in mf_dax_kill_procs() Date: Tue, 23 Aug 2022 11:23:44 +0800 Message-ID: <20220823032346.4260-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220823032346.4260-1-linmiaohe@huawei.com> References: <20220823032346.4260-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661225063; a=rsa-sha256; cv=none; b=5FGsLXz4VA7vdbm8KacnDk2CdekQkkcsDORfI817K7oi1g3OxLmNN/yIqEf1cXZT7LVJsG WjAAhCnhrs0nLwDdSFC3v2PhQXhzOedk503EeNHo8kR6wpcgx9pwqLZMnAHVSnOmKz2z05 3g3VmJhrzxvWqrnYcAVvtLgY3d6NE+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661225063; 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; bh=pFYEpTsXJmHfW6I1oKg6c4BgDdCtGcow54ssxC/v4Go=; b=sLO1GH2V1v4baROFWLdtSXAREJjn43H3fGSxOKO5QRZl6ub4xIOg6GQE/DFLovxgLFf+8g v+mMWlwlEWcWXeJYmO5eAYBXma10gZDDhBUL+biHTTGs9Ua6lF2mbCYNZ51CimLLeucWPn tZHItZFpGqmblzzVlXdaw/QF/NLktGA= X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: 953b7b6y18uef9zga77fju773da6689y X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8039E14003C X-HE-Tag: 1661225063-303702 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: After kill_procs(), tk will be freed without being removed from the to_kill list. In the next iteration, the freed list entry in the to_kill list will be accessed, thus leading to use-after-free issue. Adding list_del() in kill_procs() to fix the issue. Fixes: c36e20249571 ("mm: introduce mf_dax_kill_procs() for fsdax case") Signed-off-by: Miaohe Lin Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 1d79e693f1b9..f8262f577baf 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -413,7 +413,7 @@ static void kill_procs(struct list_head *to_kill, int forcekill, bool fail, { struct to_kill *tk, *next; - list_for_each_entry_safe (tk, next, to_kill, nd) { + list_for_each_entry_safe(tk, next, to_kill, nd) { if (forcekill) { /* * In case something went wrong with munmapping @@ -437,6 +437,7 @@ static void kill_procs(struct list_head *to_kill, int forcekill, bool fail, pr_err("%#lx: Cannot send advisory machine check signal to %s:%d\n", pfn, tk->tsk->comm, tk->tsk->pid); } + list_del(&tk->nd); put_task_struct(tk->tsk); kfree(tk); }