Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4067114pxj; Tue, 8 Jun 2021 05:50:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye8Fb1GqM7U3h9NBpy99X9uyx6DwspilLxbMAwcNDS1R1uvjEw9PJwD0L0NbJ3DcIooDWG X-Received: by 2002:a17:906:c791:: with SMTP id cw17mr22447229ejb.329.1623156633971; Tue, 08 Jun 2021 05:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623156633; cv=none; d=google.com; s=arc-20160816; b=h87l78en89U3PCuIfZc5FA5fTWmo87OfvwzQwG43eyHcTOChcWI+oaetyEGH+IeaKv BNuxU6kVmmdyhh65F92cw186cqvipS4t2jVN0opnZEp4Ay6HULSo9D4BNoGjIVj2WD5I zMPYtjvXXFP1jxqIomUjJsac89Z5buklFYvhIY4GZV2ofX73U24ynrv9hEtXvrPw/Niq SfhM0ZO6pj9tVC4BoJ1+YQ50i15yC38wqDUahlOoQ4luGrhPl8I1NwapIkao9xVDcSSK kneFlLfEVRWqZj2lIxMlCKBDSZ3b3WjQww3hFC2gxYd1IO/oZPPsrl8wSF+n+3aY6J2n HIlA== 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=NWeamr4yc1hOYElPykon+wAggarhe1Aov6qPsT30rpE=; b=PpBSsswAPPW0ile5EvtlG2tja4vuP3he8pIu+LSbBg14gux8AWHFZ/Pe5e2wMEfSrg stmT4eDQom4nCakunevcNJJ+vLuUlkfJ5e3seXiwa0X3QoZU5cWzRqYHRM8/6EGROkaQ TXedxMsDBIu72ymRA3YfdztqmrA1+r6nwxy6YjW2LFjbF7yK/8H8bFjV9A+VAp2cA7af mWBzQWbujFSzBBtrSGmYlWC0OHTtw/25pQxbkfvG4YrmUAm2PeTjJfWvDy9WtGQh5sk2 S2TJVY/S6AhHcA5j5QSu/457ckMEgmNB/t029l8ZgdeUzM0RXmHUKymm6NJDSgilcwPT fxew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VInSooZk; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl25si14696397ejc.370.2021.06.08.05.50.10; Tue, 08 Jun 2021 05:50:33 -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=@kernel.org header.s=k20201202 header.b=VInSooZk; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232531AbhFHMtu (ORCPT + 99 others); Tue, 8 Jun 2021 08:49:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:46306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232316AbhFHMtt (ORCPT ); Tue, 8 Jun 2021 08:49:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7442960FF4; Tue, 8 Jun 2021 12:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623156476; bh=bhSgOLiDaEHajTgk+K80fedzHbAhBAikOd+huyUSHo8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VInSooZkuCYeNrnAy/G28Rf+6q0RLHFNM3lDBXvcrRORxIMotGAnJ6DvP2e+L+zoj aFv0wwecRoBSwJHpgQmHzR6MhXuVaWMErQAYoOw5/DsIn++o0LGruYt/BoaJjF8BoD ptvC0+250JeHcoB6Zto5FHEwHfSQRPC1eTF0rmvcs9sViVTsOXXKdihmZ6wcaniXHN lrkP4RX+Rc8eweJoCyGHfZ7HiSxYC6vIU9d+Ut0CK9QeUaTr8BcrNyNR8Cs/U7AE0G web3VHcQePWc/l9Jf79+/jK63JTtQd2P9YMzalzYrJAC51g2kTfKSQZKivnI9fbcXv juMIvvnesdkew== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 4623640B1A; Tue, 8 Jun 2021 09:47:54 -0300 (-03) Date: Tue, 8 Jun 2021 09:47:54 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: Leo Yan , 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: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Tue, Jun 08, 2021 at 01:07:22PM +0200, Jiri Olsa escreveu: > 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, applied. - Arnaldo