From: Lizhi Xu <lizhi.xu@windriver.com>
To: <lizhi.xu@windriver.com>
Cc: <syzbot+8a192e8d090fa9a31135@syzkaller.appspotmail.com>,
<linux-kernel@vger.kernel.org>, <konishi.ryusuke@gmail.com>,
<linux-nilfs@vger.kernel.org>, <syzkaller-bugs@googlegroups.com>
Subject: [PATCH] nilfs2: add ratelimiting to nilfs2 message
Date: Fri, 27 Sep 2024 23:19:00 +0800 [thread overview]
Message-ID: <20240927151900.2596508-1-lizhi.xu@windriver.com> (raw)
In-Reply-To: <20240927134620.2081991-1-lizhi.xu@windriver.com>
Syzbot report a task hung in vcs_open.
When rec_len too small in nilfs_check_folio, it can result in a huge flood
of messages being sent to the console. It eventually caused tty to hung when
retrieving the console_lock().
Reported-by: syzbot+8a192e8d090fa9a31135@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8a192e8d090fa9a31135
Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
---
fs/nilfs2/dir.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c
index fe5b1a30c509..0a89dda75414 100644
--- a/fs/nilfs2/dir.c
+++ b/fs/nilfs2/dir.c
@@ -32,6 +32,7 @@
#include <linux/pagemap.h>
#include "nilfs.h"
#include "page.h"
+#include <linux/ratelimit.h>
static inline unsigned int nilfs_rec_len_from_disk(__le16 dlen)
{
@@ -115,6 +116,7 @@ static bool nilfs_check_folio(struct folio *folio, char *kaddr)
size_t limit = folio_size(folio);
struct nilfs_dir_entry *p;
char *error;
+ static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL * 5, 1);
if (dir->i_size < folio_pos(folio) + limit) {
limit = dir->i_size - folio_pos(folio);
@@ -148,9 +150,11 @@ static bool nilfs_check_folio(struct folio *folio, char *kaddr)
/* Too bad, we had an error */
Ebadsize:
- nilfs_error(sb,
- "size of directory #%lu is not a multiple of chunk size",
- dir->i_ino);
+ if (__ratelimit(&rs)) {
+ nilfs_error(sb,
+ "size of directory #%lu is not a multiple of chunk size",
+ dir->i_ino);
+ }
goto fail;
Eshort:
error = "rec_len is smaller than minimal";
@@ -167,18 +171,22 @@ static bool nilfs_check_folio(struct folio *folio, char *kaddr)
Einumber:
error = "disallowed inode number";
bad_entry:
- nilfs_error(sb,
+ if (__ratelimit(&rs)) {
+ nilfs_error(sb,
"bad entry in directory #%lu: %s - offset=%lu, inode=%lu, rec_len=%zd, name_len=%d",
dir->i_ino, error, (folio->index << PAGE_SHIFT) + offs,
(unsigned long)le64_to_cpu(p->inode),
rec_len, p->name_len);
+ }
goto fail;
Eend:
p = (struct nilfs_dir_entry *)(kaddr + offs);
- nilfs_error(sb,
- "entry in directory #%lu spans the page boundary offset=%lu, inode=%lu",
- dir->i_ino, (folio->index << PAGE_SHIFT) + offs,
- (unsigned long)le64_to_cpu(p->inode));
+ if (__ratelimit(&rs)) {
+ nilfs_error(sb,
+ "entry in directory #%lu spans the page boundary offset=%lu, inode=%lu",
+ dir->i_ino, (folio->index << PAGE_SHIFT) + offs,
+ (unsigned long)le64_to_cpu(p->inode));
+ }
fail:
return false;
}
--
2.43.0
next parent reply other threads:[~2024-09-27 15:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240927134620.2081991-1-lizhi.xu@windriver.com>
2024-09-27 15:19 ` Lizhi Xu [this message]
2024-09-27 18:18 ` [PATCH] nilfs2: add ratelimiting to nilfs2 message Ryusuke Konishi
2024-09-30 15:45 ` Ryusuke Konishi
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=20240927151900.2596508-1-lizhi.xu@windriver.com \
--to=lizhi.xu@windriver.com \
--cc=konishi.ryusuke@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=syzbot+8a192e8d090fa9a31135@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).