mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] The value may overflow
@ 2023-09-04  9:42 Denis Arefev
  2023-09-04 10:24 ` Mathieu Desnoyers
  0 siblings, 1 reply; 17+ messages in thread
From: Denis Arefev @ 2023-09-04  9:42 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, rcu, lvc-project, linux-kernel, trufanov, vfh

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

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
v2: Added fixes to the srcu_schedule_cbs_snp function as suggested by 
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 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 = cpu;
 			snp->grphi = cpu;
 		}
-		sdp->grpmask = 1 << (cpu - sdp->mynode->grplo);
+		sdp->grpmask = 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 *ssp, struct srcu_node *snp
 	int cpu;
 
 	for (cpu = snp->grplo; cpu <= 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);
 	}
-- 
2.25.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-09-05 22:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04  9:42 [PATCH v2] The value may overflow Denis Arefev
2023-09-04 10:24 ` Mathieu Desnoyers
2023-09-05  9:31   ` David Laight
2023-09-05 12:26     ` Mathieu Desnoyers
2023-09-05 13:26       ` Paul E. McKenney
2023-09-05 13:34         ` Mathieu Desnoyers
2023-09-05 13:56           ` Paul E. McKenney
2023-09-05 14:15             ` David Laight
2023-09-05 14:34               ` Mathieu Desnoyers
2023-09-05 16:40                 ` Paul E. McKenney
2023-09-05 19:27                   ` Paul E. McKenney
2023-09-05 19:36                     ` Mathieu Desnoyers
2023-09-05 19:45                       ` Paul E. McKenney
2023-09-05 20:40                         ` Joel Fernandes
2023-09-05 20:52                           ` Paul E. McKenney
2023-09-05 20:56                             ` Joel Fernandes
2023-09-05 22:22                               ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®