The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Du Cheng <ducheng2@gmail.com>
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
	gregkh@linuxfoundation.org, Du Cheng <ducheng2@gmail.com>,
	syzbot+651ca866e5e2b4b5095b@syzkaller.appspotmail.com
Subject: [PATCH] fs:minix: catch inode->i_nlink == 0 in minix_rename()
Date: Sun, 25 Apr 2021 15:48:51 +0800	[thread overview]
Message-ID: <20210425074851.14100-1-ducheng2@gmail.com> (raw)

If the destination inode has i_nlink==0, it is invalid. Hence we should
return an error instead of proceeding with drop_nlink() which causes
WARN_ON().

Reported by syzkaller:
https://syzkaller.appspot.com/bug?id=0b1ac5e39c478b05355e189451b5379dc925fd2e

Reported-by: syzbot+651ca866e5e2b4b5095b@syzkaller.appspotmail.com
Signed-off-by: Du Cheng <ducheng2@gmail.com>
---
This patch fixed the kernel panic on my testing envionment with the syzbot
reproducer.

This patch works in a similar spirit with the following patch on bad inode:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=facb03dddec04e4aac1bb2139accdceb04deb1f3


 fs/minix/namei.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/minix/namei.c b/fs/minix/namei.c
index 937fa5fae2b8..96761536b8d4 100644
--- a/fs/minix/namei.c
+++ b/fs/minix/namei.c
@@ -215,6 +215,10 @@ static int minix_rename(struct user_namespace *mnt_userns,
 		struct page * new_page;
 		struct minix_dir_entry * new_de;
 
+		err = -EINVAL;
+		if (new_inode->i_nlink == 0)
+			goto out_dir;
+
 		err = -ENOTEMPTY;
 		if (dir_de && !minix_empty_dir(new_inode))
 			goto out_dir;
-- 
2.30.2


                 reply	other threads:[~2021-04-25  7:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210425074851.14100-1-ducheng2@gmail.com \
    --to=ducheng2@gmail.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=syzbot+651ca866e5e2b4b5095b@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox