Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1688897pxu; Tue, 24 Nov 2020 06:42:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVkjoPuni2G8fNC/l9cZtGB8VRHpvVWnbSCLjVW2QRmyr8nxgTOBB4Q4WFIdSqnWW4aS5C X-Received: by 2002:a17:906:7f19:: with SMTP id d25mr4662894ejr.0.1606228937043; Tue, 24 Nov 2020 06:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606228937; cv=none; d=google.com; s=arc-20160816; b=Llt30cJMTyDRGjTIBmB5EY9c6bZoN+j1nvAk+a4ACFI484Z4zVwcH5dZKqk6fzsgXR G7bVc5gvJO2kCreSG+swPGWqtDIcKhUMH0OlZ3mIfm5FomVLs7ZEFSPhewNVYtJEPWTZ tIblknheDgwi+U7EUaqFCHGOu+zAr2Vxryo6HstebG8xIhhbJYzXUNbw5ieRKBIniRVG WGSEF5ZOTjHkyy74QXc2+/ruM3yfaSU4Fi1gZWLQtnboaD/Bup252VhynyDi6ToqP8Ka QYy6cndzsi1NYobt5MiBUeOtrXjdpbUY+gG01K5QFsGXbM9HiOMH2uPC5hMh/etKw37P HC+Q== 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=kymzfJ2oxkSUJR89/SsMrJNlPC5DR18c0lpdXSeyrFg=; b=Wvbx4va299U/2xk2Mmxpv6jZVa/2okylzTU5IMXN9wjInbPPHjQeZIdW2qCN22jQy8 bs9UyIV0PznTbx0velczhJADrPNpLx5Y0Jnny6vWbwjg3k3onduhwS/VkRVJKD9wt8mV s1g0n7HrnL5xtlBP6t1mX0LbyXRt5NOdZAxwMazJlery521lzktp1kGaXZqay+yJ/psh SAFbblBWzFX5COIa3L/f0qK0FHtg3wZLvaWGenV9ldfODXsXifQJ75Z1LX07vlkWBcO3 8V79/YCztWNYZ0BhU77Nwlyjx843xrCJdlkvHCCCuDyO83HsmlXGz33otPkRionVBr0B uqsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Kmaw05WW; 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 a21si8424149ejd.281.2020.11.24.06.41.37; Tue, 24 Nov 2020 06:42:17 -0800 (PST) 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=Kmaw05WW; 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 S2389159AbgKXOg4 (ORCPT + 99 others); Tue, 24 Nov 2020 09:36:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20740 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389142AbgKXOgz (ORCPT ); Tue, 24 Nov 2020 09:36:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606228613; 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=kymzfJ2oxkSUJR89/SsMrJNlPC5DR18c0lpdXSeyrFg=; b=Kmaw05WWBBAxWG2SgApsrmzr8QcSyCj0W7UezvAJuI0Ig/l4Hdq6pEpSDe/Fv+stmMoPD0 rlRwFpgWMLfe+WLgd/RNPK0ux7hA/SVUdhYSFl1A9K9DcmQFgPV2zRxY+Rcd7Z7sfe9CKV JbYuGNf41aGOo1Yan/mAyoXMyN1wAc8= 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-534-w6QARhs9OMa5dJfhMJ7fsQ-1; Tue, 24 Nov 2020 09:36:51 -0500 X-MC-Unique: w6QARhs9OMa5dJfhMJ7fsQ-1 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 E2A7A18B6140; Tue, 24 Nov 2020 14:36:48 +0000 (UTC) Received: from krava (unknown [10.40.193.173]) by smtp.corp.redhat.com (Postfix) with SMTP id A307619C44; Tue, 24 Nov 2020 14:36:46 +0000 (UTC) Date: Tue, 24 Nov 2020 15:36:45 +0100 From: Jiri Olsa To: Petr Malat Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Adrian Hunter , Kan Liang , Alexey Budankov Subject: Re: [PATCH v2 1/3] Revert "perf session: Fix decompression of PERF_RECORD_COMPRESSED records" Message-ID: <20201124143645.GD2088148@krava> References: <20201124095923.3683-1-oss@malat.biz> <20201124102919.15312-1-oss@malat.biz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201124102919.15312-1-oss@malat.biz> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 24, 2020 at 11:29:15AM +0100, Petr Malat wrote: > Both mmapped and compressed events can be split by the buffer boundary, > it doesn't make sense to handle them differently. hi, I'm going to need more than this, if there's a problem with current code please share more details, what's broken and how it shows thanks, jirka > > Fixes: bb1835a3b86c ("perf session: Fix decompression of PERF_RECORD_COMPRESSED records") > Fixes: 57fc032ad643 ("perf session: Avoid infinite loop when seeing invalid header.size") > Signed-off-by: Petr Malat > --- > tools/perf/util/session.c | 44 +++++++++++++++------------------------ > 1 file changed, 17 insertions(+), 27 deletions(-) > > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c > index 098080287c68..0d7a59c1aeb6 100644 > --- a/tools/perf/util/session.c > +++ b/tools/perf/util/session.c > @@ -2038,8 +2038,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session) > } > > static union perf_event * > -prefetch_event(char *buf, u64 head, size_t mmap_size, > - bool needs_swap, union perf_event *error) > +fetch_mmaped_event(struct perf_session *session, > + u64 head, size_t mmap_size, char *buf) > { > union perf_event *event; > > @@ -2051,32 +2051,20 @@ prefetch_event(char *buf, u64 head, size_t mmap_size, > return NULL; > > event = (union perf_event *)(buf + head); > - if (needs_swap) > - perf_event_header__bswap(&event->header); > - > - if (head + event->header.size <= mmap_size) > - return event; > > - /* We're not fetching the event so swap back again */ > - if (needs_swap) > + if (session->header.needs_swap) > perf_event_header__bswap(&event->header); > > - pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx:" > - " fuzzed or compressed perf.data?\n",__func__, head, event->header.size, mmap_size); > - > - return error; > -} > - > -static union perf_event * > -fetch_mmaped_event(u64 head, size_t mmap_size, char *buf, bool needs_swap) > -{ > - return prefetch_event(buf, head, mmap_size, needs_swap, ERR_PTR(-EINVAL)); > -} > + if (head + event->header.size > mmap_size) { > + /* We're not fetching the event so swap back again */ > + if (session->header.needs_swap) > + perf_event_header__bswap(&event->header); > + pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx: fuzzed perf.data?\n", > + __func__, head, event->header.size, mmap_size); > + return ERR_PTR(-EINVAL); > + } > > -static union perf_event * > -fetch_decomp_event(u64 head, size_t mmap_size, char *buf, bool needs_swap) > -{ > - return prefetch_event(buf, head, mmap_size, needs_swap, NULL); > + return event; > } > > static int __perf_session__process_decomp_events(struct perf_session *session) > @@ -2089,8 +2077,10 @@ static int __perf_session__process_decomp_events(struct perf_session *session) > return 0; > > while (decomp->head < decomp->size && !session_done()) { > - union perf_event *event = fetch_decomp_event(decomp->head, decomp->size, decomp->data, > - session->header.needs_swap); > + union perf_event *event = fetch_mmaped_event(session, decomp->head, decomp->size, decomp->data); > + > + if (IS_ERR(event)) > + return PTR_ERR(event); > > if (!event) > break; > @@ -2190,7 +2180,7 @@ reader__process_events(struct reader *rd, struct perf_session *session, > } > > more: > - event = fetch_mmaped_event(head, mmap_size, buf, session->header.needs_swap); > + event = fetch_mmaped_event(session, head, mmap_size, buf); > if (IS_ERR(event)) > return PTR_ERR(event); > > -- > 2.20.1 >