Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3492380pxf; Mon, 29 Mar 2021 03:54:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyePr5FCdSPvaR1kJZy5+aLiAyh/CLbEWYV0ST41O3aRZul5p/OZlW4r0IET5rpecTOjEW1 X-Received: by 2002:a05:6402:3486:: with SMTP id v6mr27728651edc.109.1617015288753; Mon, 29 Mar 2021 03:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617015288; cv=none; d=google.com; s=arc-20160816; b=0ZmPokVSgRs4iAqpEN9vu3GqFFxUfRdgYtHeWvgTmk0a7sVXFX26AQEzmUEyLClIgU ELJEUcBQjYCntx4a4nmQe1Gkn0JgRo+wxmUu0ObBPGcW6Sc7tsvy3eBqLxPu70Q0HeMa FIi8MNqSiVM3FG+/rY5IduGstuNmyLaEsj4bahDK8vHk1AB+G/VO36ZhBlkMI3cyY6UM dTPR1+31szrCgMJdfPw8/+hRQtK1whunwSG88aIK9+jMcK7E0/GSwIr08PE01nJV6UPa J50ARwm0CUjN165Qh/l+8QsN9cSW1R2aRMK2Vgcl5PJ03N5shD3Me/fzW0doPd9wOjsJ UUDg== 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=b7KUk7+gFOqjHqalgaoLb+aP9zVq6zAyG2cUQ/oOSV8=; b=nFYuJ1gtth/94HufKA60Xz523JIwY87Sh9w0bIp3HAO4hMTnkLg0xWyLFOeQsZpkpc t2WG1eEmRzOkUd1HYiqqQ5Aur/rCxTJaMjU+d1KUcJgcA6SzqTMLrwFiYuG56BGqJ/fw pEj+bU0tE3XeCNdWTO7WqZrMfnMMSw+8xmfmWgCA58ceebzUFulNgQos6IHb8TTzFwbV O++zGtEylmDQN5Y+BzK6hiEI+WI0vfHvZ2m4mTcvWSQd/Wa38nmkCscMI+UtO7BQwzX0 1C/XlsoBeMtSSXSE8AQJxNL9HTqO8rovDrg7DUHVC3gpVbHBuGKS952qq7AP/U1UXU9r d6CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1377hEZS; 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 a18si13614353ejr.606.2021.03.29.03.54.26; Mon, 29 Mar 2021 03:54:48 -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=1377hEZS; 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 S235101AbhC2In6 (ORCPT + 99 others); Mon, 29 Mar 2021 04:43:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:42680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233546AbhC2IZ4 (ORCPT ); Mon, 29 Mar 2021 04:25:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26648614A7; Mon, 29 Mar 2021 08:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006323; bh=zb6U6309W+wIdgkhmMqWm87hvVyw6zYof3eZim7Rrw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1377hEZSRBu3xysI5bg8kfEm5i4Mw1AUyoUpjaS1xwdCCiDNq8t0zKg8o+r/K3mDG qe6MoWDwpFQXD7en2pU+V1VtOM7u9wFgSxzP89s6m7yakItdfMvlyCFZ6jQtQ9LL7X 8QUFOKVoCisIhxbqaX4rXg1FxYD/5JBarj3kW8kY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Jiri Olsa , Ingo Molnar , Alexander Shishkin , Mark Rutland , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 199/221] perf synthetic events: Avoid write of uninitialized memory when generating PERF_RECORD_MMAP* records Date: Mon, 29 Mar 2021 09:58:50 +0200 Message-Id: <20210329075635.762121600@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@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: Ian Rogers [ Upstream commit 2a76f6de07906f0bb5f2a13fb02845db1695cc29 ] Account for alignment bytes in the zero-ing memset. Fixes: 1a853e36871b533c ("perf record: Allow specifying a pid to record") Signed-off-by: Ian Rogers Acked-by: Jiri Olsa Cc: Ingo Molnar Cc: Alexander Shishkin Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20210309234945.419254-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/synthetic-events.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index d9c624377da7..b4cf6dd57dd6 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -384,7 +384,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, while (!io.eof) { static const char anonstr[] = "//anon"; - size_t size; + size_t size, aligned_size; /* ensure null termination since stack will be reused. */ event->mmap2.filename[0] = '\0'; @@ -444,11 +444,12 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool, } size = strlen(event->mmap2.filename) + 1; - size = PERF_ALIGN(size, sizeof(u64)); + aligned_size = PERF_ALIGN(size, sizeof(u64)); event->mmap2.len -= event->mmap.start; event->mmap2.header.size = (sizeof(event->mmap2) - - (sizeof(event->mmap2.filename) - size)); - memset(event->mmap2.filename + size, 0, machine->id_hdr_size); + (sizeof(event->mmap2.filename) - aligned_size)); + memset(event->mmap2.filename + size, 0, machine->id_hdr_size + + (aligned_size - size)); event->mmap2.header.size += machine->id_hdr_size; event->mmap2.pid = tgid; event->mmap2.tid = pid; -- 2.30.1