Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4552763pxj; Tue, 8 Jun 2021 17:47:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2GlOXc0P6ZM1NnhcBgWjPkEGYhrxj0G46nDbhVUZ7LaKg22/gW25BsIlULZOgY4SOlQil X-Received: by 2002:a17:906:b317:: with SMTP id n23mr26558965ejz.324.1623199674399; Tue, 08 Jun 2021 17:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623199674; cv=none; d=google.com; s=arc-20160816; b=gUy7nqPtO6ov0K0vRQPyJJYxEXxzt0gJk7uqRgRRbbtPUwhEdPUqJb5V3QlpOu0qL2 8Mi2I/syizNyegqdF+Ydzp8Yy5RBI2RCYBgJTBKbYlX6VTA21N/emmU/Ww0sUXxnhRdo dKdAmXZm+SvRg5qOoOtg8gs0MCoDwYA2AZtNf7AyA6GAHvAGMQXfHRQNmiIKCi5cYEj0 QI4CWh3fiw+NWtj85zvSVOT1JSsvyMZ0uVvfOSdJ57DHx/kxa+nevmu4j1OOmbabRetD EmteIca3RjXYY/7NHHs00QaX49jDsMl/sdXRqQgw+xqNjq6oTBxTDBurQzB2KOg+HoV2 6VnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=C/2xphIxQp4/un0lu+bFhC87YLSeVemPdQfQPjhC7ag=; b=p7mYzMSLCH7fXuLQUn4Dj+yXuyexZQD6xbj01XDFdxKowdWIcggkXP6NLQoQSL6q0f CGNYbLFCTDUZHt3ooPJ3QgCxAR5KEM+0s65npzaH4OCpTFUtO5lkUc5WuqM7l7xycxKz gnkLX1XWtaUzGPjX17E7db0Rbn5N/vNb+Xpazt/n89tKF6udLt975chsBkmfc+XdtYZu bkS4xjdSKuhbXEnr/lkS94WveT2rWCe+NwBpyOyUr1CwfYwMWcMUVNqz3nt/3kIhFfvY lUNFGV2HRE6dJ7PJc+jKfrrE/2102CIbxAcSuEHICsLT0FgmG6rmLRk6nGi/zSaReCT2 uzAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bp7aniu8; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs19si1120496ejb.398.2021.06.08.17.47.30; Tue, 08 Jun 2021 17:47:54 -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=@redhat.com header.s=mimecast20190719 header.b=Bp7aniu8; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231668AbhFHLJY (ORCPT + 99 others); Tue, 8 Jun 2021 07:09:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24270 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbhFHLJX (ORCPT ); Tue, 8 Jun 2021 07:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623150450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=C/2xphIxQp4/un0lu+bFhC87YLSeVemPdQfQPjhC7ag=; b=Bp7aniu8g9LLtP/OwpjtK+9cKyb7t53xoJUEChnA98zqbNuofS3YP6aSrleyA7O0P/yEcb bNE1yTQzhd05Mo/KYFTYia1euP/LTgGC1EoYApJvWJH3dfcqJDxL4PIt1163IS/Lp5xP98 0uIrqqHq47wUL6gBfY6JU5uTr3SPXyk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-465-qEYoR3SQNWqy_jecAN9K9A-1; Tue, 08 Jun 2021 07:07:27 -0400 X-MC-Unique: qEYoR3SQNWqy_jecAN9K9A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DAD1F101371D; Tue, 8 Jun 2021 11:07:25 +0000 (UTC) Received: from krava (unknown [10.40.195.112]) by smtp.corp.redhat.com (Postfix) with SMTP id 91817620DE; Tue, 8 Jun 2021 11:07:23 +0000 (UTC) Date: Tue, 8 Jun 2021 13:07:22 +0200 From: Jiri Olsa To: Leo Yan Cc: Arnaldo Carvalho de Melo , Adrian Hunter , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Namhyung Kim , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf session: Correct buffer copying when peek event Message-ID: References: <20210605052957.1070720-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210605052957.1070720-1-leo.yan@linaro.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 05, 2021 at 01:29:57PM +0800, Leo Yan wrote: > When peek an event, it has a short path and a long path. The short path > uses the session pointer "one_mmap_addr" to directly fetch event; and > the long path needs to read out the event header and the followed 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 > --- > 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 106b3d60881a..e59242c361ce 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -1723,6 +1723,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; nice ;-) Acked-by: Jiri Olsa thanks, jirka > rest = event->header.size - hdr_sz; > > if (readn(fd, buf, rest) != (ssize_t)rest) > -- > 2.25.1 >