Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1161572ybv; Wed, 5 Feb 2020 22:32:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyujBoGk/3puUdWzIq9pMp7ghbQpi24MLU92edqdR1KuppVkAJuJYfr6yKJskZMX4d7e/mK X-Received: by 2002:aca:cdd0:: with SMTP id d199mr5949860oig.49.1580970747395; Wed, 05 Feb 2020 22:32:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580970747; cv=none; d=google.com; s=arc-20160816; b=ZVdn9LY1LdVCi5PDlqunyizU1qFkQIq44rn3n4eYV4MgLfkdBPhW2mTzr6QQrXXOvY VB86OKbrYKTJaYjc8yXvJOf7gasKXJzclpr1XW8gtUy2Rg4dBZjXPU+olUlvdNsJQWdt GKfT7CfG1ghIzqRhkpQryqlyvWfABidbNLW1rqnDtR8W1m5bkdUFjqO3oQzzzhai4xzv E1xXteDuO5fnd5v4WtZ6PwyJAlSWhmOq1lXCzM7P4M2jLDwqRSY5galJGTNktsbIkJW5 9HDpNr1rI7fDwL1fsF5Iq9gMDKbXSVYCayD4dbjs/kkMQXyzxrf1nHZf1aETpaffrg31 uqpA== 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:dkim-signature; bh=EiT7U6hb4n9/ss5eLUuNHb8HbJPdrNLlNFry2pPtbL8=; b=hM5PaiFYOuOdOh61x97c6voDpwLWPgF0BDcQmGJWrjKamCnPJeQGg3JNIeOVhzUJsQ /qTUl/MVf5AVzUeS1iAXEEUa6bfqAdmkzbg0I0DC4VDkhm7AMO/LRtq17AqPXA6FFPKc K9CnE4znA0/4BrxclxvpkLymb6yAsQnOiy09DlOjcZ17/97evO8LKEY28bzuWa+WUqm3 D3CktwGjKaD3YpIq2bt3yxO5N5yPDF5YikaTDMoywBwvyYyQlaKHgzDdQXqLBjYyafad ZM663Wl1GO2bvGxlfwfeq71/nqTN7568jyZNYGkVaAvphF8ljssHuj4151Izl4Y5yMO9 sTHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cjPVEqQ8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si1641243oic.222.2020.02.05.22.32.15; Wed, 05 Feb 2020 22:32:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cjPVEqQ8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727926AbgBFGbP (ORCPT + 99 others); Thu, 6 Feb 2020 01:31:15 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:40636 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726778AbgBFGbP (ORCPT ); Thu, 6 Feb 2020 01:31:15 -0500 Received: by mail-pj1-f68.google.com with SMTP id 12so2067308pjb.5 for ; Wed, 05 Feb 2020 22:31:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EiT7U6hb4n9/ss5eLUuNHb8HbJPdrNLlNFry2pPtbL8=; b=cjPVEqQ8bIU4+SzkdcJ7r1Hismp60wHdUsPx0PSGD1yrI1kkCfr9ExmhcZmNl51yom qvyh5lNMSE1OyfMu2MIy2fOGLvCDAQNGxWKiY62A7uy2XaX7t1LYe22XoPPehCaLERFA FZ6s+LnHoB/yssJ/Dt/onvF9MgQM+mOGUX7+FDu/Gd8oCjfXepl4o4N8SXiCD6CDCPAt p3PkrdvixpY6I8Kr/BGmjNuzHVAoukZlNTH9Nz4wca+9clFk3rsjE+dprySUbZTx1KbY 7hbv/52fy+ILZSGupGLCwpCh2gMQRoxSKjR2m4NZkxwBi7evZ2qUmBjD71JkfBZsWo2e O8PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=EiT7U6hb4n9/ss5eLUuNHb8HbJPdrNLlNFry2pPtbL8=; b=eCoXmsoANFgs5M6JXaYn7ToEyeVh06u2rZZTi1AH9gayohMroeeay3OnG76LYRqHeH XRm3bfXcIFSdQDygMDusYzKx8taC5Ij/mIsju4qkwgzT1+HxglpyhZRAsYBhJzMRd+MI mQZ6z2UZ4y8H7M3VhmQnE05ECo0OZn+zznAsvWjYGxkCi95RvovpNS6sRwPsvuZwqV9y a4gbVIzPfkeT+ozs22K0FrD5qqO5U+JU0QKmO7DyrQMA3rev4CuCxFBX0il0Je7KRLZz rMSRwWauor0B2FG91ovP6oqyhzkld1/2uFgSy/Tr/anAH209CC/5WO50YMSYj9XDlTZB FmOA== X-Gm-Message-State: APjAAAWoDiJGndvNLJz5Mrgqw1lkXASAIM6IhTCKHrtJV7/xexkDzTga Q0RL7VQ8CvSWD6CxOHkWXnZbUtnR X-Received: by 2002:a17:90a:1f8d:: with SMTP id x13mr2502314pja.27.1580970674468; Wed, 05 Feb 2020 22:31:14 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d26sm1798137pgv.66.2020.02.05.22.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 22:31:13 -0800 (PST) Date: Thu, 6 Feb 2020 15:31:10 +0900 From: Sergey Senozhatsky To: John Ogness Cc: Sergey Senozhatsky , 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 Message-ID: <20200206063110.GM41358@google.com> 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> <87wo919grz.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wo919grz.fsf@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (20/02/05 16:48), John Ogness wrote: > 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); Yes. That should do. It seems that /dev/kmsg reads/writes happen very early in my system and all the backtraces I saw were from completely unrelated paths - either a NULL deref at sys_clone()->do_fork()->copy_creds()->prepare_creads(), or general protection fault in sys_keyctl()->join_session_keyring()->prepare_creds(), or some weird crashes in ext4. And so on. I see some more unexplainable lockups on one on my test boards, but I can't provide more details at this time. Might not be related to the patch set. Need to investigate further. -ss