Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1958610pxb; Sat, 2 Apr 2022 09:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf34aZYv0/mqQXaN6ZoUUdnanKAeZcUUXOBeAx9OaqpInOaNQ+prmdBbV6qsDnSF2ynT2i X-Received: by 2002:a17:907:a088:b0:6e4:dad7:1b1f with SMTP id hu8-20020a170907a08800b006e4dad71b1fmr4306472ejc.84.1648917415227; Sat, 02 Apr 2022 09:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648917415; cv=none; d=google.com; s=arc-20160816; b=LkrcMuJy0lOYArG8SiN/WOsQY9lrVuZgsePySaZUFiXsbZg9hh6B5+Om/m0ATdWHj/ xwGCB0wGUljCYa80ZsZQCTVDl/X2gmgjQNBODDDaWqAFJouQloGKMkF8+yLQNXWc8oFn ulVRp6IZYvT7oygauEKzYZch8YFU8aGnjgsozG48eAe+nB3Y+hbmOOxSa9InXP6E5R4n l+qN98rcRcCorgII20S3nOJZWNp0E6b4PvldBkxTzOuNV7Bq3CosKfLII6fPVLDuNwF6 zFw9A7Evz+S827xIH06VQqYXv1pX+1tsikE36r2CLjpipvt019YCO7r98VJYF9NBvoSc 2Yyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=w92NLA3TMQsYKuR9CXX+L2Tvsy/pumxbCD/vKiNzt/8=; b=EKrd5XI0EBbyqP2dsDEBXXswCoKHrI3Yqq/r+g+7Qm2uUp2gF/EEmiCoOm4Mbggxij laEB72wRdhiYV3vMiWsR2ugKN6mkGmCoJOTUTQI1IaKFo7WERDQSJlyPWTwGBAPSxbIq o2nQAp5e66j1SbmGrFNzwbepUpK5HsTP3IbWOKQi/fgfatvB1f+SR8JODicbVaR3HPIy IIN82EZZW1XPrDtYA0N3HJw7RNQCJtpxOaCogSWI5GefsEERtWrbhWjoW1BeDRCOvbY7 r2mDVeMRr0A7ru6OhDl/ivPggL+Y9CQ6M5Jja/hefKceINInn+9P+vJM4zNA23o1J4Wz gxMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RrGd6fDL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a50ee05000000b00418d7a0dc0esi3699559eds.376.2022.04.02.09.36.30; Sat, 02 Apr 2022 09:36:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RrGd6fDL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245138AbiDAFt2 (ORCPT + 99 others); Fri, 1 Apr 2022 01:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238796AbiDAFtZ (ORCPT ); Fri, 1 Apr 2022 01:49:25 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EBD248792 for ; Thu, 31 Mar 2022 22:47:36 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id u26so1647681eda.12 for ; Thu, 31 Mar 2022 22:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=w92NLA3TMQsYKuR9CXX+L2Tvsy/pumxbCD/vKiNzt/8=; b=RrGd6fDL+BlZgiJiYDlk1afYMuo/wxX5kFOVTYynem0oxFMrwjZb3hB7Bju7pz0WJ5 CqSl/I+qy0nKeqMCA+hHT115kgVy6EaTH1nxCOluYxe1hWv67AuVlYeTVsp1sMM3VP9z tscXTUtG3PR+1Ts022kRGQCECRCRU8bq2GazE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w92NLA3TMQsYKuR9CXX+L2Tvsy/pumxbCD/vKiNzt/8=; b=VB2Kl/s5kCqU6RI6RiJPzIpWn09CeF2kW4zl8fECBF1xv2oDLyentsYZlfgQIx2YSY /sGPLgCEx5SRctqCC0mcxtOcZQkkqVqJ9NEpVEnqN+9pVSo/m/kAhJGJx58UfQ2xnMFe i008Wv8omaibsA5lfX1w56BdnqysiuArkaLyNCirrijoHOMfcw0/4MXfL9XdNCHL7bCt ALarPR8oD2GX4+dqFvDn5WnV8eEBa0g0CSqd2PEArQUbGJizbF5mv+JE08TRG4dj0ot4 Uhjzpc+mYAo2cpOnur25Imq9S25G5tQ4iT5S4mZKUSNMsaCuG80P9gYD+/MlterHZb6Z nM8A== X-Gm-Message-State: AOAM532/05WNHk3YntPfZnhpJFukLWCjfChpTM/FOGa5kDMbpqGTleKe 1K5AxtcfdCWXSbJPy7+y7guHElyiTc3tkPeCiMUjVn/oCeQ= X-Received: by 2002:a05:6402:350b:b0:419:1c11:23ed with SMTP id b11-20020a056402350b00b004191c1123edmr19717204edd.8.1648792055453; Thu, 31 Mar 2022 22:47:35 -0700 (PDT) MIME-Version: 1.0 References: <20220330031130.2152327-1-denik@chromium.org> <77fa14e8-6630-c0e9-21fc-2603f7383f5f@arm.com> In-Reply-To: <77fa14e8-6630-c0e9-21fc-2603f7383f5f@arm.com> From: Denis Nikitin Date: Thu, 31 Mar 2022 22:47:24 -0700 Message-ID: Subject: Re: [PATCH] perf session: Remap buf if there is no space for event To: James Clark Cc: acme@kernel.org, linux-perf-users@vger.kernel.org, jolsa@kernel.org, alexey.budankov@linux.intel.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi James, Thanks for your review. On Thu, Mar 31, 2022 at 7:20 AM James Clark wrote: > > > > On 30/03/2022 04:11, Denis Nikitin wrote: > > If a perf event doesn't fit into remaining buffer space return NULL to > > remap buf and fetch the event again. > > Keep the logic to error out on inadequate input from fuzzing. > > > > This fixes perf failing on ChromeOS (with 32b userspace): > > > > $ perf report -v -i perf.data > > ... > > prefetch_event: head=0x1fffff8 event->header_size=0x30, mmap_size=0x2000000: fuzzed or compressed perf.data? > > Error: > > failed to process sample > > > > Fixes: 57fc032ad643 ("perf session: Avoid infinite loop when seeing invalid header.size") > > Signed-off-by: Denis Nikitin > > Hi Denis, > > I tested this and it does fix the issue with a 32bit build. One concern is that the calculation to > see if it will fit in the next map is dependent on the implementation of reader__mmap(). I think it > would be possible for that to change slightly and then you could still get an infinite loop. > > But I can't really see a better way to do it, and it's unlikely for reader__mmap() to be modified > to map data in a way to waste part of the buffer so it's probably fine. > > Maybe you could extract a function to calculate where the new offset would be in the buffer and share > it between here and reader__mmap(). That would also make it more obvious what the 'head % page_size' > bit is for. Good point. I will send a separate patch to handle this. Thanks, Denis > > Either way: > > Reviewed-by: James Clark >