Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp999875ybp; Wed, 9 Oct 2019 07:28:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpu5KbLFZmjdv7H91XEmDSIDyzJLTy5KYP/3faK5x2bAcpGDdFzaR2o/jLiL/uGyV1CSRA X-Received: by 2002:a17:906:fca8:: with SMTP id qw8mr3214287ejb.188.1570631302956; Wed, 09 Oct 2019 07:28:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570631302; cv=none; d=google.com; s=arc-20160816; b=CDZUc4/3o81O90f2u+NlwxvX8MOdT7PopD3L3UHquE3MrnBL97vXQr3aROPwaIh9Z/ YZuouDb8+CiQlc81Syo185uHOJC+0ZheZMYDBBQZlbPbh7CKP+x3qrLPNO3P6S9icV3d KjOBwTir2dVA8lT5zPJF7XyiGAyOOo7RJbqSjc3o0JTDoFqA9RrK/dWkPM1ptIrJISI4 2vswX9jMhhncKL48e33FtIOArRGh07ZVCFaC8ttTP9WRn6detUrK8ZNMAMEpMVIPMAt/ pVzIov1+Z0g6lhzAPw4Er/MuIts+blNTsS9+tXaGDAd7zWvd/M4DUxsaGEwgru/9QHUJ hlXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kuZFCkSHZu70W4AtEy6o3zxM8ZT87Txzl3XTsfg+T9g=; b=yPGbVUwc2e+Cpu4xZrUsdpXw74iRll1hxbOuL7d1TaXgFr4B1AioxPoE3Qx7W/53ha WFLDp3WRB/KifQAC3J3DaGtUnxT7JLPRWKL1db6dj6SQl3EoK2bd85K0RR1vWCtalZ2c +4L3PQKyde4+W3be3JSozok2yHWfHxvUTCtksEwlQhcyMAT5FKm8beWWdqy8zmpfK0n4 lF5eIaTpkNe8yd9boUwxnKqcu5B3vPCAWV1pdXAtLc3eFYYHpan5biTisoUdV7J5UvPl SjRtTIvCfJV94n3L7PjKUwwCAXbORx+AY+f2nSZx1pc5ScE3YyX++5lmWmk4JI8B46NB jMjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ec21si1193431ejb.26.2019.10.09.07.27.58; Wed, 09 Oct 2019 07:28:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731471AbfJIOYv (ORCPT + 99 others); Wed, 9 Oct 2019 10:24:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50720 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731464AbfJIOYs (ORCPT ); Wed, 9 Oct 2019 10:24:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33609A44AFA; Wed, 9 Oct 2019 14:24:48 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBF0D60BF4; Wed, 9 Oct 2019 14:24:46 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Naoya Horiguchi , Andrew Morton , Michal Hocko Subject: [PATCH v2 2/2] mm/memory-failure.c: Don't access uninitialized memmaps in memory_failure() Date: Wed, 9 Oct 2019 16:24:35 +0200 Message-Id: <20191009142435.3975-3-david@redhat.com> In-Reply-To: <20191009142435.3975-1-david@redhat.com> References: <20191009142435.3975-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Wed, 09 Oct 2019 14:24:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We should check for pfn_to_online_page() to not access uninitialized memmaps. Reshuffle the code so we don't have to duplicate the error message. Cc: Naoya Horiguchi Cc: Andrew Morton Cc: Michal Hocko Signed-off-by: David Hildenbrand --- mm/memory-failure.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 7ef849da8278..e866e6e5660b 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1253,17 +1253,19 @@ int memory_failure(unsigned long pfn, int flags) if (!sysctl_memory_failure_recovery) panic("Memory failure on page %lx", pfn); - if (!pfn_valid(pfn)) { + p = pfn_to_online_page(pfn); + if (!p) { + if (pfn_valid(pfn)) { + pgmap = get_dev_pagemap(pfn, NULL); + if (pgmap) + return memory_failure_dev_pagemap(pfn, flags, + pgmap); + } pr_err("Memory failure: %#lx: memory outside kernel control\n", pfn); return -ENXIO; } - pgmap = get_dev_pagemap(pfn, NULL); - if (pgmap) - return memory_failure_dev_pagemap(pfn, flags, pgmap); - - p = pfn_to_page(pfn); if (PageHuge(p)) return memory_failure_hugetlb(pfn, flags); if (TestSetPageHWPoison(p)) { -- 2.21.0