From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FFCA28F3 for ; Mon, 30 Jan 2023 14:09:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7B55C433D2; Mon, 30 Jan 2023 14:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675087752; bh=kvdoUrQJvrPeZnMH1863X/Nxidy+MGmJm9pXOFZTgg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rVg/06/JccUGqP6ft1sbAp0Y8i0UaphQs2JQRgaqWYkT5xdK46WPbmZj9CZAhgeCM ZpijZIU4zWwuZteVxNcSbh1TiqyuUl7ioQhqnXMWC6JJOaXM8s0sjKjx2d1YIcBPm3 vH8YKT8YCiALQVqzm8N7HBdDnCO3mYj2Sul4R6t0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Colin Ian King , "Peter Zijlstra (Intel)" , Ian Rogers , Kim Phillips Subject: [PATCH 6.1 313/313] perf/x86/amd: fix potential integer overflow on shift of a int Date: Mon, 30 Jan 2023 14:52:28 +0100 Message-Id: <20230130134351.326412106@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130134336.532886729@linuxfoundation.org> References: <20230130134336.532886729@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Colin Ian King commit 08245672cdc6505550d1a5020603b0a8d4a6dcc7 upstream. The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then passed as a 64 bit function argument. In the case where i is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead. Fixes: 471af006a747 ("perf/x86/amd: Constrain Large Increment per Cycle events") Signed-off-by: Colin Ian King Signed-off-by: Peter Zijlstra (Intel) Acked-by: Ian Rogers Acked-by: Kim Phillips Link: https://lore.kernel.org/r/20221202135149.1797974-1-colin.i.king@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -1387,7 +1387,7 @@ static int __init amd_core_pmu_init(void * numbered counter following it. */ for (i = 0; i < x86_pmu.num_counters - 1; i += 2) - even_ctr_mask |= 1 << i; + even_ctr_mask |= BIT_ULL(i); pair_constraint = (struct event_constraint) __EVENT_CONSTRAINT(0, even_ctr_mask, 0,