Skip to content

Commit 005b618

Browse files
Artem SadovnikovNeeraj Upadhyay (AMD)
authored andcommitted
refscale: Check that nreaders and loops multiplication doesn't overflow
The nreaders and loops variables are exposed as module parameters, which, in certain combinations, can lead to multiplication overflow. Besides, loops parameter is defined as long, while through the code is used as int, which can cause truncation on 64-bit kernels and possible zeroes where they shouldn't appear. Since code uses result of multiplication as int anyway, it only makes sense to replace loops with int. Multiplication overflow check is also added due to possible multiplication between two very big numbers. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 653ed64 ("refperf: Add a test to measure performance of read-side synchronization") Signed-off-by: Artem Sadovnikov <[email protected]> Signed-off-by: Neeraj Upadhyay (AMD) <[email protected]>
1 parent 86731a2 commit 005b618

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kernel/rcu/refscale.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ torture_param(int, holdoff, IS_BUILTIN(CONFIG_RCU_REF_SCALE_TEST) ? 10 : 0,
8585
// Number of typesafe_lookup structures, that is, the degree of concurrency.
8686
torture_param(long, lookup_instances, 0, "Number of typesafe_lookup structures.");
8787
// Number of loops per experiment, all readers execute operations concurrently.
88-
torture_param(long, loops, 10000, "Number of loops per experiment.");
88+
torture_param(int, loops, 10000, "Number of loops per experiment.");
8989
// Number of readers, with -1 defaulting to about 75% of the CPUs.
9090
torture_param(int, nreaders, -1, "Number of readers, -1 for 75% of CPUs.");
9191
// Number of runs.
@@ -1140,7 +1140,7 @@ static void
11401140
ref_scale_print_module_parms(const struct ref_scale_ops *cur_ops, const char *tag)
11411141
{
11421142
pr_alert("%s" SCALE_FLAG
1143-
"--- %s: verbose=%d verbose_batched=%d shutdown=%d holdoff=%d lookup_instances=%ld loops=%ld nreaders=%d nruns=%d readdelay=%d\n", scale_type, tag,
1143+
"--- %s: verbose=%d verbose_batched=%d shutdown=%d holdoff=%d lookup_instances=%ld loops=%d nreaders=%d nruns=%d readdelay=%d\n", scale_type, tag,
11441144
verbose, verbose_batched, shutdown, holdoff, lookup_instances, loops, nreaders, nruns, readdelay);
11451145
}
11461146

@@ -1238,12 +1238,16 @@ ref_scale_init(void)
12381238
// Reader tasks (default to ~75% of online CPUs).
12391239
if (nreaders < 0)
12401240
nreaders = (num_online_cpus() >> 1) + (num_online_cpus() >> 2);
1241-
if (WARN_ONCE(loops <= 0, "%s: loops = %ld, adjusted to 1\n", __func__, loops))
1241+
if (WARN_ONCE(loops <= 0, "%s: loops = %d, adjusted to 1\n", __func__, loops))
12421242
loops = 1;
12431243
if (WARN_ONCE(nreaders <= 0, "%s: nreaders = %d, adjusted to 1\n", __func__, nreaders))
12441244
nreaders = 1;
12451245
if (WARN_ONCE(nruns <= 0, "%s: nruns = %d, adjusted to 1\n", __func__, nruns))
12461246
nruns = 1;
1247+
if (WARN_ONCE(loops > INT_MAX / nreaders,
1248+
"%s: nreaders * loops will overflow, adjusted loops to %d",
1249+
__func__, INT_MAX / nreaders))
1250+
loops = INT_MAX / nreaders;
12471251
reader_tasks = kcalloc(nreaders, sizeof(reader_tasks[0]),
12481252
GFP_KERNEL);
12491253
if (!reader_tasks) {

0 commit comments

Comments
 (0)