Re: [syzbot] KASAN: use-after-free Read in gfs2_glock_shrink_scan

From: Andreas Gruenbacher
Date: Tue May 18 2021 - 14:17:54 EST


Hi,

On Tue, May 18, 2021 at 10:49 AM Hillf Danton <hdanton@xxxxxxxx> wrote:
> When put, glock is removed from lru by calling gfs2_glock_remove_from_lru()
> in __gfs2_glock_put(), and check GLF_LRU under lru_lock.
>
> On the shrink scan path, GLF_LRU is cleared under lru_lock but because of
> cond_resched_lock(&lru_lock) in gfs2_dispose_glock_lru() progress on the put
> side can be made without deleting glock from lru.
>
> Keep GLF_LRU across the race window opened by cond_resched_lock(&lru_lock) to
> ensure correct behavior on both sides - clrear GLF_LRU after list_del under
> lru_lock.

can you please resend with a Signed-off-by tag and a valid patch (---
line missing)?

Thanks,
Andreas

> +++ x/fs/gfs2/glock.c
> @@ -1772,6 +1772,7 @@ __acquires(&lru_lock)
> while(!list_empty(list)) {
> gl = list_first_entry(list, struct gfs2_glock, gl_lru);
> list_del_init(&gl->gl_lru);
> + clear_bit(GLF_LRU, &gl->gl_flags);
> if (!spin_trylock(&gl->gl_lockref.lock)) {
> add_back_to_lru:
> list_add(&gl->gl_lru, &lru_list);
> @@ -1817,7 +1818,6 @@ static long gfs2_scan_glock_lru(int nr)
> if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
> list_move(&gl->gl_lru, &dispose);
> atomic_dec(&lru_count);
> - clear_bit(GLF_LRU, &gl->gl_flags);
> freed++;
> continue;
> }
>