Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2636203pxj; Mon, 14 Jun 2021 03:40:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJvnT2sg05SeJ45n5imLBecJJL/NYgKsCklv08wsunc5c4ZUDIzHo+KkA1FVSQzHlvMBOF X-Received: by 2002:a05:6402:754:: with SMTP id p20mr15678898edy.311.1623667202642; Mon, 14 Jun 2021 03:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623667202; cv=none; d=google.com; s=arc-20160816; b=hXUCxNoI0LvyYNnQXzTCB1FEC+ICcrLYnp0Z5T6vnS04geF/gm8sbuBs1SFoyJj1R7 ux6si/PT8L/a7bBK/Zsdmg36Qfg+qm5TvHAfjblzyxfk/zvrOjojD1buo2OOgP5Jptln jJoZ0AsMMK17YZV+L2mEsXyp7YqgeeQD6nL3yTo7vVT2ZhsRWokzZN7iFmQQzI03ZX/g fJbJiegioEW93ujncF/Q+urOcbID7/KaI+82Hb8bCBnhOfmqwwCA843HlKOBS/BeRile OUChB2SfeUsQO4o6dT652oweFOtAq+djXoG/vTJifdwXxFOtDC2RwanP3ty1raqyuf/v 9fPQ== 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=HNxRlRxvJOEdbZzDPqRt8HzbH1j3udWG0LgKiiVwthQ=; b=z+UssnuSbG0ngDbYAs5ciDnh2U5LzB81MPpICWmoP4TU3OomVEw1ylJHqEJG58sEDA R8R5lrxf2zVXlOeUcMmCLLqLseB0aczKQS4BIZK0IiqWTgjG1aRjAvYr0NIf7uxevp+b jYAJk1cMGcW2ZTKxsTXPFcAk9F5ZdYifFAV8LKsftUGcoCzchxJ07CJREMe6FsH8H0g9 r9NgGBM9A9sYqfKx5fNIX5Yia29SjlPfpYA4VLIMAKcf/Y44esM8a6o3YI4ahjZqIjwO BaN2Pqp2jeAFwJIUi46PnHBTrbZUeRUN2T1rqQilDGmEc/C3PRR+AA75b6IaSZ3BdcLZ F5Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tyw01gGY; 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 e16si11355809ejl.322.2021.06.14.03.39.40; Mon, 14 Jun 2021 03:40:02 -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=tyw01gGY; 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 S233042AbhFNKhK (ORCPT + 99 others); Mon, 14 Jun 2021 06:37:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:39860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233196AbhFNKea (ORCPT ); Mon, 14 Jun 2021 06:34:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0FC861245; Mon, 14 Jun 2021 10:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623666715; bh=Orrf/8HQCxsdAsNoUTaVt4kXDOyRkH/lzRwD6tPRPYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tyw01gGYYlNs6lbpJhVHWgifLNUmhd4yrswikSYnUfteleo5vksvHGM0WltbxcCCH Ezs2Du3KUOoLTvCBfragfCR+PpZE+y9q4reTWC+pdP2JgaJsGNxuKYDyopeFYvGEb3 VkosC1xUzMuE6QYegc/p04xc6weFW+tCBl0e+Aac= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Adrian Hunter , Jiri Olsa , Alexander Shishkin , Kan Liang , Mark Rutland , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 36/42] perf session: Correct buffer copying when peeking events Date: Mon, 14 Jun 2021 12:27:27 +0200 Message-Id: <20210614102643.850989621@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102642.700712386@linuxfoundation.org> References: <20210614102642.700712386@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: Leo Yan [ Upstream commit 197eecb6ecae0b04bd694432f640ff75597fed9c ] When peeking an event, it has a short path and a long path. The short path uses the session pointer "one_mmap_addr" to directly fetch the event; and the long path needs to read out the event header and the following event data from file and fill into the buffer pointer passed through the argument "buf". The issue is in the long path that it copies the event header and event data into the same destination address which pointer "buf", this means the event header is overwritten. We are just lucky to run into the short path in most cases, so we don't hit the issue in the long path. This patch adds the offset "hdr_sz" to the pointer "buf" when copying the event data, so that it can reserve the event header which can be used properly by its caller. Fixes: 5a52f33adf02 ("perf session: Add perf_session__peek_event()") Signed-off-by: Leo Yan Acked-by: Adrian Hunter Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20210605052957.1070720-1-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/session.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 89808ab008ad..9187d8119a75 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1427,6 +1427,7 @@ int perf_session__peek_event(struct perf_session *session, off_t file_offset, if (event->header.size < hdr_sz || event->header.size > buf_sz) return -1; + buf += hdr_sz; rest = event->header.size - hdr_sz; if (readn(fd, buf, rest) != (ssize_t)rest) -- 2.30.2