Re: [PATCH RFC] ubifs: Fix use-after-free in ubifs_tnc_end_commit

From: Ryder Wang
Date: Tue Oct 29 2024 - 04:11:10 EST


I just have some interesting finding.

The code of the function write_index() has a race condition bug. c->enext is used in write_index(), but it is NOT protected by c->tnc_mutex. So there must be SOME race condition problem. I believe some znode may be corrupted or misread if 2 kernel tasks are operating the same znode concurrently.

The code comment of struct ubifs_info below indicates that c->enext must be protected by c->tnc_mutex.
--------------------------------------------------------------------------------------------------
* @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
* @calc_idx_sz
--------------------------------------------------------------------------------------------------

That's why I don't think this patch can fully fix this issue because the race condition is still there.