Received: by 10.192.165.148 with SMTP id m20csp2619227imm; Thu, 26 Apr 2018 14:17:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+yZdVQ/yO2Y6onFnIu/xq1Dn5ZjGT/55JDNcjKi/D1TrelcIv7dukk3EMSYLnrm697krx X-Received: by 2002:a17:902:6c0b:: with SMTP id q11-v6mr24355084plk.135.1524777462157; Thu, 26 Apr 2018 14:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524777462; cv=none; d=google.com; s=arc-20160816; b=BdzZH0GBH+9XNvBz7t9JtlzRQOzQ2vzWdrrrDWoQSXPkhM4/ZAPdx31J/DVTDIsWaJ Eb8zP3tA23kid3p+JWaM6kFtAJeSvtd6zNfdWXFI72dmBPwyon3naO3FRXKliwStG9BJ mszuGYiO+kWCMYEYqaJCe28SaHkCGUJJ9VYBLVhzeK6VuKmf7vRC5+ymdoF1O8STsHNt hF3nXCE81YDempjPluaYZaupsZIDdvwCH70gxy2KWU4ZodR8oquE1bTuuipB4GPWD0aw tywf4gVZDekyIf2+lwYkTbgCjV3oTSPnZKXJsSmFeX9rvxd1F+lLnq8gbZm7H/Ejxo0Z Jgpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=WhFz7zYZll0u2m+3k3Z9AYZ2Q5LsGrduz4BC96Gaqdg=; b=mYWy9ylboUkhxAc9ylK/uKmKL+7o06FbDqqQvTAQ8mu7SPGTmRJr9IFPPDllPI+5pm 6w7u4n1pWCccs7qTKaUT4DfU/iSUBMbMGmp8bQB+n0SgAOP5AO/nNZ5HCFqZdfCjyyxa vIuRE8pSQTgDRg5W2Ww+uLnWe00F6e1tomwWZcx2gGQiHKCEBtohiRQ2Eu4Z1M3YzNqB nQo8zVRsWs9Zeusl+RQRbYqBJXAYHLIofwcmodBF8rqNCeLii4Sp47+xWZU6AxmJt8pI Ooin1Lm5Ve70eFMixX1LWu5tNx5zRyOBob+VEb1JxbBv31+n38cBkVf8Hcpjlbha9kN7 FPOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=LRmEg5DX; dkim=fail header.i=@chromium.org header.s=google header.b=JG6QhVjQ; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6-v6si18686591plo.551.2018.04.26.14.17.27; Thu, 26 Apr 2018 14:17:42 -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; dkim=fail header.i=@google.com header.s=20161025 header.b=LRmEg5DX; dkim=fail header.i=@chromium.org header.s=google header.b=JG6QhVjQ; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756261AbeDZVQO (ORCPT + 99 others); Thu, 26 Apr 2018 17:16:14 -0400 Received: from mail-vk0-f45.google.com ([209.85.213.45]:36317 "EHLO mail-vk0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752358AbeDZVQM (ORCPT ); Thu, 26 Apr 2018 17:16:12 -0400 Received: by mail-vk0-f45.google.com with SMTP id k67so1729896vkd.3 for ; Thu, 26 Apr 2018 14:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=WhFz7zYZll0u2m+3k3Z9AYZ2Q5LsGrduz4BC96Gaqdg=; b=LRmEg5DXMDn6moMCf0kjn74X2lWuRk7d+FyH1BQhwRdnuJJ93Zh8DpkEPo4bxjRra9 scQ7Ws/qDKxEDAlC9AGjtXj3bT3x7P1+6Gs3o1gQdSR7EgDyhOea3DMtVZT2IreSc6it Z5znxK/MQaTTE+a7zENoPTRriLiU7r8H3am/N665E19A8W13ZlTwdaobtYm2izkrqjNA j7vQOcZCcfQKult8zJnJyzIWGS4ayPUh3PTXTYmjYzuqIHXGgFm/boUwlKCfUVD4/0tj CcdcZpVDtDh265N09jn0AYibEUFJb5IO7YM7Kmygxc5HC4bTqJbM22dqfUFye4JcTyse 8PAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=WhFz7zYZll0u2m+3k3Z9AYZ2Q5LsGrduz4BC96Gaqdg=; b=JG6QhVjQO9xR09MUxN0PrhH9srh52mowHSt5BbCKirqA4ULpNBjxf+Ri7WMaBD9oWg fbF3VuCpROWf3HzdKnxEpfiNUL4xOrI6zUebSk5/NIkKn1Dv1z1AFxuP+l8FwadeYBst 44hKgogz+58whQl1vGg5Pl6QAQopAkyC7wtoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=WhFz7zYZll0u2m+3k3Z9AYZ2Q5LsGrduz4BC96Gaqdg=; b=MCQ2dZzxBzWfN/m44hA40w/x9Nn5pwhi6tzZqMOQzS+hqyBn0Np3Xdb9yMmDUtxjdg 567eZBlAfE/j8Xi9Ol5SPdT34dHlAqs7+I4sV5C0cSlLQB3b+9KzlkOSN3z1ujT6IwXh tgFEF/gZQ8Y8pP+iJx9AkEO4W2IVZYiaALCYd4R8vfholR1u8lpwp2h4iNDrExlzwzCe XKqw3OOqqhOCVF2NZODryNTCB417HYDyOYvdCl7n72DpCbUfGyQMiqPlMNZwnaTd4mhm ZpfxUjD+QqwkuFyaojkUUbDid8ZzpweT05vT9fiVhKTJWvW05YLUzb+doGnZ/iPVTlMt QLFw== X-Gm-Message-State: ALQs6tBt3X0npbXZpVCNhot8OuijWSipE0XxMutvnXnB+fy6iHwPO9Wf e7I7KRHgBhAwKWWpxRAEo/Vd9XHsg9I8mPZBUh7jeg== X-Received: by 10.31.148.135 with SMTP id w129mr24484610vkd.7.1524777371874; Thu, 26 Apr 2018 14:16:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.164.81 with HTTP; Thu, 26 Apr 2018 14:16:11 -0700 (PDT) In-Reply-To: <823082096.24861749.1524771086176.JavaMail.zimbra@redhat.com> References: <981100282.24860394.1524770798522.JavaMail.zimbra@redhat.com> <823082096.24861749.1524771086176.JavaMail.zimbra@redhat.com> From: Kees Cook Date: Thu, 26 Apr 2018 14:16:11 -0700 X-Google-Sender-Auth: Flt3Bziq1QjjMsZrHgJRq4D2lck Message-ID: Subject: Re: BUG: /proc/kcore does not export direct-mapped memory on arm64 (and presumably some other architectures) To: Dave Anderson , Ard Biesheuvel , Laura Abbott Cc: Linux Kernel Mailing List , Ingo Molnar , Andi Kleen 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 On Thu, Apr 26, 2018 at 12:31 PM, Dave Anderson wrote: > > While testing /proc/kcore as the live memory source for the crash utility, > it fails on arm64. The failure on arm64 occurs because only the > vmalloc/module space segments are exported in PT_LOAD segments, > and it's missing all of the PT_LOAD segments for the generic > unity-mapped regions of physical memory, as well as their associated > vmemmap sections. > > The mapping of unity-mapped RAM segments in fs/proc/kcore.c is > architecture-neutral, and after debugging it, I found this as the > problem. For each chunk of physical memory, kcore_update_ram() > calls walk_system_ram_range(), passing kclist_add_private() as a > callback function to add the chunk to the kclist, and eventually > leading to the creation of a PT_LOAD segment. > > kclist_add_private() does some verification of the memory region, > but this one below is bogus for arm64: > > static int > kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg) > { > ... [ cut ] ... > ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT)); > ... [ cut ] ... > > /* Sanity check: Can happen in 32bit arch...maybe */ > if (ent->addr < (unsigned long) __va(0)) > goto free_out; > > And that's because __va(0) is a bogus check for arm64. It is checking > whether the ent->addr value is less than the lowest possible unity-mapped > address. But "0" should not be used as a physical address on arm64; the > lowest legitimate physical address for this __va() check would be the arm64 > PHYS_OFFSET, or memstart_addr: > > Here's the arm64 __va() and PHYS_OFFSET: > > #define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) > #define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET) | PAGE_OFFSET) > > extern s64 memstart_addr; > /* PHYS_OFFSET - the physical address of the start of memory. */ > #define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) > > If PHYS_OFFSET/memstart_addr is anything other than 0 (it is 0x4000000000 on my > test system), the __va(0) calculation goes negative and creates a bogus, very > large, virtual address. And since the ent->addr virtual address is less than > bogus __va(0) address, the test fails, and the memory chunk is rejected. > > Looking at the kernel sources, it seems that this would affect other > architectures as well, i.e., the ones whose __va() is not a simple > addition of the physical address with PAGE_OFFSET. > > Anyway, I don't know what the best approach for an architecture-neutral > fix would be in this case. So I figured I'd throw it out to you guys for > some ideas. I'm not as familiar with this code, but I've added Ard and Laura to CC here, as this feels like something they'd be able to comment on. :) -Kees -- Kees Cook Pixel Security