Skip to content

Commit 8d4d9c7

Browse files
Colin Ian KingPeter Zijlstra
authored andcommitted
sched/debug: Fix memory corruption caused by multiple small reads of flags
Reading /proc/sys/kernel/sched_domain/cpu*/domain0/flags mutliple times with small reads causes oopses with slub corruption issues because the kfree is free'ing an offset from a previous allocation. Fix this by adding in a new pointer 'buf' for the allocation and kfree and use the temporary pointer tmp to handle memory copies of the buf offsets. Fixes: 5b9f8ff ("sched/debug: Output SD flag names rather than their values") Reported-by: Jeff Bastian <[email protected]> Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b4c9c9f commit 8d4d9c7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/sched/debug.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
251251
unsigned long flags = *(unsigned long *)table->data;
252252
size_t data_size = 0;
253253
size_t len = 0;
254-
char *tmp;
254+
char *tmp, *buf;
255255
int idx;
256256

257257
if (write)
@@ -269,17 +269,17 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
269269
return 0;
270270
}
271271

272-
tmp = kcalloc(data_size + 1, sizeof(*tmp), GFP_KERNEL);
273-
if (!tmp)
272+
buf = kcalloc(data_size + 1, sizeof(*buf), GFP_KERNEL);
273+
if (!buf)
274274
return -ENOMEM;
275275

276276
for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
277277
char *name = sd_flag_debug[idx].name;
278278

279-
len += snprintf(tmp + len, strlen(name) + 2, "%s ", name);
279+
len += snprintf(buf + len, strlen(name) + 2, "%s ", name);
280280
}
281281

282-
tmp += *ppos;
282+
tmp = buf + *ppos;
283283
len -= *ppos;
284284

285285
if (len > *lenp)
@@ -294,7 +294,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write,
294294
*lenp = len;
295295
*ppos += len;
296296

297-
kfree(tmp);
297+
kfree(buf);
298298

299299
return 0;
300300
}

0 commit comments

Comments
 (0)