From patchwork Mon Aug 19 05:50:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 11100315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D401513A0 for ; Mon, 19 Aug 2019 05:50:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD0A62858B for ; Mon, 19 Aug 2019 05:50:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B09CF285A6; Mon, 19 Aug 2019 05:50:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 778BB2858B for ; Mon, 19 Aug 2019 05:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E0F66B0008; Mon, 19 Aug 2019 01:50:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 490BC6B000A; Mon, 19 Aug 2019 01:50:21 -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 3A74F6B000C; Mon, 19 Aug 2019 01:50:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 182F66B0008 for ; Mon, 19 Aug 2019 01:50:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id BC357180AD801 for ; Mon, 19 Aug 2019 05:50:20 +0000 (UTC) X-FDA: 75838102200.15.brake78_775fee32bdb23 X-HE-Tag: brake78_775fee32bdb23 X-Filterd-Recvd-Size: 4627 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Mon, 19 Aug 2019 05:50:20 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id h3so423393pls.7 for ; Sun, 18 Aug 2019 22:50:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ZGbhnh/rQl26tl12zgYbAbZJa4C3RLtP+c9zSecEuwg=; b=OJC7NEqqIFckSHtMwvJvzoMvzR1HzZv8asknNEhBekF5AyaeMVFhfTN5aVT28rzsLS SfWI0BffYJI3D/kMC1pBkGlwWlRfL8chg19bQSe2fdIRvcnuL8oblwa+ItTYZSksVt/y 5yWTqRQu/fTmS3+G53PKfp+iG1Fc4EwjTbufaHqn84uroAGS/9sJl2HRSywYrrsZr+E9 lx1bQP2osZzYqlFocT9ZjaHQbYJkDywqhJAGGi8ErKQXIVuBBhX6MSoMXLkwvpS9LX6P Fe3MKHRz7aTiAlntaJTZ7hRiNaSZhM7ro++swZFdzpAhXe5vgHTa+/XsXGmIrvV3SP2I SSvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ZGbhnh/rQl26tl12zgYbAbZJa4C3RLtP+c9zSecEuwg=; b=j9FiDmJA1TAZZDZIhHKgjm4IRw2oibLpA/LuSLd5ocvrIUmz6mLOg+QXpK2jQ2kWdw Iloq3rcdFosgrOLG2tyUYyWeWXKcv9N9sBhB5sGPgHUXJZmrFj5XgKztlLQg9sZTGiUY ZuTPJ+DO4lGYTjBNbLaySTu7XUBINu32dFbU039d/XENmq48h70vpyUxkb7cKAfaNTrA AelAEZy8JbZosicHhR8IyrrLymKLwNz5m4HZe88wUV/0zrVLcsZwxCr+UuCtpONzvS+y WccO52NzP37G9bBUL2FdUyN6ZMbzvePdcB/ME2xaQgHlwp0vigM6l90TGdjVHkK/Asci LL1A== X-Gm-Message-State: APjAAAXIo4ifvZRv3a2hq939Ee23iMdIIcbwio7Q0MQLDN1QGETZFh7k Ry2MODk+8mozTobhHGLGhhI= X-Google-Smtp-Source: APXvYqxSH/FK0cAT9ydQelCiF5nBAb0CLUwft1MT1K73dTBqypzuhAaaaMpUmvakCpx0tNtvy1W0HA== X-Received: by 2002:a17:902:690b:: with SMTP id j11mr21430996plk.35.1566193819287; Sun, 18 Aug 2019 22:50:19 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id v14sm14165972pfm.164.2019.08.18.22.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 22:50:18 -0700 (PDT) From: Zhaoyang Huang To: Andrew Morton , Zhaoyang Huang , Russell King , Mike Rapoport , Rob Herring , Florian Fainelli , Geert Uytterhoeven , Doug Berger , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] arch : arm : add a criteria for pfn_valid Date: Mon, 19 Aug 2019 13:50:08 +0800 Message-Id: <1566193808-9153-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1566179120-5910-1-git-send-email-huangzhaoyang@gmail.com> References: <1566179120-5910-1-git-send-email-huangzhaoyang@gmail.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Zhaoyang Huang pfn_valid can be wrong when parsing a invalid pfn whose phys address exceeds BITS_PER_LONG as the MSB will be trimed when shifted. The issue originally arise from bellowing call stack, which corresponding to an access of the /proc/kpageflags from userspace with a invalid pfn parameter and leads to kernel panic. [46886.723249] c7 [] (stable_page_flags) from [] [46886.723264] c7 [] (kpageflags_read) from [] [46886.723280] c7 [] (proc_reg_read) from [] [46886.723290] c7 [] (__vfs_read) from [] [46886.723301] c7 [] (vfs_read) from [] [46886.723315] c7 [] (SyS_pread64) from [] (ret_fast_syscall+0x0/0x28) Signed-off-by: Zhaoyang Huang --- v2: use __pfn_to_phys/__phys_to_pfn instead of max_pfn as the criteria v3: update commit message to describe the defection's context --- arch/arm/mm/init.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index c2daabb..cc769fa 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -177,6 +177,11 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max_low, #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { + phys_addr_t addr = __pfn_to_phys(pfn); + + if (__phys_to_pfn(addr) != pfn) + return 0; + return memblock_is_map_memory(__pfn_to_phys(pfn)); } EXPORT_SYMBOL(pfn_valid);