Commit 99a2ef5
cgroup/dmem: avoid pool UAF
An UAF issue was observed:
BUG: KASAN: slab-use-after-free in page_counter_uncharge+0x65/0x150
Write of size 8 at addr ffff888106715440 by task insmod/527
CPU: 4 UID: 0 PID: 527 Comm: insmod 6.19.0-rc7-next-20260129+ #11
Tainted: [O]=OOT_MODULE
Call Trace:
<TASK>
dump_stack_lvl+0x82/0xd0
kasan_report+0xca/0x100
kasan_check_range+0x39/0x1c0
page_counter_uncharge+0x65/0x150
dmem_cgroup_uncharge+0x1f/0x260
Allocated by task 527:
Freed by task 0:
The buggy address belongs to the object at ffff888106715400
which belongs to the cache kmalloc-512 of size 512
The buggy address is located 64 bytes inside of
freed 512-byte region [ffff888106715400, ffff888106715600)
The buggy address belongs to the physical page:
Memory state around the buggy address:
ffff888106715300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff888106715380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888106715400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888106715480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888106715500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
The issue occurs because a pool can still be held by a caller after its
associated memory region is unregistered. The current implementation frees
the pool even if users still hold references to it (e.g., before uncharge
operations complete).
This patch adds a reference counter to each pool, ensuring that a pool is
only freed when its reference count drops to zero.
Fixes: b168ed4 ("kernel/cgroup: Add "dmem" memory accounting cgroup")
Cc: [email protected] # v6.14+
Signed-off-by: Chen Ridong <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>1 parent 592a682 commit 99a2ef5
1 file changed
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
74 | 76 | | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
107 | 141 | | |
108 | 142 | | |
109 | 143 | | |
110 | | - | |
| 144 | + | |
111 | 145 | | |
112 | 146 | | |
113 | 147 | | |
| |||
342 | 376 | | |
343 | 377 | | |
344 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
345 | 385 | | |
346 | 386 | | |
347 | 387 | | |
| |||
389 | 429 | | |
390 | 430 | | |
391 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
392 | 436 | | |
393 | 437 | | |
394 | 438 | | |
| |||
435 | 479 | | |
436 | 480 | | |
437 | 481 | | |
| 482 | + | |
| 483 | + | |
438 | 484 | | |
439 | 485 | | |
440 | 486 | | |
| |||
515 | 561 | | |
516 | 562 | | |
517 | 563 | | |
518 | | - | |
| 564 | + | |
519 | 565 | | |
| 566 | + | |
| 567 | + | |
520 | 568 | | |
521 | 569 | | |
522 | 570 | | |
| |||
530 | 578 | | |
531 | 579 | | |
532 | 580 | | |
| 581 | + | |
| 582 | + | |
533 | 583 | | |
534 | 584 | | |
535 | 585 | | |
| |||
538 | 588 | | |
539 | 589 | | |
540 | 590 | | |
| 591 | + | |
| 592 | + | |
541 | 593 | | |
542 | 594 | | |
543 | 595 | | |
| |||
573 | 625 | | |
574 | 626 | | |
575 | 627 | | |
| 628 | + | |
576 | 629 | | |
577 | 630 | | |
578 | 631 | | |
| |||
624 | 677 | | |
625 | 678 | | |
626 | 679 | | |
| 680 | + | |
627 | 681 | | |
| 682 | + | |
628 | 683 | | |
629 | 684 | | |
630 | 685 | | |
| |||
719 | 774 | | |
720 | 775 | | |
721 | 776 | | |
| 777 | + | |
722 | 778 | | |
723 | 779 | | |
724 | 780 | | |
| |||
0 commit comments