From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935085AbcKKSHP (ORCPT ); Fri, 11 Nov 2016 13:07:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:39182 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756930AbcKKSHO (ORCPT ); Fri, 11 Nov 2016 13:07:14 -0500 Date: Fri, 11 Nov 2016 19:07:09 +0100 From: Petr Mladek To: Steven Rostedt Cc: Linus Torvalds , Joe Perches , Andrew Morton , Sergey Senozhatsky , Jason Wessel , Jaroslav Kysela , Takashi Iwai , Chris Mason , Josef Bacik , David Sterba , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] printk/NMI: Handle continuous lines and missing newline Message-ID: <20161111180709.GA2145@dhcp128.suse.cz> References: <1478695291-12169-1-git-send-email-pmladek@suse.com> <1478695291-12169-2-git-send-email-pmladek@suse.com> <20161111122851.0417e6af@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161111122851.0417e6af@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2016-11-11 12:28:51, Steven Rostedt wrote: > On Wed, 9 Nov 2016 13:41:28 +0100 > Petr Mladek wrote: > > > > /* > > @@ -135,8 +170,8 @@ static void __printk_nmi_flush(struct irq_work *work) > > __RAW_SPIN_LOCK_INITIALIZER(read_lock); > > struct nmi_seq_buf *s = container_of(work, struct nmi_seq_buf, work); > > unsigned long flags; > > - size_t len, size; > > - int i, last_i; > > + size_t len; > > + int i; > > > > /* > > * The lock has two functions. First, one reader has to flush all > > @@ -154,12 +189,14 @@ static void __printk_nmi_flush(struct irq_work *work) > > /* > > * This is just a paranoid check that nobody has manipulated > > * the buffer an unexpected way. If we printed something then > > - * @len must only increase. > > + * @len must only increase. Also it should never overflow the > > + * buffer size. > > */ > > - if (i && i >= len) { > > + if ((i && i >= len) || len > sizeof(s->buffer)) { > > What's wrong with using s->len? Isn't that what is inside the buffer? > Couldn't just checking against the buffer size print garbage? Note that this is not the classic seq_buf. It is struct nmi_seq_buf where "len" is atomic_t and buffer is defined as buffer[NMI_LOG_BUF_LEN]. It is just a paranoid check that should newer be true if the implementation is correct. I believe that it makes sense as is. Best Regards, Petr