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 1FB90C32771 for ; Mon, 26 Sep 2022 06:48:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B91B900010; Mon, 26 Sep 2022 02:48:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7683E900002; Mon, 26 Sep 2022 02:48:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62FB8900010; Mon, 26 Sep 2022 02:48:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 51020900002 for ; Mon, 26 Sep 2022 02:48:33 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 24C451A03B0 for ; Mon, 26 Sep 2022 06:48:33 +0000 (UTC) X-FDA: 79953308106.18.DFD620B Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf30.hostedemail.com (Postfix) with ESMTP id 8BA1080002 for ; Mon, 26 Sep 2022 06:48:32 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MbYB66thtzHtmL; Mon, 26 Sep 2022 14:43:42 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 26 Sep 2022 14:48:28 +0800 Received: from [10.174.179.24] (10.174.179.24) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 26 Sep 2022 14:48:28 +0800 Subject: Re: [PATCH v4] mm: hugetlb: fix UAF in hugetlb_handle_userfault To: Andrew Morton References: <20220924034905.2694686-1-liushixin2@huawei.com> <20220925112826.c3efd2cf438d1bb6329f78ed@linux-foundation.org> CC: Liu Zixian , Mike Kravetz , Muchun Song , "Sidhartha Kumar" , John Hubbard , "David Hildenbrand" , Kefeng Wang , , From: Liu Shixin Message-ID: <174f5998-1f1d-c283-26bb-82c5a68150ab@huawei.com> Date: Mon, 26 Sep 2022 14:48:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20220925112826.c3efd2cf438d1bb6329f78ed@linux-foundation.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.24] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664174912; a=rsa-sha256; cv=none; b=2TuVNhJ0fQbr8iOxuiY9BXyXqKY0ziBUzgpq5yKvUakOoE7yGgIJX233psy+ZIYPGrZ415 /xtE6+hj5C3BJw0YtrtMre+xq7QsSBbHcPlMoDar0ALcR8XIG0MjJ3wn97z42uU61KbO/Y 8dch7gDXPUvWTw7Yx7YzLUmZ7yV/nwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664174912; 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=xVtnuPUc45cKLbcqFsGdpBIOgjRfRQ1kmtuR2u9buY0=; b=zyw01LT9LejcrwjPjZknQ0FxWlL/uxpeUlFKoUiswF/MoMxRHXA769v9y7/0peq4eblsXK qCc+5DMq1wuVcgBSKbnnCGmX5QAoFcno7hBFjXH35E2IcTGjdEKxsUuoX+Hx6txejVwTVH L/PZUjJrUieaKf4Rdqg/f5wkGmtOBEU= X-Stat-Signature: astdiohhsbb4qdco3t5wdhxdxoto8m8c X-Rspamd-Queue-Id: 8BA1080002 Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1664174912-167042 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 2022/9/26 2:28, Andrew Morton wrote: > On Sat, 24 Sep 2022 11:49:05 +0800 Liu Shixin wrote: > >> The vma_lock and hugetlb_fault_mutex are dropped before handling >> userfault and reacquire them again after handle_userfault(), but >> reacquire the vma_lock could lead to UAF[1,2] due to the following >> race, >> >> hugetlb_fault >> hugetlb_no_page >> /*unlock vma_lock */ >> hugetlb_handle_userfault >> handle_userfault >> /* unlock mm->mmap_lock*/ >> vm_mmap_pgoff >> do_mmap >> mmap_region >> munmap_vma_range >> /* clean old vma */ >> /* lock vma_lock again <--- UAF */ >> /* unlock vma_lock */ >> >> Since the vma_lock will unlock immediately after hugetlb_handle_userfault(), >> let's drop the unneeded lock and unlock in hugetlb_handle_userfault() to fix >> the issue. >> > Thanks. Turns out that porting all the pending material on top of this > change was not a confidence-inspiring activity. So I ended up merging > your v3. Please work with Greg on the backporting when he gets on to > it? Hopefully that will merely involve sending him this v4. OK, I'll do it. > . >