Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp459480imn; Mon, 25 Jul 2022 23:39:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1toScH9q1TfI2ZqRbyXC/ptPKMJDmPLryu2/5za31AIvRsmpSkTbS5LOutMTDyuZ4KYU+p8 X-Received: by 2002:a17:907:60cf:b0:72f:267e:eb8e with SMTP id hv15-20020a17090760cf00b0072f267eeb8emr13163816ejc.544.1658817573080; Mon, 25 Jul 2022 23:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658817573; cv=none; d=google.com; s=arc-20160816; b=lWw+tnneMXYXBQH2h4sykFxGu/vn3Jh34Sf11MQmEWmY3R/kAZ+REGL9rF1c5vbMUI evteOAq500wiwZve3Uy9gTknS76sLXsaR4eRZ2cyhDJIpgqnSW4/GXgmZakWtrsa0P6/ K2jltGLYpGZU4yNTKdTEN/Ol0w4Rg1AIVCpvWmFWaB8XZVb2VtXjLQwzI7w73mSUWyAN 60G88WioOt/75JNm2Lyw4XADb6xLKV3n9Deu0K93RBUvbSp41nuEBU+vOQ37Jdx3/GYc byN18NHeX6Tj6gsd7hDlNAy0UKiRZ5vL04iLYKWvMiSVx1v82mJw0CVefYvyVuJJpSbg p3Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AdOoxODJiumCfXGJPDqlgTRMx1Hwty97pt6JnuBcVOQ=; b=gWxl/TVnAEBH4rW0G38C711Xvb+2VrinXppocSsFaJLWEa2eXoKuwKyn2/VCn/iGFO Zl8+TTjcu7HlIa0pbyDxEaZEl1EzRdrTsaM1UnqMcevgeKs+I+hJVWROdthNE/h1pmmq 9i4qHHsToS57xWIXZGRGTCZEtWoOBGKKWiXHMPwW47HxXT9sDgjHyQHQ9nuE6PMWuHn8 13/alM2LWj0mQ8DEflfrHjQdy9Wx6+pZF59faHJ/GudOjZ3nvI+sXqBQgsqDiFVWhA1t K/PHCb8m+6c9sdKK0FzICA94EpVUOgz3HStgV88nalQt8OOwlFTqRQQSujEEGNdOEBSt kC1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ie3eJ3v2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020a056402190f00b0043bb87a322csi18550212edz.52.2022.07.25.23.39.08; Mon, 25 Jul 2022 23:39:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ie3eJ3v2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237955AbiGZG1s (ORCPT + 99 others); Tue, 26 Jul 2022 02:27:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237946AbiGZG1b (ORCPT ); Tue, 26 Jul 2022 02:27:31 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E9F027B0A for ; Mon, 25 Jul 2022 23:25:33 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id q22so7184747pgt.9 for ; Mon, 25 Jul 2022 23:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AdOoxODJiumCfXGJPDqlgTRMx1Hwty97pt6JnuBcVOQ=; b=ie3eJ3v2MPmIgwvF18zCl0L7By+ZEHT6fvXB5MfvLLOglu2VNhWaFg0Aqpj4oWyFj/ of1Gi+hZUS/Vcz+B0hP6r8GYy5SVUp4JrJ0MxBXtBzTArlpIZCa9xkZ5jxuW97oFB3fr +RtPx5Oj2VyJT2fkx+KuSfmvZb8vBN2+ONNsazQcrLHqXnptWUSZe/Lc9LVzoUOt9qes 7wGiFnR0kuFDs5/fh25ZMN4wcE2DH3bwvifDn+sDUUnEvvpjFSk/MjVOaWHh0bdVtJny Z/czCq1xNx12UrAiJT1VP+uTjBZPt3D5o7F70keje9f+ldWFWS0qkXy1iw2IjqGBYANo KMYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AdOoxODJiumCfXGJPDqlgTRMx1Hwty97pt6JnuBcVOQ=; b=oBtSmuA8QLNHUNnwjcSBSCsTL9uiXtLINjHiZnkxLwDeZINHE+Yy6pv9B3Hr/ar5pg kJ9TlpsDDJlajYLWEXtVYokIdu+0GglTY8iionxKvwW556qLofXRWlBoqUEUrdM0HuJg xlV3GKAk1LAkiZtoH0r9aLkvyhLkl9MWEGQtoJaSQ7J7aa+ep6m2TRvDFSXtWFev201X jWLJo63doeKEiMxns7K8NQE4i4lFvY8SYFMk9ossdSIxkOUbdF7otkrRfxMcwRy8Rcvi 8e/D0jjmZWC6jZVq0aoTgpZoxZsOxVIK+96P7AT0dp/v6ntvzU+s99DkobwiVHYC1ioy 0IQQ== X-Gm-Message-State: AJIora+7h6TnkgVx6gv/rbdh7iO6GR5ulFo07QquB3hoKpU+t9Zg3cFo A0tXp/2wY3QpLby7+T6oy0OLCA== X-Received: by 2002:a63:ce13:0:b0:40d:d291:7710 with SMTP id y19-20020a63ce13000000b0040dd2917710mr13573244pgf.269.1658816732987; Mon, 25 Jul 2022 23:25:32 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.241]) by smtp.gmail.com with ESMTPSA id d11-20020a63d64b000000b00416212f8da7sm9423951pgj.44.2022.07.25.23.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 23:25:32 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH] mm: fix NULL pointer dereference in wp_page_reuse() Date: Tue, 26 Jul 2022 14:24:36 +0800 Message-Id: <20220726062436.90290-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The vmf->page can be NULL when the wp_page_reuse() is invoked by wp_pfn_shared(), it will cause the following panic: [ 12.981200] BUG: kernel NULL pointer dereference, address: 000000000000008 [ 12.981954] #PF: supervisor read access in kernel mode [ 12.982615] #PF: error_code(0x0000) - not-present page [ 12.983146] PGD 0 P4D 0 [ 12.983417] Oops: 0000 [#1] PREEMPT SMP PTI [ 12.983846] CPU: 18 PID: 923 Comm: Xorg Not tainted 5.19.0-rc8.bm.1-amd64 #263 [ 12.984606] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g14 [ 12.985760] RIP: 0010:_compound_head+0x0/0x40 [...] [ 12.995932] Call Trace: [ 12.996199] [ 12.996424] wp_page_reuse+0x1c/0xa0 [ 12.996800] do_wp_page+0x1a5/0x3f0 [ 12.997169] __handle_mm_fault+0x8cf/0xd20 [ 12.997587] ? _raw_spin_unlock_irqrestore+0x23/0x35 [ 12.998105] handle_mm_fault+0xd5/0x2a0 [ 12.998499] do_user_addr_fault+0x1d0/0x680 [ 12.998930] exc_page_fault+0x78/0x170 [ 12.999321] asm_exc_page_fault+0x22/0x30 To fix it, this patch performs a NULL pointer check before dereferencing the vmf->page. Fixes: 6c287605fd56 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Qi Zheng --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 4cf7d4b6c950..9174918ce3f7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3043,7 +3043,7 @@ static inline void wp_page_reuse(struct vm_fault *vmf) pte_t entry; VM_BUG_ON(!(vmf->flags & FAULT_FLAG_WRITE)); - VM_BUG_ON(PageAnon(page) && !PageAnonExclusive(page)); + VM_BUG_ON(page && PageAnon(page) && !PageAnonExclusive(page)); /* * Clear the pages cpupid information as the existing -- 2.20.1