From patchwork Tue Apr 14 06:20:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11486837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 688FC6CA for ; Tue, 14 Apr 2020 06:21:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3443F2076A for ; Tue, 14 Apr 2020 06:21:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="wW8qZX3U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3443F2076A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 718898E0003; Tue, 14 Apr 2020 02:21:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6FA658E0001; Tue, 14 Apr 2020 02:21:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 605618E0003; Tue, 14 Apr 2020 02:21:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id 495EE8E0001 for ; Tue, 14 Apr 2020 02:21:55 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 13D2B584C for ; Tue, 14 Apr 2020 06:21:55 +0000 (UTC) X-FDA: 76705464990.11.wing41_2dc6f23125f1d X-Spam-Summary: 2,0,0,899d5b6d903f4b69,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:69:355:379:541:559:800:960:968:973:988:989:1260:1311:1314:1345:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2899:2901:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:4250:4321:4605:5007:6117:6119:6238:6261:6653:7264:7903:7904:8660:8784:9121:9163:10004:11026:11639:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12683:12740:12895:12986:13148:13161:13229:13230:13870:13894:14096:14110:14181:14394:14721:21080:21162:21324:21444:21451:21622:21740:21990:22017:22047:30003:30012:30029:30054:30056:30070,0,RBL:209.85.210.196:@bytedance.com:.lbl8.mailshell.net-62.14.0.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: wing41_2dc6f23125f1d X-Filterd-Recvd-Size: 5682 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 06:21:54 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id k15so5625792pfh.6 for ; Mon, 13 Apr 2020 23:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AhGsCcJsWxwEFFxEZHrkOLjEp/9h1BEi4GUJh65PtH4=; b=wW8qZX3Uelwn7XTniuKRvm+BQQg7fayx1Qw8h2CxqacAQ1p1I90+7Lp17FAjvDv9z1 qC341SseVZacRkPlv/Da5KdalPz3wP0Zj5KbZIKWCKJXiRrHHFEdh1VdGUssJ8iiI33g G/Dhf5Di1CQLga6HRgfBIEhO4SeGEMr1Yti8Gkm2auK+lMmEd3Wrg+tjq29Nslt4lZ9b jtzo9RF9qOOItIeoP1R0ook+cd29AqjnQur7QVVVTij5N8HqWAsNSiwyZYCg9At9tuHM A4PsPLgYBbiOoA+QEq0gt2VvRRQ2l0DR9PJPDejd2nf95pA2ULMHCHwTHcyx36MsONSU NjAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AhGsCcJsWxwEFFxEZHrkOLjEp/9h1BEi4GUJh65PtH4=; b=pGRL7l7qjhdq/DgAiOHn52cS6h2BqmBfu/O4SKozTZIJIaxnLxExrtVXXbcVPYGSn5 djW9ejwRyZ7MyoaPetwUNRCGUA95D4EQHOZQub/3rdcTOtgbTUfBukyAT0NBtke1mzkR Ya1DROpalDxtUWFwwxkGNr3PNPL60OukUOLUxb4x9JHbSsPYXFM2ZiuxncxPEbbIoy8/ Zh5kyCXoVGTE0mZZypxVnlDsjFX2hxz9xIoDwCXg0MXj9HWztRf/nHisUHiZBRtD1qi1 l9iRvNMYKneWnNJ/Ibhm8YoHfJUzQehM6oCBcrY9szG5SYDdxGqLIJgQgYCNuA7Tk2Uq V0fQ== X-Gm-Message-State: AGi0PuYNUKq2fyWeu3j/uw+btoEmUslpXU8lothXuZwPrDnwyCl9YdyT uOiQ96Tx4dyBCs+hXoa5SkRDuQ== X-Google-Smtp-Source: APiQypJ63b72LYvQX0syssjhVvQdWz8tO1l5fSoJ4sTfv7EI8r/gFKegCWq+/El+20plx32p4Nrzlg== X-Received: by 2002:a62:e803:: with SMTP id c3mr5962493pfi.228.1586845313150; Mon, 13 Apr 2020 23:21:53 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.69]) by smtp.gmail.com with ESMTPSA id w12sm3211103pfq.133.2020.04.13.23.21.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2020 23:21:52 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Xiongchun duan Subject: [PATCH] mm/ksm: Fix kernel NULL pointer dereference at 0000000000000040 Date: Tue, 14 Apr 2020 14:20:50 +0800 Message-Id: <20200414062050.66644-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 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: The find_mergeable_vma can return NULL. In this case, it leads to crash when we access vma->vm_mm(which's offset is 0x40) in write_protect_page. And this case did happen on our server. The following calltrace is captured in kernel 4.19 with ksm enabled. So add a vma check to fix it. -------------------------------------------------------------------------- BUG: unable to handle kernel NULL pointer dereference at 0000000000000040 PGD 0 P4D 0 Oops: 0000 [#1] SMP NOPTI CPU: 9 PID: 510 Comm: ksmd Kdump: loaded Tainted: G OE 4.19.36.bsk.9-amd64 #4.19.36.bsk.9 Hardware name: FOXCONN R-5111/GROOT, BIOS IC1B111F 08/17/2019 RIP: 0010:try_to_merge_one_page+0xc7/0x760 Code: 24 58 65 48 33 34 25 28 00 00 00 89 e8 0f 85 a3 06 00 00 48 83 c4 60 5b 5d 41 5c 41 5d 41 5e 41 5f c3 48 8b 46 08 a8 01 75 b8 <49> 8b 44 24 40 4c 8d 7c 24 20 b9 07 00 00 00 4c 89 e6 4c 89 ff 48 RSP: 0018:ffffadbdd9fffdb0 EFLAGS: 00010246 RAX: ffffda83ffd4be08 RBX: ffffda83ffd4be40 RCX: 0000002c6e800000 RDX: 0000000000000000 RSI: ffffda83ffd4be40 RDI: 0000000000000000 RBP: ffffa11939f02ec0 R08: 0000000094e1a447 R09: 00000000abe76577 R10: 0000000000000962 R11: 0000000000004e6a R12: 0000000000000000 R13: ffffda83b1e06380 R14: ffffa18f31f072c0 R15: ffffda83ffd4be40 FS: 0000000000000000(0000) GS:ffffa0da43b80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000040 CR3: 0000002c77c0a003 CR4: 00000000007626e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: ? follow_page_pte+0x36d/0x5e0 ksm_scan_thread+0x115e/0x1960 ? remove_wait_queue+0x60/0x60 kthread+0xf5/0x130 ? try_to_merge_with_ksm_page+0x90/0x90 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x1f/0x30 -------------------------------------------------------------------------- Signed-off-by: Muchun Song Signed-off-by: Xiongchun duan Reviewed-by: David Hildenbrand --- mm/ksm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index a558da9e71770..69b2f85e22d5b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2112,8 +2112,11 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) down_read(&mm->mmap_sem); vma = find_mergeable_vma(mm, rmap_item->address); - err = try_to_merge_one_page(vma, page, - ZERO_PAGE(rmap_item->address)); + if (vma) + err = try_to_merge_one_page(vma, page, + ZERO_PAGE(rmap_item->address)); + else + err = -EFAULT; up_read(&mm->mmap_sem); /* * In case of failure, the page was not really empty, so we