Commit 26f775a
mm/damon/core: avoid use of half-online-committed context
One major usage of damon_call() is online DAMON parameters update. It is
done by calling damon_commit_ctx() inside the damon_call() callback
function. damon_commit_ctx() can fail for two reasons: 1) invalid
parameters and 2) internal memory allocation failures. In case of
failures, the damon_ctx that attempted to be updated (commit destination)
can be partially updated (or, corrupted from a perspective), and therefore
shouldn't be used anymore. The function only ensures the damon_ctx object
can safely deallocated using damon_destroy_ctx().
The API callers are, however, calling damon_commit_ctx() only after
asserting the parameters are valid, to avoid damon_commit_ctx() fails due
to invalid input parameters. But it can still theoretically fail if the
internal memory allocation fails. In the case, DAMON may run with the
partially updated damon_ctx. This can result in unexpected behaviors
including even NULL pointer dereference in case of damos_commit_dests()
failure [1]. Such allocation failure is arguably too small to fail, so
the real world impact would be rare. But, given the bad consequence, this
needs to be fixed.
Avoid such partially-committed (maybe-corrupted) damon_ctx use by saving
the damon_commit_ctx() failure on the damon_ctx object. For this,
introduce damon_ctx->maybe_corrupted field. damon_commit_ctx() sets it
when it is failed. kdamond_call() checks if the field is set after each
damon_call_control->fn() is executed. If it is set, ignore remaining
callback requests and return. All kdamond_call() callers including
kdamond_fn() also check the maybe_corrupted field right after
kdamond_call() invocations. If the field is set, break the kdamond_fn()
main loop so that DAMON sill doesn't use the context that might be
corrupted.
[[email protected]: let kdamond_call() with cancel regardless of maybe_corrupted]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://sashiko.dev/#/patchset/20260319145218.86197-1-sj%40kernel.org
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lore.kernel.org/[email protected] [1]
Fixes: 3301f18 ("mm/damon/sysfs: handle commit command using damon_call()")
Signed-off-by: SeongJae Park <[email protected]>
Cc: <[email protected]> [6.15+]
Signed-off-by: Andrew Morton <[email protected]>1 parent 3a206a8 commit 26f775a
2 files changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
810 | 810 | | |
811 | 811 | | |
812 | 812 | | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
813 | 819 | | |
814 | 820 | | |
815 | 821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1252 | 1252 | | |
1253 | 1253 | | |
1254 | 1254 | | |
| 1255 | + | |
1255 | 1256 | | |
1256 | 1257 | | |
1257 | 1258 | | |
| |||
1277 | 1278 | | |
1278 | 1279 | | |
1279 | 1280 | | |
| 1281 | + | |
1280 | 1282 | | |
1281 | 1283 | | |
1282 | 1284 | | |
| |||
2678 | 2680 | | |
2679 | 2681 | | |
2680 | 2682 | | |
| 2683 | + | |
| 2684 | + | |
2681 | 2685 | | |
2682 | 2686 | | |
2683 | 2687 | | |
| |||
2707 | 2711 | | |
2708 | 2712 | | |
2709 | 2713 | | |
| 2714 | + | |
| 2715 | + | |
2710 | 2716 | | |
2711 | 2717 | | |
2712 | 2718 | | |
| |||
2790 | 2796 | | |
2791 | 2797 | | |
2792 | 2798 | | |
| 2799 | + | |
| 2800 | + | |
2793 | 2801 | | |
2794 | 2802 | | |
2795 | 2803 | | |
| |||
0 commit comments