Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2723342imj; Mon, 11 Feb 2019 07:31:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IYtgVW6fpNhJlAf4ce9mV4+VWPUHg5NrY3UwoRfYQ2kN0alM9NRkOUgNQxPgShuWOlltLmy X-Received: by 2002:a62:109b:: with SMTP id 27mr36736382pfq.227.1549899112058; Mon, 11 Feb 2019 07:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899112; cv=none; d=google.com; s=arc-20160816; b=qS+3fmQn7wadCnaMQyLdxXRqzik62sfACDcdqB7NsNDI1vh0JS/boIuW84lhAT+t43 sjKM0Hpi2Ckbj++DJhYnfKKY9CYTp/12Lgi8l6Bqjf3xenEG5ZZxZu7DUgk+aW5mBGTa YKNUyC9j4bQCOuqac9eVFEDgKfpvOPajwdhtrqa1116mlP+I8li3vEXROqZgnK9IsHtg b1qkzR4Ejg+kZ8DXLe7KwXYaEbO3vB9KUIHnu8Djnd/CqzQTfVUMfC4239M03NyEXa3M ji5DCDgp6kKy67PdXHLnF8/ddaO+wjzAV3bfsMScf3l/LZG9HHkiptmEvOhbzsTowD+Z SRpw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RZ2pumYfTCS9CWqa8CaLR09mIwcx6I4HmyR9OH1FvZ8=; b=S6Wonud43rwWewBfKhl6qUwdbQKA3JqGOtbb3+V1JxClr7ENTRBIp74InesmxjlkPT P7QncE2wQFnWZSrtaAGL43b0kTjyUp2QE9BNIji6xfygE7uvPXBxN0er7vfokuId5mvH 2lop7r6RWZ89kVYL3tKEjR5fZeVTTVnLLzlx8F4E1nidPQwRiAqp78UhMZZLEheGr+NW 4qAKvbeNyvUJgvZMdEJ+RxiQwBbpZBggZuShJdB7HJAjYDEn6ZOujJG1GbGtk84Cj7kZ 3kHkvcvUTWZPLXHW2B+sZhzAXLThIzrRfuXHQoqu1A7v/8SRokrHLQv7lwjRRbSfVfyH K0fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R0bT78yp; 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 l24si9627982pgj.171.2019.02.11.07.31.34; Mon, 11 Feb 2019 07:31:52 -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=@kernel.org header.s=default header.b=R0bT78yp; 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 S1730847AbfBKP3Y (ORCPT + 99 others); Mon, 11 Feb 2019 10:29:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:45118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728869AbfBKO5j (ORCPT ); Mon, 11 Feb 2019 09:57:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 C4FEC20700; Mon, 11 Feb 2019 14:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897059; bh=qQVVisWLrG+14GC3Tu8GD+5RQRblYfACaS/IJCFpWGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0bT78ypgj3btCwZRl4nMQFwevzFABEXUoJEV0p1CztnQzIGvW5V0CGKwXHS8d47H 5J1W8IRZR6qj2Y8vZ3kie09lM60EiLIgZj9QyBi08crx6blnZV2ErV55mXfN/ThuXo p8W6Ro6WiFXL/MLngeQFk5y1s39P7/DCl3NfGUEo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 4.14 077/205] tracing: Have trace_stack nr_entries compare not be so subtle Date: Mon, 11 Feb 2019 15:17:55 +0100 Message-Id: <20190211141833.742514107@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 719a52a4064a..ba662010542c 100644 --- a/kernel/trace/trace_stack.c +++ b/kernel/trace/trace_stack.c @@ -282,7 +282,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; -- 2.19.1