From nobody Sun Feb 8 16:30:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC913C83F33 for ; Mon, 4 Sep 2023 12:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240112AbjIDMVU (ORCPT ); Mon, 4 Sep 2023 08:21:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjIDMVT (ORCPT ); Mon, 4 Sep 2023 08:21:19 -0400 Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B78181B7; Mon, 4 Sep 2023 05:21:16 -0700 (PDT) From: Denis Arefev DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1693830074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=PkhsYPl5R9WQ8Ho5cdIw7xtPTnCUIlc0O/XJmxrf3js=; b=glfoCKVaEopzeuCS1zErWOGHqBzjhqa6l+KOzdtKuAhCMt6J5RUk+CR5Fg9mZOd1237iwQ lSNTRvTnW7q9yQGmwBYeJKf/J5Pmq8h7mbaW8MJODq+afMLhnarEi4i4seDcbJulcj3I3S imbi9S/4raLhg7EykWBF4jPszOO0LAA= To: Lai Jiangshan Cc: "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , rcu@vger.kernel.org, lvc-project@linuxtesting.org, linux-kernel@vger.kernel.org, trufanov@swemel.ru, vfh@swemel.ru Subject: [PATCH v3] Fix srcu_struct node grpmask overflow on 64-bit systems Date: Mon, 4 Sep 2023 15:21:14 +0300 Message-Id: <20230904122114.66757-1-arefev@swemel.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The value of an arithmetic expression 1 << (cpu - sdp->mynode->grplo) is subject to overflow due to a failure to cast operands to a larger data type before performing arithmetic. The maximum result of this subtraction is defined by the RCU_FANOUT=20 or other srcu level-spread values assigned by rcu_init_levelspread(),=20 which can indeed cause the signed 32-bit integer literal ("1") to overflow=20 when shifted by any value greater than 31.=20 Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Denis Arefev Reviewed-by: Mathieu Desnoyers --- v3: Changed the name of the patch, as suggested by=20 Mathieu Desnoyers v2: Added fixes to the srcu_schedule_cbs_snp function as suggested by=20 Mathieu Desnoyers kernel/rcu/srcutree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 20d7a238d675..6c18e6005ae1 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -223,7 +223,7 @@ static bool init_srcu_struct_nodes(struct srcu_struct *= ssp, gfp_t gfp_flags) snp->grplo =3D cpu; snp->grphi =3D cpu; } - sdp->grpmask =3D 1 << (cpu - sdp->mynode->grplo); + sdp->grpmask =3D 1UL << (cpu - sdp->mynode->grplo); } smp_store_release(&ssp->srcu_sup->srcu_size_state, SRCU_SIZE_WAIT_BARRIER= ); return true; @@ -833,7 +833,7 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *s= sp, struct srcu_node *snp int cpu; =20 for (cpu =3D snp->grplo; cpu <=3D snp->grphi; cpu++) { - if (!(mask & (1 << (cpu - snp->grplo)))) + if (!(mask & (1UL << (cpu - snp->grplo)))) continue; srcu_schedule_cbs_sdp(per_cpu_ptr(ssp->sda, cpu), delay); } --=20 2.25.1