Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2673359imj; Mon, 11 Feb 2019 06:50:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IaP+mXcq/77CGpYb7k4V36fUdQZZpGDHEDgWblb4UoblnRmFQW95fzoteyxYzSN/7b1wnBv X-Received: by 2002:a63:d846:: with SMTP id k6mr34337869pgj.251.1549896625469; Mon, 11 Feb 2019 06:50:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549896625; cv=none; d=google.com; s=arc-20160816; b=Om6S8wI0C2isFrIEJaB7opBY31cACxrmC9OP+7+ehjH3KIhlhVoAN4v7QUh8EaPh7Y r8wQUELAev2q0YJ5jjDGHaCydBZBJbb+PDMIY5ewqdIDMcnUC8m+yEGkqp9M71waSJx5 abMcopS88Pnehxf0rOiXfbS2yW8yAKBIROMLh5q/NL/Wk8k0ymBmLThExU58698ZLXWB u/T/Aj5szvoOPtFrVYlPAgf/m+bGFhDN27seT5MrHK6+xhqnNaFX0BLRqanVGJo41JQp SU12rCI4yGHmo5iOO4FrHBi6RRfCNrw2P+vGywQ9fD6Ug4fPdnNX5xK2lusHd7nKXwiI 1GlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=WyDizlV64RwSAg6GQsgYX5scLMuSyAqFiZQSa9fvCz0=; b=bj0ry3zsZyMW93I+bC78N6+zErGRvjk7iWa9z5eBZKbUYQHYDPX/Mr2mxTlXTUJ19r /ctw6cHf2OKVFIjdbJleADyjPv0qfXlerddQ1cd1b5GKGuXRtlUY3Gn+nPC6FKnnmN75 SobOjGc00mxowU2gwzmtpqriyI/AuZnXV54z+udP2Aam+KBKwCxVnLNGtuXvwd7g/z6I BjzD3uZLVDSwZmoYmyYiP3OAHUfcznUsc4BOoeTWnFe8ZmZ9AuZQNVluslTdRk2sk87r Gfcy+yF2hCOXnz7kFzYucicoYIpj8z8nzbDRnG9FZPkOl593pwlpXxxaLSCRsp3KId+/ 7KWQ== 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 y129si1882459pgy.175.2019.02.11.06.50.09; Mon, 11 Feb 2019 06:50:25 -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 S2387828AbfBKOtL (ORCPT + 99 others); Mon, 11 Feb 2019 09:49:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:34686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387809AbfBKOtK (ORCPT ); Mon, 11 Feb 2019 09:49:10 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1347520844; Mon, 11 Feb 2019 14:49:08 +0000 (UTC) Date: Mon, 11 Feb 2019 09:49:07 -0500 From: Steven Rostedt To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Dan Carpenter , Sasha Levin Subject: Re: [PATCH 4.20 138/352] tracing: Have trace_stack nr_entries compare not be so subtle Message-ID: <20190211094907.41712c44@gandalf.local.home> In-Reply-To: <20190211141855.296924278@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> <20190211141855.296924278@linuxfoundation.org> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 11 Feb 2019 15:16:05 +0100 Greg Kroah-Hartman wrote: > 4.20-stable review patch. If anyone has any objections, please let me know. > This is not a bug fix and was not meant for stable. Please do not apply. -- Steve > ------------------ > > [ Upstream commit ca16b0fbb05242f18da9d810c07d3882ffed831c ] > > Dan Carpenter reviewed the trace_stack.c code and figured he found an off by > one bug. > > "From reviewing the code, it seems possible for > stack_trace_max.nr_entries to be set to .max_entries and in that case we > would be reading one element beyond the end of the stack_dump_trace[] > array. If it's not set to .max_entries then the bug doesn't affect > runtime." > > Although it looks to be the case, it is not. Because we have: > > static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] = > { [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX }; > > struct stack_trace stack_trace_max = { > .max_entries = STACK_TRACE_ENTRIES - 1, > .entries = &stack_dump_trace[0], > }; > > And: > > stack_trace_max.nr_entries = x; > for (; x < i; x++) > stack_dump_trace[x] = ULONG_MAX; > > Even if nr_entries equals max_entries, indexing with it into the > stack_dump_trace[] array will not overflow the array. But if it is the case, > the second part of the conditional that tests stack_dump_trace[nr_entries] > to ULONG_MAX will always be true. > > By applying Dan's patch, it removes the subtle aspect of it and makes the if > conditional slightly more efficient. > > Link: http://lkml.kernel.org/r/20180620110758.crunhd5bfep7zuiz@kili.mountain > > Signed-off-by: Dan Carpenter > Signed-off-by: Steven Rostedt (VMware) > Signed-off-by: Sasha Levin > --- > kernel/trace/trace_stack.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c > index 2b0d1ee3241c..e2a153fc1afc 100644 > --- a/kernel/trace/trace_stack.c > +++ b/kernel/trace/trace_stack.c > @@ -286,7 +286,7 @@ __next(struct seq_file *m, loff_t *pos) > { > long n = *pos - 1; > > - if (n > stack_trace_max.nr_entries || stack_dump_trace[n] == ULONG_MAX) > + if (n >= stack_trace_max.nr_entries || stack_dump_trace[n] == ULONG_MAX) > return NULL; > > m->private = (void *)n;