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: 166019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp388740vqn; Fri, 17 Nov 2023 00:49:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmLVXqDSVQ8KrKuDKugspQvqjtiXqiAHTuSWSpTW64AM8PW07nZbUrR9v7+fov6hudDTc+ X-Received: by 2002:a17:90b:3904:b0:274:8949:d834 with SMTP id ob4-20020a17090b390400b002748949d834mr12611641pjb.49.1700210997533; Fri, 17 Nov 2023 00:49:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700210997; cv=none; d=google.com; s=arc-20160816; b=d0I2CW5IgQyqUff/C/MYPyI4PzDhs9TXwGXvvGy6ERsogHgH4oTb/q0vTub5EEstw9 NCOlKOtJ5S0a4zjeevQJOTHmcXxU+x/qiNAaZ8kr7Y5sBLQmihNPPUKJ+OIqYKJ41o/X VfFwnLiDUihP2gJl0ImWwPbNAw+7+zdKdfjILp4njpZtV90VcvoDOC7+5FDCFXCHNHQ4 aWM2hNIhlHY/+h4ucKP8Rv313/dYm0AQpYFvuFYwF0jwsUEK7O9YzCH5EDfM33XmVLJd 56HMhaLVbThxfQPth0kHC+wMc74SYIsuA3h0hWVhuUQXLbozVwQx7iPWDR11tX6dH28K jkLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=Rbv+r+ppwEUPn8ow9+hXf/8JayiuTVDgUStT51BtKzU=; fh=XHiL7zpnRGdQsliIuRbdej+es9UL68qCBU6TgkDomws=; b=00OTiMFEXATmIHa8LtZ7GmM7ajHvVA1nApQ02vMFr/ta0O1vo3jfKxHtHaJUhlHdY1 jlxnyz65JepQ9LdhM6TqOkzypTUA1mzobLrj/RPosUyrq4Sa0YEJV/iyPJAWE7J99v0h r9exerk6Vj+a6azVTc+WlF2Ekln0cE09xs2yS5SF1m4iuuLV8f+irQqbwUYjKV3SHxMF 6HT+R8yjxRxoGC9rwIp2yHmnk7agpnsyg2aHyTsiy52rDem/cWoDeXtXP2vS4hMjaiIG QlO2BTj2CLsVM58O6+5HSqZb8Kd7g/5KaObLIRK0+wr9QDkrzYawIJ6k+JEnWtZmCpRl 2psg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DjqnuM7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id f14-20020a170902ce8e00b001ce5b9c6181si1407954plg.549.2023.11.17.00.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 00:49:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DjqnuM7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 23B09826FAE8; Fri, 17 Nov 2023 00:49:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345708AbjKQIth (ORCPT + 30 others); Fri, 17 Nov 2023 03:49:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345738AbjKQItf (ORCPT ); Fri, 17 Nov 2023 03:49:35 -0500 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89769D5E for ; Fri, 17 Nov 2023 00:49:30 -0800 (PST) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5844bc378feso860394eaf.0 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=vger.kernel.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=DjqnuM7wzaKU4qq/EF17jReQbbqhfmsY1s7m3+fBngTvVjCo2jj/7sMRJsPHvsN1+1 q+P1AZIYF1qMfanCF75/QWmcS2sdA9DCrGaqD04yEAn5W1kkF8ZX94tKZkSHzu+CMm/D 7Sys/F/lGykDFJfJjDCPP66+/nEsL15dnoLBRr8R3+llDJUoQPQJZ28FUMfdNJIF2VE1 hOvQaQ6QW2Z6mmOcQgfySCkYA5BZGyRbr6+WhXO3XIQNU1bfps8W/KiH2vrDOffblDkR AbAB0nru+H50F9gtG84Y8kE8uTKH72BLQ71iCSgVuh5en2SivxOGDhFWroOURO2RhnCH 3UGw== 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=uVeEbhuxnMlYpj7KtwUY2BoqYx431Ijhz0exEyv7vDLl/B7JO3JVjjHxCM5qf453VH o5MyBbn8rpBdjq4eded9CwpxwJagaed105xI02wSVFhmcrp9flbDF/3XYjbDiJFQmfTi XZ1bCEQ1Y3YeUay02EsWyLKve8b5EZ5Q3qKqwEJqwqmZoX+g3QTli81PhSyuVFgvTQZh Arp+/uKuyhup5t49zgW1Ch+iobnttLFxER19lcOWUEf7T9vfePeaftA6ktyAe4NzQwJ2 IFu4nC5zwiEHLOF39ZyNcyLBr20gYlOzd1xFxIOIpuooX+fT0fje+naLWG0Ri1jDqyOt PQxw== X-Gm-Message-State: AOJu0YwAAKjfvAoBRZXTGEU2daiXnQy02uAElTfjfI3ECULDEg0ZrXGc wGLDreJcnjFx4KmX9dzVV1886A== 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-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 17 Nov 2023 00:49:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782800447137561840 X-GMAIL-MSGID: 1782800447137561840 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;