Message ID | d3d9ff14-ef8-8f84-e160-bfa1f5794275@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 32D96C001B0 for <linux-mm@archiver.kernel.org>; Sun, 23 Jul 2023 22:32:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7BA46B0071; Sun, 23 Jul 2023 18:32:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2B338D0001; Sun, 23 Jul 2023 18:32:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F2146B0075; Sun, 23 Jul 2023 18:32:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7DDCB6B0071 for <linux-mm@kvack.org>; Sun, 23 Jul 2023 18:32:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3A48E807CA for <linux-mm@kvack.org>; Sun, 23 Jul 2023 22:32:38 +0000 (UTC) X-FDA: 81044327196.29.24F0412 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by imf07.hostedemail.com (Postfix) with ESMTP id 71DEB40014 for <linux-mm@kvack.org>; Sun, 23 Jul 2023 22:32:35 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=6TW6tzdC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690151555; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6mJ5yjUa61OKtsotomDyQc7p3NQ997kyi3UbHr9vQck=; b=vtUKgDC1xtao1gS44Bq5x120AAO5mmhkyeHbIfEiE2orrejUQHuHsQzMRiKBgQi2H7K2RM SdnKCun0KFfcUCoz7W+dPqwlc7xhLezeenNfA+s0KuM46NVbgXSpape5yggSULv6D036TB S83tSzUUAxlO3EJ8Gx3KrjLxSNYen5k= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=6TW6tzdC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of hughd@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690151555; a=rsa-sha256; cv=none; b=SFf7XgVQCBSgWio6hi6Ub91KvbxagAzXygTHjHhF07TDd2iZJRMvzAtGSLB1iKIVAV7pHr pIamb3vmv+xO+iIJPqhm9AHUFg4rWDk4K1rkYidq2OuX5OkdnX9LtzeFYBSr1J7lBQ0eJ6 pNbuVN7TIu5YEIAikS4Szq4IWWRIlvA= Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-577ddda6ab1so56214277b3.0 for <linux-mm@kvack.org>; Sun, 23 Jul 2023 15:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690151554; x=1690756354; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=6mJ5yjUa61OKtsotomDyQc7p3NQ997kyi3UbHr9vQck=; b=6TW6tzdCv/zJZetW3at30hfzlMddap7Z7fj+GldyzIgigr6T/xHW6mjhCM4pvSj3Q5 h5TyPuiLMyS54ezUO7aFMsJB86VYDD1vKE694/gkNGbdnL9iY77JcmkcNUGvyjawJaIq BjAE9MN2ZbLEq/LNBLIFuF2Ek09JgxgKNG9cXLscgacxJQ5lJbuWKmjJuALrca8xMAt3 5DroplM2hCTuaQrXESdTEpiFCx+/8R7A51nPLTYCGWcc5xPkH47MNRHi+ctmstGgrSf9 eVsau7CwzmMa2SBw+NS5ElWiu1xHP1FxRVmTB4ePG0Chh3dV63YJC00zhVrRRqL4zgXj HBcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690151554; x=1690756354; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6mJ5yjUa61OKtsotomDyQc7p3NQ997kyi3UbHr9vQck=; b=Apq/iB2Q/YRVGdJ3h4Z4vgKXrE+/2Yvaxe9N4Sv3r0sJLbwNPN3p8aRkue1lXLdpZ0 kQhbDYHKKCJBRxuSwqcv/YK3V0+18ZF9SxEQzn+U/X1g65ifT/DuFbydKQRRexl+U/ro w/uneYvW6SZ09wq8NqhQ40IuPNwyHJ17cTQyCugih0wbhpmOOXAYqP1HT3b3rpihICnL okFBCoObxMje5PSk/vrRrlKELIw1CQ9NfMLSHNZXXlKFCrEZNx7L33hLTI4mOj28kpdv LAKyr0W62JvXQ39IJjqUVbM5W+HMAREce5QsizwOQdqx8Xor4Pw/De+TRF11ns2dxi9h v0eQ== X-Gm-Message-State: ABy/qLYyMk18ORmTOv3u9izLWUkuBwbOIGjQ6KDVWE4zPKQnULxYMaiD wM4Fcj7lt3gINoKUiNfE9zlBCw== X-Google-Smtp-Source: APBJJlHufBlazAq/Jg+6fKB/G5aofMpIvebr8HbzAqYoBP3QAOOO5H84n4F6vZlA+flxU3ygHkBQcw== X-Received: by 2002:a0d:e211:0:b0:583:4064:a35f with SMTP id l17-20020a0de211000000b005834064a35fmr4569918ywe.23.1690151554487; Sun, 23 Jul 2023 15:32:34 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id n189-20020a8172c6000000b005771bb5a25dsm2391276ywc.61.2023.07.23.15.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 15:32:34 -0700 (PDT) Date: Sun, 23 Jul 2023 15:32:27 -0700 (PDT) From: Hugh Dickins <hughd@google.com> X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton <akpm@linux-foundation.org> cc: Mike Kravetz <mike.kravetz@oracle.com>, Mike Rapoport <rppt@kernel.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Matthew Wilcox <willy@infradead.org>, David Hildenbrand <david@redhat.com>, Suren Baghdasaryan <surenb@google.com>, Qi Zheng <zhengqi.arch@bytedance.com>, Yang Shi <shy828301@gmail.com>, Mel Gorman <mgorman@techsingularity.net>, Peter Xu <peterx@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Will Deacon <will@kernel.org>, Yu Zhao <yuzhao@google.com>, Alistair Popple <apopple@nvidia.com>, Ralph Campbell <rcampbell@nvidia.com>, Ira Weiny <ira.weiny@intel.com>, Steven Price <steven.price@arm.com>, SeongJae Park <sj@kernel.org>, Lorenzo Stoakes <lstoakes@gmail.com>, Huang Ying <ying.huang@intel.com>, Naoya Horiguchi <naoya.horiguchi@nec.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, Zack Rusin <zackr@vmware.com>, Jason Gunthorpe <jgg@ziepe.ca>, Axel Rasmussen <axelrasmussen@google.com>, Anshuman Khandual <anshuman.khandual@arm.com>, Pasha Tatashin <pasha.tatashin@soleen.com>, Miaohe Lin <linmiaohe@huawei.com>, Minchan Kim <minchan@kernel.org>, Christoph Hellwig <hch@infradead.org>, Song Liu <song@kernel.org>, Thomas Hellstrom <thomas.hellstrom@linux.intel.com>, Russell King <linux@armlinux.org.uk>, "David S. Miller" <davem@davemloft.net>, Michael Ellerman <mpe@ellerman.id.au>, "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>, Heiko Carstens <hca@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Claudio Imbrenda <imbrenda@linux.ibm.com>, Alexander Gordeev <agordeev@linux.ibm.com>, Gerald Schaefer <gerald.schaefer@linux.ibm.com>, Vasily Gorbik <gor@linux.ibm.com>, Jann Horn <jannh@google.com>, Vishal Moola <vishal.moola@gmail.com>, Vlastimil Babka <vbabka@suse.cz>, Zi Yan <ziy@nvidia.com>, linux-arm-kernel@lists.infradead.org, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 10/13 fix] mm/khugepaged: collapse_pte_mapped_thp() with mmap_read_lock(): fix In-Reply-To: <b53be6a4-7715-51f9-aad-f1347dcb7c4@google.com> Message-ID: <d3d9ff14-ef8-8f84-e160-bfa1f5794275@google.com> References: <7cd843a9-aa80-14f-5eb2-33427363c20@google.com> <b53be6a4-7715-51f9-aad-f1347dcb7c4@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 71DEB40014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3jas46eqz5s9x8o73qp9o7u4o5w4k41q X-HE-Tag: 1690151555-954156 X-HE-Meta: U2FsdGVkX19DkVhzV48uQmi/jKfBTLUPIwhn41GSa3Qjs4RxXzQ469B8gENhAnrAIuGP5DndBr8d/Db/0mpFat2Xn5SNek4AEtQ7hO4KSOTCyDSsB24nidj1Jd+QKmMzh1Sb2zV2LyD3llmDejlPJ9b4I5E6kKRAnWPXjCfbJCcTa0fU+fwjHTQg9kE7siFQJGBiZdxl43vG0iJPb2ffrVLSTr+YVFfEnD61eoy6j4m1YcuFcuqyhRakOQan+ywupshiKvR+J5fZSxKRk8hEMExu44diUU4CtKBTi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kPqzm66BXVS/JMPJ3ISyoPu+OZdWSs478e9zm/YMruKKjHHuKEJrRoS848PDi5DzRf5q5xBXV0cko+c32Xzn40TdCnLaBfRZvLKa+ygjswAez/I27y4Wbo7Vtth2ruA648BJr/SB3cs3ZCS8+XwLWZMOavHMjhX52gOWSatSPCHYHfa8pZKn8Pzv7mZcis9aonG2sqI7soYwYkH3PeD+jPLyIYtNR1O8tZYJHQ/R3T/nffS8ls/6Aqw== 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: <linux-mm.kvack.org> |
Series |
None
|
expand
|
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6bad69c0e4bd..1c773db26e88 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2747,7 +2747,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, BUG_ON(*prev); mmap_read_lock(mm); result = collapse_pte_mapped_thp(mm, addr, true); - mmap_locked = true; + mmap_read_unlock(mm); goto handle_result; /* Whitelisted set of results where continuing OK */ case SCAN_PMD_NULL:
madvise_collapse() setting "mmap_locked = true" after calling collapse_pte_mapped_thp() looked good but was wrong. If the loop then moves on to the next extent, mmap_locked assures it that "vma" has been revalidated under mmap_lock, which was not the case: and led to UAFs, crashes in __fput() or task_work_run(), even collapse_file()'s VM_BUG_ON(start & (HPAGE_PMD_NR - 1)) - all detected by syzbot. (collapse_pte_mapped_thp() does validate the vma that it works on: but it's not passed in as an argument, collapse_pte_mapped_thp() finds the vma for mm and addr by itself - which may by this time have changed from the vma saved in madvise_collapse().) Reported-by: syzbot+fe7b1487405295d29268@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/000000000000f9de430600ae05db@google.com/ Reported-by: syzbot+173cc8cfdfbbef6dd755@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-mm/000000000000e4b0f0060123ca40@google.com/ Signed-off-by: Hugh Dickins <hughd@google.com> --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)