Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3695736imm; Mon, 18 Jun 2018 02:28:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL1iec8DQ8Ryx8na3eBK6YeBAOxSiCeepq8PRXY/wIvm6MymYnVcLsFUD0DZ+xwKdCYzdrQ X-Received: by 2002:a62:de03:: with SMTP id h3-v6mr12751207pfg.46.1529314115433; Mon, 18 Jun 2018 02:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529314115; cv=none; d=google.com; s=arc-20160816; b=GtPAYbGn+Hk6Nl/JckcNKdT9DmEiIClK6qVC6TnBaZsU5nJ+Fk2sYbzG9PNfSmZ2J/ MCuwFi5X/Taat0YSgHGq7YQq/i8Nolx6VR2VFwNJ+LN1xn1cFuzL9EyGct+sX+91Hdap KCrIRwHCPnypBS3KfzuFdW+eEOholMaibKg7BYngzAY/offsEcws67SfOtIpc0fJbsyB 84HXPOWkZrEg5kpJ02dGdBjVow/PM7jqT9dX3KiWkTS7NNp19RvB850U+bm343vSyLs0 4rP3mHcgh94zs1Xsem+oOMtn4hAt4jvf02QCpMlldDZaEToZRw6ru3Ww0nGHCFNFJzz6 9fCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hw7CrBpyj1kWoJD2Mwh/wCjEVCDRYuKLKpY1er/AyZI=; b=Cf770DMCXl1Q/JxWc8dT525d+Ilkt8Hx6FI9x8fhfdSK2yLRs46H/LOGIh2ayQpjO/ Jlphpdewb5oUH0KeVvmcDO9lWSkforpWPgJYcY962h99ri8AjlPfMUcqyxzTJzlkz1wM DYK9FUV2OuQrbUzXCZWQTjzIy6uEPdduO7Vp2OXCL26a3T3JN4hcRJSYItpfhYe4gh2f dtU16S+ev2kz9kLg915SVVuN5QCsg3jZB8fckd9DOY8E+gfobM+rf86LTDHriIJRrkCH 4Kk+xSpbETROUQomcKacg4W8ONx3q54lN3LMbcxEBvsQnhdLUf8NZZncO9YS8Cjv9ctY 9G7Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25-v6si11983199pgc.605.2018.06.18.02.28.21; Mon, 18 Jun 2018 02:28:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966006AbeFRI0D (ORCPT + 99 others); Mon, 18 Jun 2018 04:26:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57104 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965887AbeFRI0B (ORCPT ); Mon, 18 Jun 2018 04:26:01 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 25B7BC5C; Mon, 18 Jun 2018 08:26:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laura Abbott , Dave Anderson , Kees Cook , Ard Biesheuvel , Ingo Molnar , Andi Kleen , Andrew Morton , Linus Torvalds , Sasha Levin , Alexey Dobriyan Subject: [PATCH 4.16 229/279] proc/kcore: dont bounds check against address 0 Date: Mon, 18 Jun 2018 10:13:34 +0200 Message-Id: <20180618080618.296533742@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Laura Abbott [ Upstream commit 3955333df9a50e8783d115613a397ae55d905080 ] The existing kcore code checks for bad addresses against __va(0) with the assumption that this is the lowest address on the system. This may not hold true on some systems (e.g. arm64) and produce overflows and crashes. Switch to using other functions to validate the address range. It's currently only seen on arm64 and it's not clear if anyone wants to use that particular combination on a stable release. So this is not urgent for stable. Link: http://lkml.kernel.org/r/20180501201143.15121-1-labbott@redhat.com Signed-off-by: Laura Abbott Tested-by: Dave Anderson Cc: Kees Cook Cc: Ard Biesheuvel Cc: Ingo Molnar Cc: Andi Kleen Cc: Alexey Dobriyan a Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/proc/kcore.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -209,25 +209,34 @@ kclist_add_private(unsigned long pfn, un { struct list_head *head = (struct list_head *)arg; struct kcore_list *ent; + struct page *p; + + if (!pfn_valid(pfn)) + return 1; + + p = pfn_to_page(pfn); + if (!memmap_valid_within(pfn, p, page_zone(p))) + return 1; ent = kmalloc(sizeof(*ent), GFP_KERNEL); if (!ent) return -ENOMEM; - ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT)); + ent->addr = (unsigned long)page_to_virt(p); ent->size = nr_pages << PAGE_SHIFT; - /* Sanity check: Can happen in 32bit arch...maybe */ - if (ent->addr < (unsigned long) __va(0)) + if (!virt_addr_valid(ent->addr)) goto free_out; /* cut not-mapped area. ....from ppc-32 code. */ if (ULONG_MAX - ent->addr < ent->size) ent->size = ULONG_MAX - ent->addr; - /* cut when vmalloc() area is higher than direct-map area */ - if (VMALLOC_START > (unsigned long)__va(0)) { - if (ent->addr > VMALLOC_START) - goto free_out; + /* + * We've already checked virt_addr_valid so we know this address + * is a valid pointer, therefore we can check against it to determine + * if we need to trim + */ + if (VMALLOC_START > ent->addr) { if (VMALLOC_START - ent->addr < ent->size) ent->size = VMALLOC_START - ent->addr; }