В ядре Linux была устранена следующая уязвимость: samples/damon/mtier: handle damon_stop() failure damon_sample_mtier_stop() предполагает, что его вызов damon_stop() всегда будет успешно останавливать два контекста DAMON. Таким образом, он распределяет два контекста DAMON после вызова damon_stop(). Однако, если данный контекст уже остановлен, damon_stop() терпит неудачу и возвращает ошибку, позволяя контекстам DAMON, которые еще не остановились, продолжать работать.
Такого рода неожиданные ранние остановки контекста DAMON могут произойти из-за сбоев выделения памяти в kdamond_fn(). Поскольку damon_sample_mtier_stop() просто распределяет все контексты DAMON с объектами damon_target и damon_region, которые связаны с контекстами, выполнение неостановленного контекста DAMON (kdamond) заканчивается использованием освобожденной памяти (use-after-free). Исправьте проблему, разделив вызываемый damon_stop() на контексты.
Обратите внимание, что DAMON_SYSFS также позволяет выполнять несколько контекстов DAMON. Но он называет damon_stop () для каждого контекста один за другим. Следовательно, этот вопрос только в МТЭР.
В долгосрочной перспективе было бы лучше рефакторить damon_stop(), чтобы всегда обеспечивать остановку всех контекстов независимо от сбоев в середине. Однако сделайте это исправление текущим способом, чтобы сделать его простым и легким для обратной связи. Я сделаю рефакторинг позже.
Эта проблема была обнаружена [1] Sashiko.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: samples/damon/mtier: handle damon_stop() failure damon_sample_mtier_stop() assumes its damon_stop() call will always successfully stops the two DAMON contexts. Hence it deallocates the two DAMON contexts after the damon_stop() call. However, if a given context is already stopped, damon_stop() fails and returns an error while letting the DAMON contexts that have not yet stopped keep running. This kind of unexpected early DAMON context stops could happen due to memory allocation failures in kdamond_fn(). Because damon_sample_mtier_stop() just deallocates all DAMON contexts with damon_target and damon_region objects that are linked to the contexts, the execution of the unstopped DAMON context (kdamond) ends up using the memory that freed (use-after-free). Fix the issue by separating the damon_stop() to be invoked per context. Note that DAMON_SYSFS also allows multiple DAMON contexts execution. But, it calls damon_stop() for each context one by one. Hence this issue is only in mtier. For the long term, it would be better to refactor damon_stop() to always ensure stopping all contexts regardless of the failures in the middle. Make this fix in the current way, though, to keep it simple and easy to backport. I will do the refactoring later. The issue was discovered [1] by Sashiko.