History

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.

Colin Ian King committed 6 years ago

Commit 8d4d9c71 parent b4c9c9f1 file · +6 −6Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/sched/debug.c+6−6
@@ -251,7 +251,7 @@ static int sd_ctl_doflags(struct ctl_table *table, int write, · 250 unmodified lines
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, · 11 unmodified lines
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, · 8 unmodified lines
294294 *lenp = len;
295295 *ppos += len;
296296
297− kfree(tmp);
297+ kfree(buf);
298298
299299 return 0;
300300 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t