From patchwork Mon Jun 14 10:28:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 459819 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp3179870jae; Mon, 14 Jun 2021 04:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPwWrY5wOcWg5lBzL2XR8der94p3FmXzifRSjYZWyXOLd+ez1SwDandWpq3XsWrVZSf1H6 X-Received: by 2002:a17:906:2bcc:: with SMTP id n12mr14157968ejg.430.1623668983121; Mon, 14 Jun 2021 04:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668983; cv=none; d=google.com; s=arc-20160816; b=gWbIhLdtpJwSkpQ5hPphxIctMUQmFwKaq9gO2YGZgYF2jxdOpw7RClNORmk5wRvgZx Cr4XWJiFztNMxyJ0kGZhm1jtLXnbtIE3qCNZ4IGtMYtH+Non28yVHG4IeyoQ4bqdy966 CJz6IqxeAX7LTpMAFUmOc1KalMrE6a2Pavp/wkle0Ak0kKLobPbjKiBu+GwjI987gayl XkENv1htBVEP6Tz8MRj/UhHzpY64ylCdf+XZiAybGQkROq8zqXGVaXtu0u2cnNclemcY ftyJvntZmCekOe54aq2WMyiY1wsOqqKzQax5doB6zZ7Pp9u+91gl/SgFZr73lT1WhazH iQGg== 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=ImFiUorPRIQtDM4GXKUKCCONKHUQ0rwK0d6N95nmUho=; b=EXkhephqbAAhQTQ6kR21j4cZv7lSMEaDOlHA5o4OKBoli9Xt5FgfkqoVg7dnQV2vj0 RvFEq1ex72FzvMBs/jeL7ffHMQlqPpU3uZZAKDO5QSfIyWBAQfCiEK4EE0NVGZHwiN7B MOJvaOQDnsNgjxgCuzbJ1Ve0oIoClULe/q7LzbsbSPBHOTSqXvklsHy6EJNpREfMrG+T Xmd251M4Bmbv2RNXMa7puM72+JpR+Anw3UjqVdj+xQhroJu208goYNIiXmDozCemiwnf HvAjQO6fYZ0TM5vX81MYqG905w0TECPm4ekZyAeB3pInYeO2yW6RbbCsprbULINhHMZ+ 4sKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LOIQZCPm; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 y4si574263edc.212.2021.06.14.04.09.42; Mon, 14 Jun 2021 04:09:43 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=LOIQZCPm; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S234401AbhFNLLc (ORCPT + 12 others); Mon, 14 Jun 2021 07:11:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:39540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234235AbhFNLHx (ORCPT ); Mon, 14 Jun 2021 07:07:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3437E6143B; Mon, 14 Jun 2021 10:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667569; bh=EQ6y0pZz4laLx9qhCPoyfofPdJvZrEAeH1YaFEmb3rA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LOIQZCPm8gRkv14QcyKL48IeERp/oic9AI4WCvh7MvqH6UR3EjWdmP4419ZE+JBf3 E2JIUtNmmD7hoIrvLpaDcceKPz1tHSeo0KPWX/6mvO+4MWDxtrqbWo0o0ujfiENULH JxTtRqDF3k14/9OGCI/QnqhX+eURvv46rKkHltqI= 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 5.10 122/131] perf session: Correct buffer copying when peeking events Date: Mon, 14 Jun 2021 12:28:03 +0200 Message-Id: <20210614102657.164247593@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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(+) -- 2.30.2 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 63b619084b34..9dddec19a494 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1699,6 +1699,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)