Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2765318ybc; Mon, 18 Nov 2019 04:24:10 -0800 (PST) X-Google-Smtp-Source: APXvYqyhV142kKTs9Oy9HxYkynNIkV1r/29QPVJhU/2xB7R/Rr2UVt222+QKAvRNVi6Oc3BeUVbK X-Received: by 2002:a5d:448f:: with SMTP id j15mr5025312wrq.70.1574079850006; Mon, 18 Nov 2019 04:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574079849; cv=none; d=google.com; s=arc-20160816; b=a5M5mcn2rbDXH9b8RKm9FVnLxVOe9tiBgy8ohFuH917Jx1b0yX4W0be7VNksppH+K6 V1RC0QrGXt4Ey6xYWmGUqYBfFrNauTEA1MSh49mETGhG4HfG/SqLM+PS8mXCVs9F6oKQ sGi+cS7js2OHoGcf4v1bis5ntwyBVWQBW6Uf1LB2/JZ67xxaRMMZU6nCekCzCQBKP6Dp UW55p07MfFnfvzrRi1CRBf6f/gEWcdsa0JeE67xiC01Q/tioHEyEhTAEWt2xC4M0G5r1 behl2nBaQDyf4fe1t/O+INWyppI2AJsdbzM6L5fnfNUgmrCnnpetgaIE4Tze5GIdkpKz lpOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=h0NoYJqekTI3Qnjh2uoxpfc3n3uRw7aVsaWansrk0nM=; b=lrjw7uyW68HLsj2VGIfvsB/JUX/FjgD/iQP92dwyUgNqlDnkcmncTUfb8OsVHmM7ri lINGU9uyY6T+Qs3Ai2rCHMEBj3aCcoLsn86wyVV9LZ/4DIoVTVZfGaKBfwhWoul/jGmd GeBMjIxODNXdxxfPzzRhkf1humqdOrBfyn1sDTaaeWZxQAtGjFlxP7zRwjmWqq6iOMLL ZyPoo+Zqqwr39TKt8f2P0JhT0AHDrK4eloppFg2j4vA2xCj1G5ZR+LcYKy+jHdraU3QW 7LBfFjn2uyPmJVF9QBJSpq7FrYKVTtPt4gafiRto5RNx7IDYrSiUA/FvnrWJqxd+AJV6 aKPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G5V9I6dt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id x28si15648128edl.21.2019.11.18.04.23.46; Mon, 18 Nov 2019 04:24:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G5V9I6dt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726686AbfKRMWW (ORCPT + 99 others); Mon, 18 Nov 2019 07:22:22 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46859 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726464AbfKRMWW (ORCPT ); Mon, 18 Nov 2019 07:22:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574079741; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h0NoYJqekTI3Qnjh2uoxpfc3n3uRw7aVsaWansrk0nM=; b=G5V9I6dtdu/aPo4sYY0TydiuiQ8tTJeYtR/7jAjLJ93AiKxYjYAJljePDEYDLxzN5vqH4W 0kX45AHIY6vwlUNzi5UxOLw6tSd/A/WtbZ748H2WIZH5LcwGbBUiRBprwX1oZjCwx+Bp5H HPCdvrQsXMxhnuAK9k5W4sAN79nH7VU= 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-182-I0ynNsuQOn6w1bTaEdDk5Q-1; Mon, 18 Nov 2019 07:22:18 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1F861883521; Mon, 18 Nov 2019 12:22:16 +0000 (UTC) Received: from krava (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with SMTP id 1442219C6A; Mon, 18 Nov 2019 12:22:14 +0000 (UTC) Date: Mon, 18 Nov 2019 13:22:14 +0100 From: Jiri Olsa To: Alexey Budankov Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel Subject: Re: [PATCH v2] perf session: fix decompression of PERF_RECORD_COMPRESSED records Message-ID: <20191118122214.GB14046@krava> References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: I0ynNsuQOn6w1bTaEdDk5Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 18, 2019 at 02:30:04PM +0300, Alexey Budankov wrote: >=20 > Avoid termination of trace loading in case the last record in > the decompressed buffer partly resides in the following > mmaped PERF_RECORD_COMPRESSED record. In this case NULL value > returned by fetch_mmaped_event() means to proceed to the next > mmaped record then decompress it and load compressed events. >=20 > The issue can be reproduced like this: >=20 > $ perf record -z -- some_long_running_workload > $ perf report --stdio -vv > decomp (B): 44519 to 163000 > decomp (B): 48119 to 174800 > decomp (B): 65527 to 131072 > fetch_mmaped_event: head=3D0x1ffe0 event->header_size=3D0x28, mmap_size= =3D0x20000: fuzzed perf.data? > Error: > failed to process sample > ... >=20 > Testing: > 71: Zstd perf.data compression/decompression : Ok >=20 > Fixes: 57fc032ad643 ("perf session: Avoid infinite loop when seeing inval= id header.size") > Link: https://marc.info/?l=3Dlinux-kernel&m=3D156580812427554&w=3D2 > Co-developed-by: Jiri Olsa > Signed-off-by: Alexey Budankov > --- > Changes in v2: > - avoided static declaration of prefetch_event(); > - renamed 'ret' to 'error' for returning in case of split compressed=20 > or overlapping records; > - passed only needs_swap quality into fetch_*_event() instead of=20 > the whole session object; > --- > tools/perf/util/session.c | 44 ++++++++++++++++++++++++--------------- > 1 file changed, 27 insertions(+), 17 deletions(-) >=20 > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index f07b8ecb91bc..c2b0703d6587 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -1958,8 +1958,8 @@ static int __perf_session__process_pipe_events(stru= ct perf_session *session) > } > =20 > static union perf_event * > -fetch_mmaped_event(struct perf_session *session, > -=09=09 u64 head, size_t mmap_size, char *buf) > +prefetch_event(char *buf, u64 head, size_t mmap_size, > +=09 bool needs_swap, union perf_event *error) > { > =09union perf_event *event; > =20 > @@ -1971,20 +1971,32 @@ fetch_mmaped_event(struct perf_session *session, > =09=09return NULL; > =20 > =09event =3D (union perf_event *)(buf + head); > +=09if (needs_swap) > +=09=09perf_event_header__bswap(&event->header); > =20 > -=09if (session->header.needs_swap) > +=09if (head + event->header.size <=3D mmap_size) > +=09=09return event; > + > +=09/* We're not fetching the event so swap back again */ > +=09if (needs_swap) > =09=09perf_event_header__bswap(&event->header); > =20 > -=09if (head + event->header.size > mmap_size) { > -=09=09/* We're not fetching the event so swap back again */ > -=09=09if (session->header.needs_swap) > -=09=09=09perf_event_header__bswap(&event->header); > -=09=09pr_debug("%s: head=3D%#" PRIx64 " event->header_size=3D%#x, mmap_s= ize=3D%#zx: fuzzed perf.data?\n", > -=09=09=09 __func__, head, event->header.size, mmap_size); > -=09=09return ERR_PTR(-EINVAL); > -=09} > +=09pr_debug("%s: head=3D%#" PRIx64 " event->header_size=3D%#x, mmap_size= =3D%#zx\n", > +=09=09__func__, head, event->header.size, mmap_size); you're missign the 'fuzzed perf.data?' in here I think we should keep it just change to: 'fuzzed or compressed perf.data?' thanks, jirka