All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: Gao Xiang <hsiangkao@linux.alibaba.com>, linux-erofs@lists.ozlabs.org
Cc: syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] erofs: fix rare pcluster memory leak after unmounting
Date: Thu, 12 Dec 2024 22:16:35 +0800	[thread overview]
Message-ID: <88a6844e-1294-4997-8ef3-a69ff6add34d@kernel.org> (raw)
In-Reply-To: <20241203072821.1885740-1-hsiangkao@linux.alibaba.com>

On 2024/12/3 15:28, Gao Xiang wrote:
> There may still exist some pcluster with valid reference counts
> during unmounting.  Instead of introducing another synchronization
> primitive, just try again as unmounting is relatively rare.  This
> approach is similar to z_erofs_cache_invalidate_folio().
> 
> It was also reported by syzbot as a UAF due to commit f5ad9f9a603f
> ("erofs: free pclusters if no cached folio is attached"):
> 
> BUG: KASAN: slab-use-after-free in do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
> ..
>   queued_spin_trylock include/asm-generic/qspinlock.h:92 [inline]
>   do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
>   __raw_spin_trylock include/linux/spinlock_api_smp.h:89 [inline]
>   _raw_spin_trylock+0x20/0x80 kernel/locking/spinlock.c:138
>   spin_trylock include/linux/spinlock.h:361 [inline]
>   z_erofs_put_pcluster fs/erofs/zdata.c:959 [inline]
>   z_erofs_decompress_pcluster fs/erofs/zdata.c:1403 [inline]
>   z_erofs_decompress_queue+0x3798/0x3ef0 fs/erofs/zdata.c:1425
>   z_erofs_decompressqueue_work+0x99/0xe0 fs/erofs/zdata.c:1437
>   process_one_work kernel/workqueue.c:3229 [inline]
>   process_scheduled_works+0xa68/0x1840 kernel/workqueue.c:3310
>   worker_thread+0x870/0xd30 kernel/workqueue.c:3391
>   kthread+0x2f2/0x390 kernel/kthread.c:389
>   ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147
>   ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
>   </TASK>
> 
> However, it seems a long outstanding memory leak.  Fix it now.
> 
> Fixes: f5ad9f9a603f ("erofs: free pclusters if no cached folio is attached")
> Reported-by: syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/r/674c1235.050a0220.ad585.0032.GAE@google.com
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: Gao Xiang <hsiangkao@linux.alibaba.com>, linux-erofs@lists.ozlabs.org
Cc: Chao Yu <chao@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com
Subject: Re: [PATCH] erofs: fix rare pcluster memory leak after unmounting
Date: Thu, 12 Dec 2024 22:16:35 +0800	[thread overview]
Message-ID: <88a6844e-1294-4997-8ef3-a69ff6add34d@kernel.org> (raw)
In-Reply-To: <20241203072821.1885740-1-hsiangkao@linux.alibaba.com>

On 2024/12/3 15:28, Gao Xiang wrote:
> There may still exist some pcluster with valid reference counts
> during unmounting.  Instead of introducing another synchronization
> primitive, just try again as unmounting is relatively rare.  This
> approach is similar to z_erofs_cache_invalidate_folio().
> 
> It was also reported by syzbot as a UAF due to commit f5ad9f9a603f
> ("erofs: free pclusters if no cached folio is attached"):
> 
> BUG: KASAN: slab-use-after-free in do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
> ..
>   queued_spin_trylock include/asm-generic/qspinlock.h:92 [inline]
>   do_raw_spin_trylock+0x72/0x1f0 kernel/locking/spinlock_debug.c:123
>   __raw_spin_trylock include/linux/spinlock_api_smp.h:89 [inline]
>   _raw_spin_trylock+0x20/0x80 kernel/locking/spinlock.c:138
>   spin_trylock include/linux/spinlock.h:361 [inline]
>   z_erofs_put_pcluster fs/erofs/zdata.c:959 [inline]
>   z_erofs_decompress_pcluster fs/erofs/zdata.c:1403 [inline]
>   z_erofs_decompress_queue+0x3798/0x3ef0 fs/erofs/zdata.c:1425
>   z_erofs_decompressqueue_work+0x99/0xe0 fs/erofs/zdata.c:1437
>   process_one_work kernel/workqueue.c:3229 [inline]
>   process_scheduled_works+0xa68/0x1840 kernel/workqueue.c:3310
>   worker_thread+0x870/0xd30 kernel/workqueue.c:3391
>   kthread+0x2f2/0x390 kernel/kthread.c:389
>   ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:147
>   ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
>   </TASK>
> 
> However, it seems a long outstanding memory leak.  Fix it now.
> 
> Fixes: f5ad9f9a603f ("erofs: free pclusters if no cached folio is attached")
> Reported-by: syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/r/674c1235.050a0220.ad585.0032.GAE@google.com
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

  reply	other threads:[~2024-12-12 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-01  7:37 [syzbot] [erofs?] KASAN: slab-use-after-free Read in z_erofs_decompress_queue syzbot
2024-12-03  7:28 ` [PATCH] erofs: fix rare pcluster memory leak after unmounting Gao Xiang
2024-12-03  7:28   ` Gao Xiang
2024-12-12 14:16   ` Chao Yu via Linux-erofs [this message]
2024-12-12 14:16     ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88a6844e-1294-4997-8ef3-a69ff6add34d@kernel.org \
    --to=linux-erofs@lists.ozlabs.org \
    --cc=chao@kernel.org \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+7ff87b095e7ca0c5ac39@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.