From patchwork Fri Nov 17 08:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13458516 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 7BECAC072A2 for ; Fri, 17 Nov 2023 08:49:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1D4E6B04C8; Fri, 17 Nov 2023 03:49:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCCD46B04CA; Fri, 17 Nov 2023 03:49:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B943A6B04CB; Fri, 17 Nov 2023 03:49:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A846C6B04C8 for ; Fri, 17 Nov 2023 03:49:32 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 717341A06CD for ; Fri, 17 Nov 2023 08:49:32 +0000 (UTC) X-FDA: 81466822584.14.EE5246B Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf18.hostedemail.com (Postfix) with ESMTP id C0B041C0018 for ; Fri, 17 Nov 2023 08:49:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=CN95QVDb; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700210970; 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: references:dkim-signature; bh=Rbv+r+ppwEUPn8ow9+hXf/8JayiuTVDgUStT51BtKzU=; b=UNVBuInl6ckR82mH/q/urcBH2uP6r1TDCLThtcbgTijZDf1cp3I0utqYgOIXazBIoTDx2z +9Ti2+jyMW7gXpA7/Hd9CjZ8lrX6TFxhxLX+sjpA+Z9ajcG3Dx4utg4mYyCFND7ktx83+s bGabqSSzqr1vutf99MeovWa0CvMFljs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700210970; a=rsa-sha256; cv=none; b=u9Y/Ue/QcgucYjdjMW2zYhgXKd1MJwp3QAFrzhz2WSiyV0k5mmu+WJlv37OkVpyTUSYdpB bws5xNztdxDKWe43flr6zjcIwH4Hx504w2/mXChpYxqr2MNmQpK9eNZH+Qog3MtqrAO7G2 AaycQ0dT98Bv+4PH1FE9ru53mm0WdDw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=CN95QVDb; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-58a42c3cbb8so845926eaf.3 for ; Fri, 17 Nov 2023 00:49:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700210970; x=1700815770; darn=kvack.org; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=Rbv+r+ppwEUPn8ow9+hXf/8JayiuTVDgUStT51BtKzU=; b=CN95QVDb8kPLGE0w2W/6ij6aYzbjuC702Npjd9KxU8tSrJem2ucFsZMqMbRDrHZZXA OBCslgeug6fXXEe7p9BkdFuK5EgssfOsQeIapYKYMlI7ZBr1JYpzu+AkZSCabRL19JFK 6tRPRZPhsw5rjAI/MhfjJ38drORm9JN3tMqS2ZDUflNkza67TFoszWcybIOzemvENKbz FoRGXveAwX5/6QsbIffpu3yp9/UNJPw/BorBvL6bEGDw81OGvaDEGhNyPlcVZKYeV8c0 +DHADfUcjWtyvM65ymzrg93qteYPeEvSNYcfiPkizhvGzY+ZdFjXPqzfJ0ZbZIuVvMEw GLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700210970; x=1700815770; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Rbv+r+ppwEUPn8ow9+hXf/8JayiuTVDgUStT51BtKzU=; b=JYFpP4iLqcKtVr9GHBKYtegogOAz6yT8ELhzyfKdkmEcApBeFEbRL28Vki0vQsIMc/ ibk5N2at9mejkFibQNPP88VCtyTpib/Ye/JbkDlfPHKMGMQuDuM7c3ZF+CjInPLHrcOq 10zqADPOtqv1+GH0suDPgMUjpXc+rzxM7LJeoqr2PKxi28hmrj9rbxkMjEe6AUcCGYIh v3WPTK66xxwklfPWZFTnqJzYHY6TvJ+h0wnpuUXvnWmR7+hduIr1WWys7ITGCseqqxlc YcbRBgdjZslijfPNh1b39YrJXvB5ag8fk6WBOoc0MhY5WCw53uVFKVJZxH1mHa5+WeMP e26g== X-Gm-Message-State: AOJu0Yyag93b2HY9bWFW39AO5ZWfuC/wYHIsYvbLvZqx9NQf5HX+Edcz yKd7hXjYu6Hcqrv9vNEi/iN9Tg== X-Google-Smtp-Source: AGHT+IHbLLanJXF1s064IWXZYvm0+1EUT3rkvAWo2dTcspQO2Su78NjgMtsNLGqxMrA/EwETi6VzuA== X-Received: by 2002:a4a:9205:0:b0:589:df75:2d83 with SMTP id f5-20020a4a9205000000b00589df752d83mr16733953ooh.1.1700210969734; Fri, 17 Nov 2023 00:49:29 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id v4-20020a4a5a04000000b00587947707aasm239258ooa.4.2023.11.17.00.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 00:49:28 -0800 (PST) Date: Fri, 17 Nov 2023 00:49:18 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: syzbot , "Kirill A. Shutemov" , Matthew Wilcox , Jann Horn , =?iso-8859-15?q?Jos=E9_Pekkarinen?= , linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com Subject: [PATCH] mm: fix oops when filemap_map_pmd() without prealloc_pte Message-ID: <6ed0c50c-78ef-0719-b3c5-60c0c010431c@google.com> MIME-Version: 1.0 X-Stat-Signature: 1ibyh3odrabfzhe33jb3q99z1rdqhnhu X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C0B041C0018 X-Rspam-User: X-HE-Tag: 1700210970-225546 X-HE-Meta: U2FsdGVkX1/071M6LjyVjfc4Q7yEDKeAumhXu8ABS/XRpHM2KZohNqTL9GBpDM33buDadnjL9uEssTCY7/Imh+JNyRyWkh3DCrcALqUAkiNZGBYudAauiGueW0mP3FSBjEm2ExQx8bCbFFzfftGEHK23AARn7OMkAbUnULYxYrJMK4DZ3BYGmJK/aU6oEsCR8mSfiHHOsraZJGjDas+qwB19+tOrRb2TECN/8KgRykm2Vu8n7gEJKw49qXbhYE5JcFs7WZoACqE7cyPAKMENHGIhAyA9AvrnpVb2UHDXHCYOAU+e3vCKr0m/7bl/g775BruQ2dQKNrlpLXySIARJ6mXTkqMEE95UZgRXQTSf2yFVhZU1WvZCLH+knSprs9Cjt/wpmOzbAtvvizg7g3+7sZNGMc01jcGNOA61VgwqVZg+s3SsoNiAgrFnPWwn1LIHO2gQ5OuB0ndvJGmdOOFBzKRBrmT36sJEfx12GLbID1fX78ZUcNBDeB5p0zA4uOFG5XJ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owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: syzbot reports oops in lockdep's __lock_acquire(), called from __pte_offset_map_lock() called from filemap_map_pages(); or when I run the repro, the oops comes in pmd_install(), called from filemap_map_pmd() called from filemap_map_pages(), just before the __pte_offset_map_lock(). The problem is that filemap_map_pmd() has been assuming that when it finds pmd_none(), a page table has already been prepared in prealloc_pte; and indeed do_fault_around() has been careful to preallocate one there, when it finds pmd_none(): but what if *pmd became none in between? My 6.6 mods in mm/khugepaged.c, avoiding mmap_lock for write, have made it easy for *pmd to be cleared while servicing a page fault; but even before those, a huge *pmd might be zapped while a fault is serviced. The difference in symptomatic stack traces comes from the "memory model" in use: pmd_install() uses pmd_populate() uses page_to_pfn(): in some models that is strict, and will oops on the NULL prealloc_pte; in other models, it will construct a bogus value to be populated into *pmd, then __pte_offset_map_lock() oops when trying to access split ptlock pointer (or some other symptom in normal case of ptlock embedded not pointer). Reported-and-tested-by: syzbot+89edd67979b52675ddec@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-mm/0000000000005e44550608a0806c@google.com/ Link: https://lore.kernel.org/linux-mm/20231115065506.19780-1-jose.pekkarinen@foxhound.fi/ Fixes: f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") Signed-off-by: Hugh Dickins Cc: [5.12+] Reviewed-by: David Hildenbrand --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index 9710f43a89ac..3d4dae9d1070 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3371,7 +3371,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct folio *folio, } } - if (pmd_none(*vmf->pmd)) + if (pmd_none(*vmf->pmd) && vmf->prealloc_pte) pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); return false;