[PATCH] fs: fat: Prevent fsfuzzer from dominating the console

Li Chen posted 1 patch 3 months, 3 weeks ago
There is a newer version of this series
fs/fat/misc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] fs: fat: Prevent fsfuzzer from dominating the console
Posted by Li Chen 3 months, 3 weeks ago
From: Li Chen <chenl311@chinatelecom.cn>

fsfuzzer may make many invalid access for FAT-fs and generate many kmsg
like "FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)".

For platforms & os that enables hardware serial device whose speed are
slow, this may cause softlockup easily.

So let's ratelimit the error log.

The log as below:
[11916.242560] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.254485] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.266388] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.278287] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.290180] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.302068] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.313962] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.325848] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.337732] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.349619] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.361505] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.373391] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.385272] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.397144] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.409025] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.420909] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.432791] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.444674] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.456558] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.468446] FAT-fs (loop2): error, invalid access to FAT (entry 0x00000ccb)
[11916.480352] watchdog: BUG: soft lockup - CPU#58 stuck for 26s! [cat:2446035]
[11916.480357] Modules linked in: ...
[11916.480503] CPU: 58 PID: 2446035 Comm: cat Kdump: loaded Tainted: ...
[11916.480508] Hardware name: vclusters VSFT5000 B/VSFT5000 B, BIOS ...
[11916.480510] pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[11916.480513] pc : console_emit_next_record+0x1b4/0x288
[11916.480524] lr : console_emit_next_record+0x1ac/0x288
[11916.480525] sp : ffff80009bcdae90
[11916.480527] x29: ffff80009bcdaec0 x28: ffff800082513810 x27: 0000000000000001
[11916.480530] x26: 0000000000000001 x25: ffff800081f66000 x24: 0000000000000000
[11916.480533] x23: 0000000000000000 x22: ffff80009bcdaf8f x21: 0000000000000001
[11916.480535] x20: 0000000000000000 x19: ffff800082513810 x18: ffffffffffffffff
[11916.480538] x17: 0000000000000002 x16: 0000000000000001 x15: ffff80009bcdab30
[11916.480541] x14: 0000000000000000 x13: 205d353330363434 x12: 32545b5d36343438
[11916.480543] x11: 652820544146206f x10: 7420737365636361 x9 : ffff800080159a6c
[11916.480546] x8 : 69202c726f727265 x7 : 545b5d3634343836 x6 : 342e36313931315b
[11916.480549] x5 : ffff800082513a01 x4 : ffff80009bcdad31 x3 : 0000000000000000
[11916.480551] x2 : 00000000ffffffff x1 : 0000000001b9b000 x0 : ffff8000836cef00
[11916.480554] Call trace:
[11916.480557]  console_emit_next_record+0x1b4/0x288
[11916.480560]  console_flush_all+0xcc/0x190
[11916.480563]  console_unlock+0x78/0x138
[11916.480565]  vprintk_emit+0x1c4/0x210
[11916.480568]  vprintk_default+0x40/0x58
[11916.480570]  vprintk+0x84/0xc8
[11916.480572]  _printk+0x68/0xa0
[11916.480578]  _fat_msg+0x6c/0xa0 [fat]
[11916.480593]  __fat_fs_error+0xf8/0x118 [fat]
[11916.480601]  fat_ent_read+0x164/0x238 [fat]
[11916.480609]  fat_get_cluster+0x180/0x2c8 [fat]
[11916.480617]  fat_get_mapped_cluster+0xb8/0x170 [fat]

Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
Reviewed-by: Bin Lai <laib2@chinatelecom.cn>
---
 fs/fat/misc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index c7a2d27120bab..75c2b59fbd532 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -23,8 +23,10 @@ void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
 	struct fat_mount_options *opts = &MSDOS_SB(sb)->options;
 	va_list args;
 	struct va_format vaf;
+	static DEFINE_RATELIMIT_STATE(fat_err_rs, DEFAULT_RATELIMIT_INTERVAL,
+								  DEFAULT_RATELIMIT_BURST);
 
-	if (report) {
+	if (report && __ratelimit(&fat_err_rs)) {
 		va_start(args, fmt);
 		vaf.fmt = fmt;
 		vaf.va = &args;
-- 
2.49.0
Re: [PATCH] fs: fat: Prevent fsfuzzer from dominating the console
Posted by OGAWA Hirofumi 3 months, 3 weeks ago
Li Chen <me@linux.beauty> writes:

> Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
> Reviewed-by: Bin Lai <laib2@chinatelecom.cn>
> ---
>  fs/fat/misc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fat/misc.c b/fs/fat/misc.c
> index c7a2d27120bab..75c2b59fbd532 100644
> --- a/fs/fat/misc.c
> +++ b/fs/fat/misc.c
> @@ -23,8 +23,10 @@ void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
>  	struct fat_mount_options *opts = &MSDOS_SB(sb)->options;
>  	va_list args;
>  	struct va_format vaf;
> +	static DEFINE_RATELIMIT_STATE(fat_err_rs, DEFAULT_RATELIMIT_INTERVAL,
> +								  DEFAULT_RATELIMIT_BURST);
>  
> -	if (report) {
> +	if (report && __ratelimit(&fat_err_rs)) {
>  		va_start(args, fmt);
>  		vaf.fmt = fmt;
>  		vaf.va = &args;

Why didn't use fat_fs_error_ratelimit()?

Thanks.
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Re: [PATCH] fs: fat: Prevent fsfuzzer from dominating the console
Posted by Li Chen 3 months, 3 weeks ago
Hi OGAWA,

 ---- On Thu, 19 Jun 2025 20:04:33 +0800  OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> wrote --- 
 > Li Chen <me@linux.beauty> writes:
 > 
 > > Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
 > > Reviewed-by: Bin Lai <laib2@chinatelecom.cn>
 > > ---
 > >  fs/fat/misc.c | 4 +++-
 > >  1 file changed, 3 insertions(+), 1 deletion(-)
 > >
 > > diff --git a/fs/fat/misc.c b/fs/fat/misc.c
 > > index c7a2d27120bab..75c2b59fbd532 100644
 > > --- a/fs/fat/misc.c
 > > +++ b/fs/fat/misc.c
 > > @@ -23,8 +23,10 @@ void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
 > >      struct fat_mount_options *opts = &MSDOS_SB(sb)->options;
 > >      va_list args;
 > >      struct va_format vaf;
 > > +    static DEFINE_RATELIMIT_STATE(fat_err_rs, DEFAULT_RATELIMIT_INTERVAL,
 > > +                                  DEFAULT_RATELIMIT_BURST);
 > >  
 > > -    if (report) {
 > > +    if (report && __ratelimit(&fat_err_rs)) {
 > >          va_start(args, fmt);
 > >          vaf.fmt = fmt;
 > >          vaf.va = &args;
 > 
 > Why didn't use fat_fs_error_ratelimit()?

Oops, I missed that. I'll use it in v2. Thanks!

Regards,
Li