Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp419073ybv; Wed, 5 Feb 2020 07:51:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwX6IcpZdz4DOlUuKbmPr+JGb8OAtUAIZqZNmr6qakLujUOqfjLLb7E51jNp4VL+RQpZzt0 X-Received: by 2002:aca:f1c2:: with SMTP id p185mr3432151oih.87.1580917866488; Wed, 05 Feb 2020 07:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580917866; cv=none; d=google.com; s=arc-20160816; b=KthCtv1oZySHoebc2XrlWm6E6YpmJV0dkM3TLdJMXIwBbF1LATAoZM9xi0jX4FchjT 0VF/lzla7pexSxS7dFL01w9Bd4Do3tf7cbA3uCSJ/zFlgptl13tsUkJpIXSLCWAOra/k GkqyMwZOwkbMr0QerOkxhMTr+PO5adaVgiwFDcYvhkl7E4/3EdsRwp+WR86t76oieJ8R scoRKNdaeDCWo4EtGW4v2vCk42b2GyD8gr6LCoM8i+O8HSvHdn5498essryugsyI3dkZ 5Hd3a1ETeoGhdcFS9jmLuuo+lwesstWMmxpvh1c+BdUwusndw3exhkYP6xTNU0WydT5r ojiQ== 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:message-id :in-reply-to:date:references:subject:cc:to:from; bh=lNOwWu6VatvmeS9qqdDbl4D8DMM/i85HCTHBV1dLunU=; b=iHU4IDQ0BReWxc5BAmjpvH+IoVarq3m/yLs7C/S/KqISgdrdPbs6f0KDf5MGfjzKyc XtpClw9CHj1wLR7iNqFn85YNWjuqiXubwI8zo/5DblXqxk5g5hlbCvtAcFSrqnfv7F8P 1YlpEmXl3ulURtxsB6NkGix/MLy23p+eUb9y3soJPLeX/osFfHFUmkZWSeHegMuYVQic 4+R1ueYcY+mjO8dMm3IbWtKr3P53YOUwWWyYXKltztXIrGLQn00ZQwvj2shsx4ZjCAXM EYJ05cE9Tnu3rcbynKEBqODAgiepWdrtwFkaJYurnw3PfoV+1YNn7o5+tN/UySol7b3S rg8A== 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 s21si14516779otr.304.2020.02.05.07.50.54; Wed, 05 Feb 2020 07:51:06 -0800 (PST) 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 S1727398AbgBEPsp (ORCPT + 99 others); Wed, 5 Feb 2020 10:48:45 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35877 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbgBEPsm (ORCPT ); Wed, 5 Feb 2020 10:48:42 -0500 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1izMus-0004bD-Iv; Wed, 05 Feb 2020 16:48:38 +0100 From: John Ogness To: Sergey Senozhatsky Cc: Sergey Senozhatsky , lijiang , Petr Mladek , Peter Zijlstra , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2] printk: replace ringbuffer References: <20200128161948.8524-1-john.ogness@linutronix.de> <20200205044848.GH41358@google.com> <20200205050204.GI41358@google.com> <88827ae2-7af5-347b-29fb-cffb94350f8f@redhat.com> <20200205063640.GJ41358@google.com> <877e11h0ir.fsf@linutronix.de> <20200205110522.GA456@jagdpanzerIV.localdomain> Date: Wed, 05 Feb 2020 16:48:32 +0100 In-Reply-To: <20200205110522.GA456@jagdpanzerIV.localdomain> (Sergey Senozhatsky's message of "Wed, 5 Feb 2020 20:07:44 +0900") Message-ID: <87wo919grz.fsf@linutronix.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-02-05, Sergey Senozhatsky wrote: > 3BUG: KASAN: wild-memory-access in copy_data+0x129/0x220> > 3Write of size 4 at addr 5a5a5a5a5a5a5a5a by task cat/474> The problem was due to an uninitialized pointer. Very recently the ringbuffer API was expanded so that it could optionally count lines in a record. This made it possible for me to implement record_print_text_inline(), which can do all the kmsg_dump multi-line madness without requiring a temporary buffer. Rather than passing an extra argument around for the optional line count, I added the text_line_count pointer to the printk_record struct. And since line counting is rarely needed, it is only performed if text_line_count is non-NULL. I oversaw that devkmsg_open() setup a printk_record and so I did not see to add the extra NULL initialization of text_line_count. There should be be an initializer function/macro to avoid this danger. John Ogness The quick fixup: diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d0d24ee1d1f4..5ad67ff60cd9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -883,6 +883,7 @@ static int devkmsg_open(struct inode *inode, struct file *file) user->record.text_buf_size = sizeof(user->text_buf); user->record.dict_buf = &user->dict_buf[0]; user->record.dict_buf_size = sizeof(user->dict_buf); + user->record.text_line_count = NULL; logbuf_lock_irq(); user->seq = prb_first_seq(prb);