Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp908498yba; Thu, 9 May 2019 07:47:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6bqH54Q8J4I7sXHonJ5eCcruGRgv5PUMuv5g2VmLONIRd6/CqRMfhjRgybdCgLhyHjNVs X-Received: by 2002:aa7:8c1a:: with SMTP id c26mr5705566pfd.25.1557413277902; Thu, 09 May 2019 07:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557413277; cv=none; d=google.com; s=arc-20160816; b=ozmuovtLXPdn2wuNY0NSP7SNZcT2gSDk+FabeXL8E01Dne8iPpXGsY5KRl3AO+qPPD a0YKb6ezCUEyI9cQwqyC5Cr2oz+S4XhOVNGtSOQ3NfRzM8uYkIC9TYs6t8Fp7kuDbnnH nvPLmPLXZxIlYCK5zsKmzvsS9zN0uQbEDTvOrXs9ZcnILFYZ23kLu4/Nif29cJgRmUjY 4EqvYyuuf72oL1zWtIyianGIP8E3HldtVB64vDeBDAor0UAoq5gRA7gejPApyOXiTxr8 0oVuwbzKd92i1YDVysS9L6eLfjV0Ajo+yRgXKmXh5BJ1DCu9PEBIleDU+2A034b/aaVK KSvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=4yG+65jWnW1ADMx7LqvT5UOGyx9kSaR3a3jJSE6KpUM=; b=LNcBlaNWY2488mlH1c8A+z8YEaWxA2fpa3O81pWzxD0bKgiZ94JrGIiWvrcu00T3CJ 7aUFXpdWbscyZzEJvfwBVn1X+D4nLzqK4xCg22gV0F7TDXXm4s38Aq7WZIRqr/gbW3Qw bk3Eka8MmvNcBlYO0g0eEwkI2YF9HWISLi8806acD0BmSLOOLMKNXnq7hTzMaPj6/PQK /QXTS7dd8NpQyzxvx23lgwQjqATH1TjbKwh9agEIu5Vr6C9REqKv/EzE4EA6FmoJVDkm jevpfZSU3IO/4NOTH+BtQK9JfNMT5XCGyQbJx86KWYpNhClH2KWSMgrNXblNj0tSGIMA PS1w== 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 33si3033636plk.421.2019.05.09.07.47.40; Thu, 09 May 2019 07:47:57 -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 S1726710AbfEIOGP (ORCPT + 99 others); Thu, 9 May 2019 10:06:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:60536 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726192AbfEIOGP (ORCPT ); Thu, 9 May 2019 10:06:15 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9158BAC31; Thu, 9 May 2019 14:06:12 +0000 (UTC) Date: Thu, 9 May 2019 16:06:09 +0200 From: Petr Mladek To: Steven Rostedt Cc: Linus Torvalds , Andy Shevchenko , Rasmus Villemoes , "Tobin C . Harding" , Michal Hocko , Sergey Senozhatsky , Sergey Senozhatsky , linux-kernel@vger.kernel.org, Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Russell Currey , Christophe Leroy , Stephen Rothwell , Heiko Carstens , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Martin Schwidefsky Subject: Re: [PATCH] vsprintf: Do not break early boot with probing addresses Message-ID: <20190509140609.n44v6kj27wb77jck@pathway.suse.cz> References: <20190509121923.8339-1-pmladek@suse.com> <20190509091357.0af3fcd7@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190509091357.0af3fcd7@gandalf.local.home> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2019-05-09 09:13:57, Steven Rostedt wrote: > On Thu, 9 May 2019 14:19:23 +0200 > Petr Mladek wrote: > > > The commit 3e5903eb9cff70730 ("vsprintf: Prevent crash when dereferencing > > invalid pointers") broke boot on several architectures. The common > > pattern is that probe_kernel_read() is not working during early > > boot because userspace access framework is not ready. > > > > The check is only the best effort. Let's not rush with it during > > the early boot. > > > > Details: > > > > 1. Report on Power: > > > > Kernel crashes very early during boot with with CONFIG_PPC_KUAP and > > CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG > > > > The problem is the combination of some new code called via printk(), > > check_pointer() which calls probe_kernel_read(). That then calls > > allow_user_access() (PPC_KUAP) and that uses mmu_has_feature() too early > > (before we've patched features). With the JUMP_LABEL debug enabled that > > causes us to call printk() & dump_stack() and we end up recursing and > > overflowing the stack. > > > > Because it happens so early you don't get any output, just an apparently > > dead system. > > > > The stack trace (which you don't see) is something like: > > > > ... > > dump_stack+0xdc > > probe_kernel_read+0x1a4 > > check_pointer+0x58 > > string+0x3c > > vsnprintf+0x1bc > > vscnprintf+0x20 > > printk_safe_log_store+0x7c > > printk+0x40 > > dump_stack_print_info+0xbc > > dump_stack+0x8 > > probe_kernel_read+0x1a4 > > probe_kernel_read+0x19c > > check_pointer+0x58 > > string+0x3c > > vsnprintf+0x1bc > > vscnprintf+0x20 > > vprintk_store+0x6c > > vprintk_emit+0xec > > vprintk_func+0xd4 > > printk+0x40 > > cpufeatures_process_feature+0xc8 > > scan_cpufeatures_subnodes+0x380 > > of_scan_flat_dt_subnodes+0xb4 > > dt_cpu_ftrs_scan_callback+0x158 > > of_scan_flat_dt+0xf0 > > dt_cpu_ftrs_scan+0x3c > > early_init_devtree+0x360 > > early_setup+0x9c > > > > 2. Report on s390: > > > > vsnprintf invocations, are broken on s390. For example, the early boot > > output now looks like this where the first (efault) should be > > the linux_banner: > > > > [ 0.099985] (efault) > > [ 0.099985] setup: Linux is running as a z/VM guest operating system in 64-bit mode > > [ 0.100066] setup: The maximum memory size is 8192MB > > [ 0.100070] cma: Reserved 4 MiB at (efault) > > [ 0.100100] numa: NUMA mode: (efault) > > > > The reason for this, is that the code assumes that > > probe_kernel_address() works very early. This however is not true on > > at least s390. Uaccess on KERNEL_DS works only after page tables have > > been setup on s390, which happens with setup_arch()->paging_init(). > > > > Any probe_kernel_address() invocation before that will return -EFAULT. > > Hmm, this sounds to me that probe_kernel_address() is broken for these > architectures. Perhaps the system_state check should be in > probe_kernel_address() for those architectures? Yeah. Well, these problems are hard to debug. It left a dead power system with a blank screen. I am not sure if the added check is worth the pain. I hope that the check would help to debug problems. But it is yet another complexity in printk() path. I think that it is fine to keep it enabled only on the booted system for a while and get some more feedback. Best Regards, Petr