Commit 91d920f
committed
mm/kmemleak: simplify kmemleak_cond_resched() usage
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2151065
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-stable&id=6061e740822530a4ef443548b19c4e0bc6342c7a
commit 6061e74
Author: Waiman Long <longman@redhat.com>
Date: Wed, 18 Jan 2023 23:01:10 -0500
mm/kmemleak: simplify kmemleak_cond_resched() usage
Patch series "mm/kmemleak: Simplify kmemleak_cond_resched() & fix UAF", v2.
It was found that a KASAN use-after-free error was reported in the
kmemleak_scan() function. After further examination, it is believe that
even though a reference is taken from the current object, it does not
prevent the object pointed to by the next pointer from going away after a
cond_resched().
To fix that, additional flags are added to make sure that the current
object won't be removed from the object_list during the duration of the
cond_resched() to ensure the validity of the next pointer.
While making the change, I also simplify the current usage of
kmemleak_cond_resched() to make it easier to understand.
This patch (of 2):
The presence of a pinned argument and the 64k loop count make
kmemleak_cond_resched() a bit more complex to read. The pinned argument
is used only by first kmemleak_scan() loop.
Simplify the usage of kmemleak_cond_resched() by removing the pinned
argument and always do a get_object()/put_object() sequence. In addition,
the 64k loop is removed by using need_resched() to decide if
kmemleak_cond_resched() should be called.
Link: https://lkml.kernel.org/r/20230119040111.350923-1-longman@redhat.com
Link: https://lkml.kernel.org/r/20230119040111.350923-2-longman@redhat.com
Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Waiman Long <longman@redhat.com>1 parent 470c25f commit 91d920f
1 file changed
+12
-36
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1466 | 1466 | | |
1467 | 1467 | | |
1468 | 1468 | | |
1469 | | - | |
1470 | | - | |
1471 | | - | |
1472 | | - | |
| 1469 | + | |
1473 | 1470 | | |
1474 | | - | |
| 1471 | + | |
1475 | 1472 | | |
1476 | | - | |
1477 | | - | |
| 1473 | + | |
| 1474 | + | |
1478 | 1475 | | |
1479 | 1476 | | |
1480 | 1477 | | |
1481 | 1478 | | |
1482 | | - | |
1483 | | - | |
1484 | | - | |
| 1479 | + | |
1485 | 1480 | | |
1486 | 1481 | | |
1487 | 1482 | | |
| |||
1495 | 1490 | | |
1496 | 1491 | | |
1497 | 1492 | | |
1498 | | - | |
1499 | 1493 | | |
1500 | 1494 | | |
1501 | 1495 | | |
1502 | 1496 | | |
1503 | 1497 | | |
1504 | 1498 | | |
1505 | | - | |
1506 | | - | |
1507 | 1499 | | |
1508 | 1500 | | |
1509 | 1501 | | |
| |||
1529 | 1521 | | |
1530 | 1522 | | |
1531 | 1523 | | |
1532 | | - | |
| 1524 | + | |
1533 | 1525 | | |
1534 | | - | |
1535 | | - | |
1536 | 1526 | | |
1537 | 1527 | | |
1538 | 1528 | | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
1542 | | - | |
1543 | | - | |
1544 | | - | |
| 1529 | + | |
| 1530 | + | |
1545 | 1531 | | |
1546 | 1532 | | |
1547 | 1533 | | |
| |||
1608 | 1594 | | |
1609 | 1595 | | |
1610 | 1596 | | |
1611 | | - | |
1612 | 1597 | | |
1613 | | - | |
1614 | | - | |
1615 | | - | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
| 1598 | + | |
| 1599 | + | |
1619 | 1600 | | |
1620 | 1601 | | |
1621 | 1602 | | |
| |||
1650 | 1631 | | |
1651 | 1632 | | |
1652 | 1633 | | |
1653 | | - | |
1654 | 1634 | | |
1655 | | - | |
1656 | | - | |
1657 | | - | |
1658 | | - | |
1659 | | - | |
1660 | | - | |
| 1635 | + | |
| 1636 | + | |
1661 | 1637 | | |
1662 | 1638 | | |
1663 | 1639 | | |
| |||
0 commit comments