Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8099637rwi; Tue, 25 Oct 2022 02:26:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4y2nSEeUsUVtHmsPKNfZ+GFbiQ3oOT4F9qJL96BXeSEHE668qiYsgaTo2iO1hf2soEUaR8 X-Received: by 2002:a17:907:3201:b0:741:94f2:aeaf with SMTP id xg1-20020a170907320100b0074194f2aeafmr30975222ejb.505.1666689961447; Tue, 25 Oct 2022 02:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666689961; cv=none; d=google.com; s=arc-20160816; b=JJx26W2q9341APHZcdS4eW/vWRn3xDPRM/TbGQxCWooWipXOklAuj9P37ukMSOtAia s1sW86/yQjqA0L9ueurptSwMAb6vluobg//m2RBEE+xMhg8CxxODEpuUXRsNVELcaYEx J3sR6fjftPMwi4iGQKgwnsx4DYPxWh6aWNpsm8xu/JnBzo26B2Zj/SR0OYmX+YTwe4+Z PL4e0qyRpfOZTR1jN/L+w1+meZnRbIH57YxV0Dg3Vv3doiJfFrdBNrfHBaDmKBjBLLh5 p6EbWrdjBL3cl6dBwNfwRIMEnZdyW+VR++V3ud+a3lDP+46bNTL/HSqr+uMHDMPO0op/ 3aAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0fvfKX4zW0ea1QU1UhyN499kdzLJCK0LcIjY28CE2+g=; b=ea8ani18sgWL9Df5gBfI1GdEnJ3mrVyERYYu0sHTYov1GJ/+k4AkBEA96+XTMzxgPD n5OU6EGzcoeJnxGfWBNID0Pg+MitHGXlb8OfowYLGU+7HDUVHC+Ekir4ERkE5Tv1oORX 03dtXn4vaDTSlEbTx7qYpCs3fmiWBLWGxIRa1JXKPJwUX4FJPW3Mz6scbHuDpslye7s6 8Qah7Oayb11vsx+keUMcC2ZC1dyuhEdaV0RlMTDczQy26I4/4cpIiWGsbhIyZRfaJfbp 2iRWG2dfknoIdAfJgjUy/X7xtEt4Mias4V+qHgJEfGq6MEUsaSpU9uXTcxhAekpyfAk4 onrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=JogF0gqm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a056402084e00b0045d9ceae6d8si2743077edz.492.2022.10.25.02.25.37; Tue, 25 Oct 2022 02:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=JogF0gqm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231343AbiJYIkm (ORCPT + 99 others); Tue, 25 Oct 2022 04:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231326AbiJYIkk (ORCPT ); Tue, 25 Oct 2022 04:40:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B1333E02 for ; Tue, 25 Oct 2022 01:40:39 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 195331F74A; Tue, 25 Oct 2022 08:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1666687238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0fvfKX4zW0ea1QU1UhyN499kdzLJCK0LcIjY28CE2+g=; b=JogF0gqmtvMcCJ1EfisBNF/pR4anb/hP0BCY68OvOPdlf8p8muBqD/OvwarfT/JsqGvtVc YUXs93uLYDlX0wiKzoS84UVbbwtZT2qjCNC7U+K1ExP0iWtaXQT8OP3VNEHwqiZ5OB/TGo rN4QOsGK6oziPJvJVwAURB6xI1l+9n8= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 86A9F2C141; Tue, 25 Oct 2022 08:40:37 +0000 (UTC) Date: Tue, 25 Oct 2022 10:40:37 +0200 From: Petr Mladek To: Andy Shevchenko Cc: Konrad Rzeszutek Wilk , Jane Chu , rostedt@goodmis.org, senozhatsky@chromium.org, linux@rasmusvillemoes.dk, linux-mm@kvack.org, linux-kernel@vger.kernel.org, wangkefeng.wang@huawei.com, haakon.bugge@oracle.com, john.haxby@oracle.com Subject: Re: [PATCH v3 1/1] vsprintf: protect kernel from panic due to non-canonical pointer dereference Message-ID: References: <20221019194159.2923873-1-jane.chu@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2022-10-20 19:03:23, Andy Shevchenko wrote: > On Thu, Oct 20, 2022 at 10:52:03AM -0400, Konrad Rzeszutek Wilk wrote: > > On Wed, Oct 19, 2022 at 11:33:47PM +0300, Andy Shevchenko wrote: > > > On Wed, Oct 19, 2022 at 01:41:59PM -0600, Jane Chu wrote: > > > > Having stepped on a local kernel bug where reading sysfs has led to > > > > out-of-bound pointer dereference by vsprintf() which led to GPF panic. > > > > And the reason for GPF is that the OOB pointer was turned to a > > > > non-canonical address such as 0x7665645f63616465. > > > > > > > > vsprintf() already has this line of defense > > > > if ((unsigned long)ptr < PAGE_SIZE || IS_ERR_VALUE(ptr)) > > > > return "(efault)"; > > > > Since a non-canonical pointer can be detected by kern_addr_valid() > > > > on architectures that present VM holes as well as meaningful > > > > implementation of kern_addr_valid() that detects the non-canonical > > > > addresses, this patch adds a check on non-canonical string pointer by > > > > kern_addr_valid() and "(efault)" to alert user that something > > > > is wrong instead of unecessarily panic the server. > > > > > > > > On the other hand, if the non-canonical string pointer is dereferenced > > > > else where in the kernel, by virtue of being non-canonical, a crash > > > > is expected to be immediate. > > > > > > What if there is no other dereference except the one happened in printf()? > > > > > > Just to point out here, that I formally NAKed this on the basis that NULL > > > and error pointers are special, for the bogus pointers we need crash ASAP, > > > no matter what the code issues it. I.o.w. printf() is not special for that > > > kind of pointers (i.e. bogus pointers, but not special). > > > > Hey Andy, > > > > Do we want to have user space programs crash the kernel? > > > > This patch leads to making the kernel more harden so that we do > > not crash when there are bugs but continue on. > > Fine, how to push a user to report a bug in the kernel if for them > there is no bug? > > OK, let's assume user recognizes this as a bug, what should they do in order > to provide a better description of the bug, so developer can easily debug > and fix it? WARN() would provide similar information as panic() without actually crashing the kernel. > > Would we not want that experience for users ? > > Yes, if it is a bug in the kernel we want to know it with all possible details. > Hiding bugs is a way to nowhere. I agree but we should always distinguish between fatal problems where the system could hardly continue working and unexpected behavior that is not critical. Many error code paths handle unexpected situations. Some problems are caused by users and some by bugs in the code. The kernel could always refuse doing some operation rather than crash. People will report it because it does not work. And there are non-destructive ways how to show useful debugging information. Best Regards, Petr