From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D964BC433EF for ; Wed, 8 Dec 2021 21:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r3GfBW5tScXRGl2zCy7F6v77RszLcWpyczAVbTeFcX4=; b=OeAf84ZlDUFkI+ aF3z1j/XkqmBFnQR1PRHiJPc88bkD6RrHIQ16leg0vNabWgcPGjaty/lhXDb7hK4N4TtkvhLPbcO4 JMVHYl7jD+KBW9nP4z85PqcbFkKCyLpgIp9SS6rWNneMEkd8NuJGR+V5Rxo6SsR6vt3q9Hf//Tas0 J4TehQlQ8LpF1yBhK1VQDyVktnE5FV5LQ8WoExGiHwedwAGRWo2+y6oW26VXIK1rMgKUQ5UXWMGOp ypHMCTARb+8GVQ1PzqB1JwgsSkDHu/ce64UibdoGLaBCDxaZyEtHiYBr6rjimstdwjjXyUDScbo8l ZSDcgdF/b7R/HnSPl43w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mv4as-00EGfI-GZ; Wed, 08 Dec 2021 21:35:18 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mv4ao-00EGeI-Ox for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 21:35:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638999313; 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=CeXKyb655iDPT4A+Z5xrV0y1RP5TDI3g9ay8C+HT3HE=; b=ZH90dDGKKfNfoBxmMmT0Mv1ko1iMEp/wbKwbbtnS5zMOQn8Xn9LDyyqIielXGd1axcW5Kr RWQ8GJjIr9PD2ZLBsuNNvklscHjw8F+ygZ50DgtIwmAF4priVyL7lG3IczI8GPAf+14Bl6 p7d4mjYlBTPc2qI2oPlvKIQO18JXjlI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-sn6UHnTBPQueHVhoEky1MQ-1; Wed, 08 Dec 2021 16:35:12 -0500 X-MC-Unique: sn6UHnTBPQueHVhoEky1MQ-1 Received: by mail-wm1-f70.google.com with SMTP id g80-20020a1c2053000000b003331a764709so3700529wmg.2 for ; Wed, 08 Dec 2021 13:35:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CeXKyb655iDPT4A+Z5xrV0y1RP5TDI3g9ay8C+HT3HE=; b=hH6Cv3XpceDXRndwdWD2PelrnlJlsbnvzFTPZDyVhFf6C/hcZn7jAd2lzqYz2DqVLY FgmVibTmg/IhISSS9oUqHOoHlsYmo5XE5UUk6KDsLNWP/KF2hI+hXGjLF2KMVNvU0IK/ n8j/nEZqQXcaR0XHZxq2HBAeVzbbzNAem1dET8R/h9GnZJMjcal3gK22svNLkarkPFni scqKZaQf0VQe9TBciXlzDAtzz1fL499grkVLwHgxfy88BrFQr23lqYH1g1Tj+fFvxQGN TgiGfvRCgomk/Pw6y0eRr59S9Mr/pTA9v137J5LDpYc+d6MmaFjj5BUCrwREwYfUObzW g9EA== X-Gm-Message-State: AOAM5308cMR88MGQPoMArjH5PZZeaZKDdCdTVwU2g6eLF+270ipC9eoB IzEK+dSVPoqioHAh0Nys777VHV3mQ9jStCUEIdiG/lpaWGj0SgohIXZ/mfuK3KlbGpZlAPWmAOW K0InNB4JmUrk5GFMX8GmJqsCtItDgafFfkxg= X-Received: by 2002:adf:e391:: with SMTP id e17mr1405890wrm.613.1638999311138; Wed, 08 Dec 2021 13:35:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJx56PDcQ9x4W4KPUCMLY+uuyJihSBiRNIwzduX5rQ30E/1Tn92gPDE60lBy2g7CxuCj7cySQA== X-Received: by 2002:adf:e391:: with SMTP id e17mr1405757wrm.613.1638999309893; Wed, 08 Dec 2021 13:35:09 -0800 (PST) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id b6sm7152187wmq.45.2021.12.08.13.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 13:35:09 -0800 (PST) Date: Wed, 8 Dec 2021 22:35:07 +0100 From: Jiri Olsa To: German Gomez Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org, John Garry , Will Deacon , Mathieu Poirier , Leo Yan , Mark Rutland , Alexander Shishkin , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v1 1/4] perf tools: Prevent out-of-bounds access to registers Message-ID: References: <20211201123334.679131-1-german.gomez@arm.com> <20211201123334.679131-2-german.gomez@arm.com> MIME-Version: 1.0 In-Reply-To: <20211201123334.679131-2-german.gomez@arm.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211208_133514_917473_C3ABB053 X-CRM114-Status: GOOD ( 24.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Dec 01, 2021 at 12:33:29PM +0000, German Gomez wrote: > The size of the cache of register values is arch-dependant > (PERF_REGS_MAX). This has the potential of causing an out-of-bounds > access in the function "perf_reg_value" if the local architecture > contains less registers than the one the perf.data file was recorded on. > > Since the maximum number of registers is bound by the bitmask "u64 > cache_mask", and the size of the cache when running under x86 systems is > 64 already, fix the size to 64 and add a range-check to the function > "perf_reg_value" to prevent out-of-bounds access. > > Signed-off-by: German Gomez Acked-by: Jiri Olsa thanks, jirka > --- > tools/perf/util/event.h | 5 ++++- > tools/perf/util/perf_regs.c | 3 +++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h > index 95ffed663..c59331eea 100644 > --- a/tools/perf/util/event.h > +++ b/tools/perf/util/event.h > @@ -44,13 +44,16 @@ struct perf_event_attr; > /* perf sample has 16 bits size limit */ > #define PERF_SAMPLE_MAX_SIZE (1 << 16) > > +/* number of register is bound by the number of bits in regs_dump::mask (64) */ > +#define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64)) > + > struct regs_dump { > u64 abi; > u64 mask; > u64 *regs; > > /* Cached values/mask filled by first register access. */ > - u64 cache_regs[PERF_REGS_MAX]; > + u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE]; > u64 cache_mask; > }; > > diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c > index 5ee47ae15..06a7461ba 100644 > --- a/tools/perf/util/perf_regs.c > +++ b/tools/perf/util/perf_regs.c > @@ -25,6 +25,9 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id) > int i, idx = 0; > u64 mask = regs->mask; > > + if ((u64)id >= PERF_SAMPLE_REGS_CACHE_SIZE) > + return -EINVAL; > + > if (regs->cache_mask & (1ULL << id)) > goto out; > > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel