Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3245837pxf; Mon, 5 Apr 2021 07:09:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwERQNYKDOV+A/szv7XXSvSsTDt4ZSzxQtypZ/K/nWSGJ87ZYTrNvYojN92IB/NfMbA4L7u X-Received: by 2002:a17:906:1115:: with SMTP id h21mr15649882eja.352.1617631753728; Mon, 05 Apr 2021 07:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617631753; cv=none; d=google.com; s=arc-20160816; b=0ctaTR/Qdc5uAMrfYDcz4ym2aWL8hdNs72IPzfI66K2YDV4lq5hQJoJKzmcPlv84Hi k7CEFYhs1i5OuITiW+1tjhPEiDMgNERw/oQycPAT9BQwRGYn0sc8wustK2Lt6v/X87VQ wN9Q4l+gPjuwkX4xk8sP19sk0QVS5UZKtthOVethueD/Gqe5WSczLO+s4yljzDQ8+YUa gZ7wsRzp4I4dvR3rn1SHjlV6rEfMX/mAclKEjDN6HkCGPvVpwPdWXtARKpOb97UQZjTM JAj5rvoMtQihznd143qXGV6KHSquJgpFwZ9MD2EATGeUFJJcUiOFn9dh2GPV+x7EWPPe 4dKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dQw5vZFXfNE2KMvZnyXFB918aZYOPn1UDYNVkIA+cGs=; b=pGAbRH3hMchlHJd4pniSZC7h+K7ELmJBruyDLHgP6Gf1462LhJ6kFWnWIJ+ugKSz1h 0cNrQfwoVNQ8C3C4sh/DkPMGrd8vhCDFnJ3cI2EiC2ZcfuGw6yF9JIIACNb7X7I2NHNr 2J40p9xTB7htrq7oeDroWVpNDxnuiq5J3RL/J1EOSlshBv7adxziUBJTzVawflMS4/d+ b84uKzubGaKP5XZaLR6qXIOkO/wzYkBZLGjXOhJtR9I38jX2MlLhI5Ca/d5d9ifN1n6z TwbZ3IrFrx6T11uZDrPLA5/TDX7IrFBRlNXXhjre4DD1+0WixAgi0UBg/QGoycAtvrZo WU6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g+YQ881o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v2si5302353edw.153.2021.04.05.07.08.50; Mon, 05 Apr 2021 07:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g+YQ881o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237510AbhDEJCy (ORCPT + 99 others); Mon, 5 Apr 2021 05:02:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:43414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237262AbhDEJB3 (ORCPT ); Mon, 5 Apr 2021 05:01:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 67CAE610E8; Mon, 5 Apr 2021 09:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617613276; bh=GDA/V174sJWMf+BaEEszQCXILyZ5LI9jMZfXs7HDUOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+YQ881oT8Lr4sAE5JDX/uew/y8AyQxqchUBZvdPqTKM3HMTOMtXLdUB38GiysjVH qefHA9EuA/O1jvpWnNOqBQXtYxTs+kooMM633yXSYIRkP2v1nbFpeESfkJi41ZllGW BX1e9m5DFID9yVanweSUK3/S7x47oDUL7g82oGrI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Gorbik , "Steven Rostedt (VMware)" Subject: [PATCH 4.19 34/56] tracing: Fix stack trace event size Date: Mon, 5 Apr 2021 10:54:05 +0200 Message-Id: <20210405085023.627967648@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085022.562176619@linuxfoundation.org> References: <20210405085022.562176619@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit 9deb193af69d3fd6dd8e47f292b67c805a787010 upstream. Commit cbc3b92ce037 fixed an issue to modify the macros of the stack trace event so that user space could parse it properly. Originally the stack trace format to user space showed that the called stack was a dynamic array. But it is not actually a dynamic array, in the way that other dynamic event arrays worked, and this broke user space parsing for it. The update was to make the array look to have 8 entries in it. Helper functions were added to make it parse it correctly, as the stack was dynamic, but was determined by the size of the event stored. Although this fixed user space on how it read the event, it changed the internal structure used for the stack trace event. It changed the array size from [0] to [8] (added 8 entries). This increased the size of the stack trace event by 8 words. The size reserved on the ring buffer was the size of the stack trace event plus the number of stack entries found in the stack trace. That commit caused the amount to be 8 more than what was needed because it did not expect the caller field to have any size. This produced 8 entries of garbage (and reading random data) from the stack trace event: -0 [002] d... 1976396.837549: => trace_event_raw_event_sched_switch => __traceiter_sched_switch => __schedule => schedule_idle => do_idle => cpu_startup_entry => secondary_startup_64_no_verify => 0xc8c5e150ffff93de => 0xffff93de => 0 => 0 => 0xc8c5e17800000000 => 0x1f30affff93de => 0x00000004 => 0x200000000 Instead, subtract the size of the caller field from the size of the event to make sure that only the amount needed to store the stack trace is reserved. Link: https://lore.kernel.org/lkml/your-ad-here.call-01617191565-ext-9692@work.hours/ Cc: stable@vger.kernel.org Fixes: cbc3b92ce037 ("tracing: Set kernel_stack's caller size properly") Reported-by: Vasily Gorbik Tested-by: Vasily Gorbik Acked-by: Vasily Gorbik Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2645,7 +2645,8 @@ static void __ftrace_trace_stack(struct size *= sizeof(unsigned long); event = __trace_buffer_lock_reserve(buffer, TRACE_STACK, - sizeof(*entry) + size, flags, pc); + (sizeof(*entry) - sizeof(entry->caller)) + size, + flags, pc); if (!event) goto out; entry = ring_buffer_event_data(event);