В ядре Linux была устранена следующая уязвимость: ocfs2: найти запись xattr снова после дефрагментации ведра ocfs2_xattr_set_entry_bucket() передает loc.xl_entry в ocfs2_xa_set() дважды: один раз для ведра, как это стоит, и, если это сообщает -ENOSPC, еще раз после того, как ocfs2_defrag_xattr_bucket() упаковал имя / значение пары вниз. Defragmenting заканчивается сортировкой входного массива на xe_name_hash. Ведра отсортированы, поэтому сортирует только записи, которые разделяют хэш, но lib/sort.c является нестабильной кучей, и она их перемешивает. loc.xl_entry - это адрес внутри xh_entries, поэтому впоследствии он указывает, какая запись приземлилась в этом слоте, а не найденная поиском.
Второй ocfs2_xa_set() затем работает на неправильной записи. Ничто на этом пути не сравнивает имя записи с xi->xi_name, поэтому то, что происходит, зависит от того, как эти две записи сравниваются по размеру: ocfs2_xa_reuse_entry () использует свой BUG_ON (), когда размеры добавленных имен различаются, и в противном случае новое значение записывается в слот значений соседнего атрибута, а задаваемый атрибут остается нетронутым. setxattr () сообщает об успехе в любом случае. Запомните хеш записи перед дефрагментацией и посмотрите запись снова, как это делает ocfs2_xattr_bucket_find().
Запись, которая не может быть найдена снова, означает, что ведро больше не содержит то, что нашел поиск, поэтому не удается с -EFSCORRUPTED, а не пишет через устаревший указатель.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: ocfs2: find the xattr entry again after defragmenting a bucket ocfs2_xattr_set_entry_bucket() hands loc.xl_entry to ocfs2_xa_set() twice: once for the bucket as it stands, and, if that reports -ENOSPC, once more after ocfs2_defrag_xattr_bucket() has packed the name/value pairs down. Defragmenting ends by sorting the entry array on xe_name_hash. Buckets are kept sorted, so the sort only permutes entries that share a hash, but lib/sort.c is an unstable heapsort and it does permute them. loc.xl_entry is an address inside xh_entries[], so afterwards it denotes whichever entry landed in that slot rather than the one the search found. The second ocfs2_xa_set() then works on the wrong entry. Nothing on that path compares the entry's name with xi->xi_name, so what happens depends on how the two entries compare in size: ocfs2_xa_reuse_entry() trips its BUG_ON() when the padded name sizes differ, and otherwise the new value is written into the neighbouring attribute's value slot while the attribute being set is left untouched. setxattr() reports success either way. Remember the entry's hash before defragmenting and look the entry up again afterwards, the way ocfs2_xattr_bucket_find() does. An entry that cannot be found again means the bucket no longer holds what the search found, so fail with -EFSCORRUPTED rather than writing through the stale pointer.