Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5899430rwi; Tue, 18 Oct 2022 05:48:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gALjMzN9S3Os1NYEZUSFh9dk44ip835A48HqeYDyi/J9jxzYdQ4xLApNJqnkQMk2Fh7QU X-Received: by 2002:a17:902:6bc8:b0:179:fef9:b2fa with SMTP id m8-20020a1709026bc800b00179fef9b2famr2892299plt.96.1666097303955; Tue, 18 Oct 2022 05:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666097303; cv=none; d=google.com; s=arc-20160816; b=NXnNhehxe1AK1M/8Bggs6FDMBp+nIZ85Hk2Z8EztUE7clyrQCC1W+YqOG2zBxkIpBC nA0owjuKPabS0ZdMDrUuiOJayNgLxR8pKoNLL99IwMVmfP4rpxv5BPyFE2AhEpDfGha1 IoFFcNz+LvU8StzTIZ3pgGSEgXOpvnH1tzWjEYQsQtuqkeKzAzOYyqOciR+ALRROA696 XHnZDJEnOcQHsGU/pM0suIttMTQwD0S1N6bAVhLYIJVttiis4GHoy2nmzldkqpnvK3NF XpDymzYff2KxwoRW3G80zPshTUIzv2w+EP06B8adQK/9LlBJW52UfIoY5knV0nW8zHX9 WIDw== 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=sKipOqzSH18Zplx7+uC+JD42wmy1hZ3JXjFNsBc6m/s=; b=YALuC7Wcks/GPHog7dqYtqVf78cqKp/CobW/Yx/J3m/wBVhNK0TyegXzEhLZnqiaEE Yszr+55ZXJWnI19zf3s68CDi1bKrr5D1CFJJhGI3lYK4G0lJpxUX9NaoVDpNavrxzrzD 9oVyHDtCpCJONSa6B4DNCzCw0M+Nbp3s0av1UrhtJocg1HTRvdvTs62LBKsypd2KR67w rhLPY15tpv9lVinIpLtNS0q6UspJM4pRqpY09R70IsU3+lQVNFqwB+uTkwMmY/s4216i G6bN+0L3rkOjkWKZwdqxuAGIIvqb5lbhpbYlvbcl4v2nLD4pwu/aO7S+b0n7ZX2u/0By Q4+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qao1nO00; 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 p185-20020a6342c2000000b0045129bad767si14978128pga.421.2022.10.18.05.48.10; Tue, 18 Oct 2022 05:48:23 -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=qao1nO00; 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 S230087AbiJRMpm (ORCPT + 99 others); Tue, 18 Oct 2022 08:45:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbiJRMpk (ORCPT ); Tue, 18 Oct 2022 08:45:40 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED583BA923 for ; Tue, 18 Oct 2022 05:45:24 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7F14F33CB0; Tue, 18 Oct 2022 12:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1666097123; 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=sKipOqzSH18Zplx7+uC+JD42wmy1hZ3JXjFNsBc6m/s=; b=qao1nO00ADjQ8yQcW6uTOKI8ljAaHRmB0tSu8lw5e/PK0pix18uddsOLt+MH3eBQ6kHHGN iMaoqxdZGCKbEi17mTmgFLciNAgk61S6nYBJrgXvr444dB1mM9yHaH2bHJ5YYhySRLfjFI wX5QDMaYs8PbWBSCtXa5ZEbhfaohyZs= 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 173632C141; Tue, 18 Oct 2022 12:45:23 +0000 (UTC) Date: Tue, 18 Oct 2022 14:45:20 +0200 From: Petr Mladek To: Jane Chu Cc: Andy Shevchenko , "rostedt@goodmis.org" , "senozhatsky@chromium.org" , "linux@rasmusvillemoes.dk" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] vsprintf: protect kernel from panic due to non-canonical pointer dereference Message-ID: References: <20221017191611.2577466-1-jane.chu@oracle.com> <5d987403-a7bf-8996-d639-c99edeaabcdf@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d987403-a7bf-8996-d639-c99edeaabcdf@oracle.com> 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 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 Mon 2022-10-17 19:31:53, Jane Chu wrote: > On 10/17/2022 12:25 PM, Andy Shevchenko wrote: > > On Mon, Oct 17, 2022 at 01:16:11PM -0600, Jane Chu wrote: > >> While debugging a separate issue, it was found that an invalid string > >> pointer could very well contain a non-canical address, such as > >> 0x7665645f63616465. In that case, this line of defense isn't enough > >> to protect the kernel from crashing due to general protection fault > >> > >> if ((unsigned long)ptr < PAGE_SIZE || IS_ERR_VALUE(ptr)) > >> return "(efault)"; > >> > >> So instead, use kern_addr_valid() to validate the string pointer. > > > > How did you check that value of the (invalid string) pointer? > > > > In the bug scenario, the invalid string pointer was an out-of-bound > string pointer. While the OOB referencing is fixed, Could you please provide more details about the fixed OOB? What exact vsprintf()/printk() call was broken and eventually how it was fixed, please? > the lingering issue > is that the kernel ought to be able to protect itself, as the pointer > contains a non-canonical address. Was the pointer used only by the vsprintf()? Or was it accessed also by another code, please? I wonder if this patch would prevent the crash or if the broken kernel would crash later anyway. > That said, I realized that not all > architecture implement meaningful kern_addr_valid(), so this line > if ((unsigned long)ptr < PAGE_SIZE || IS_ERR_VALUE(ptr)) > is still need. I'll send v2. Please, add linux-mm@kvack.org into CC. I wonder if kern_addr_valid() is safe to use anywhere, especially during early boot. I wonder if it would make sense to implement it on all architectures. Best Regards, Petr