Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3295281pxf; Mon, 5 Apr 2021 08:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSlAqArMh1odFDegSxvdMRSrHpfrgD5L8BZGqshhPPxfLW14ewc/sknwaFE32QW6mvLtPC X-Received: by 2002:a05:6602:2bc1:: with SMTP id s1mr78152iov.140.1617636028015; Mon, 05 Apr 2021 08:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617636028; cv=none; d=google.com; s=arc-20160816; b=dQNjOD5rDBAZaVByqwoGGh1ZVxYPnTlnuB82SvGAMaVxwKchcP5iAuLSc75d5ZE6l7 hBIbpQbBAS3NQmBBU60nUXLNaFO7n7J0fj7CFB3zXmZ/vCJCFaFtrml9+jNMOeN3qH8t TRBn4mt+sUPj4sIPv7zgDKEz2GU5Rea4Z63xaJAq1XWzqB4EvaAa36GTADG5HKnnJCZ4 9pqXHETZZpgtJTBzbLlaZE0FQXL57QIUnpAfXLpLjfWLPP4U/MwCttmrNqE3qKAD1L1p BQykiBm4xc3LthCiz9IyhZd3I5F6//I4rhS8U2aVKEMAQnbalYgPK1cpSKZKTYkN4ILl Eccg== 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=AqSpz9UDwCccDBVTyg7DBVcmc1SBHLnEzZxbcfQ1/r0=; b=siaG6bew/HjHt2FngSXxA7MOIBgbNotTmxQVJ9m/KIcTUiGl3eDoR6cKX+D5WE8S9X Sh7C8aBWYz8M4PNgSTtVNZwId4W8FDHN/jhfMpahM7ZH44S+zyJQwKPMf7/2HEstanY9 hT3hfNOhHJeDL4pGl75MR3WRNMAjlTmex/iVDscT3wHuzwQ0elfj+na/dO6rCoUYH6hw dLAUo9Z0M+O4nnqDDUWI9xPGq+qm/3tls1sAxhkxD6LVoh1cALSKtSSoOFkcU5d6XNrA auCbhCz4TwLgIZq+dh2xzoyAWzQ0YL34bTe2BWSfe0hpbGyV3yyVCIKROBzMa0PhUq9C 1olQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gnvGsvwa; 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 s8si3254485ilu.144.2021.04.05.08.20.16; Mon, 05 Apr 2021 08:20:28 -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=gnvGsvwa; 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 S238035AbhDEJHT (ORCPT + 99 others); Mon, 5 Apr 2021 05:07:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:48612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237836AbhDEJFX (ORCPT ); Mon, 5 Apr 2021 05:05:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0FF38613A9; Mon, 5 Apr 2021 09:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617613516; bh=ogBNOLnzdqZhhc74vgJX+cTFHvEdTeKq9V92f9LWiSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gnvGsvwahJ9UQNc4pp9Pwj6v8KJdPkbxNZK7RAkZRSzDu4yS9kuAWqZxPQ4x0A1l8 Zb8jrrk+aMgduWksSNF0e6ouOw/wTf03u+bNIpHUkWK+anPXMsxRHPO4NpgK+V7pL5 dRoOvbtQXTKP+a8tj36YWTpITKAQnHqGeTbID3U4= 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 5.4 49/74] tracing: Fix stack trace event size Date: Mon, 5 Apr 2021 10:54:13 +0200 Message-Id: <20210405085026.331685598@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085024.703004126@linuxfoundation.org> References: <20210405085024.703004126@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 @@ -2857,7 +2857,8 @@ static void __ftrace_trace_stack(struct size = nr_entries * 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);