mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Lizhi Xu <lizhi.xu@windriver.com>
Cc: syzbot+73d8fc29ec7cba8286fa@syzkaller.appspotmail.com,
	almaz.alexandrovich@paragon-software.com, brauner@kernel.org,
	jack@suse.cz, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, ntfs3@lists.linux.dev,
	syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk
Subject: Re: [PATCH] fs: add check for symlink corrupted
Date: Fri, 15 Nov 2024 12:43:06 +0100	[thread overview]
Message-ID: <20241115114306.5sgqa3opc56rhu4x@quack3> (raw)
In-Reply-To: <20241115094908.3783952-1-lizhi.xu@windriver.com>

On Fri 15-11-24 17:49:08, Lizhi Xu wrote:
> syzbot reported a null-ptr-deref in pick_link. [1]
> When symlink's inode is corrupted, the value of the i_link is 2 in this case,
> it will trigger null pointer deref when accessing *res in pick_link(). 
> 
> To avoid this issue, add a check for inode mode, return -EINVAL when it's
> not symlink.
> 
> [1]
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> CPU: 0 UID: 0 PID: 5310 Comm: syz-executor255 Not tainted 6.12.0-rc6-syzkaller-00318-ga9cda7c0ffed #0
> Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
> RIP: 0010:pick_link+0x51c/0xd50 fs/namei.c:1864

Hum, based on line number is:

        if (*res == '/') { <<<< HERE
                error = nd_jump_root(nd);
                if (unlikely(error))

So res would be non-zero but a small number.

> Code: c1 e8 03 42 80 3c 38 00 74 08 48 89 df e8 fc 00 e9 ff 48 8b 2b 48 85 ed 0f 84 92 00 00 00 e8 7b 36 7f ff 48 89 e8 48 c1 e8 03 <42> 0f b6 04 38 84 c0 0f 85 a2 05 00 00 0f b6 5d 00 bf 2f 00 00 00
> RSP: 0018:ffffc9000d147998 EFLAGS: 00010246
> RAX: 0000000000000000 RBX: ffff88804558dec8 RCX: ffff88801ec7a440
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
> RBP: 0000000000000002 R08: ffffffff8215a35f R09: 1ffffffff203a13d
> R10: dffffc0000000000 R11: fffffbfff203a13e R12: 1ffff92001a28f93
> R13: ffffc9000d147af8 R14: 1ffff92001a28f5f R15: dffffc0000000000
> FS:  0000555577611380(0000) GS:ffff88801fc00000(0000) knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007fcc0a595ed8 CR3: 0000000035760000 CR4: 0000000000352ef0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>  <TASK>
>  step_into+0xca9/0x1080 fs/namei.c:1923
>  lookup_last fs/namei.c:2556 [inline]
>  path_lookupat+0x16f/0x450 fs/namei.c:2580
>  filename_lookup+0x256/0x610 fs/namei.c:2609
>  user_path_at+0x3a/0x60 fs/namei.c:3016
>  do_mount fs/namespace.c:3844 [inline]
>  __do_sys_mount fs/namespace.c:4057 [inline]
>  __se_sys_mount+0x297/0x3c0 fs/namespace.c:4034
>  do_syscall_x64 arch/x86/entry/common.c:52 [inline]
>  do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
>  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> RIP: 0033:0x7f4b18ad5b19
> Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007ffc2e486c48 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
> RAX: ffffffffffffffda RBX: 0030656c69662f2e RCX: 00007f4b18ad5b19
> RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000000
> RBP: 00007f4b18b685f0 R08: 0000000000000000 R09: 00005555776124c0
> R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffc2e486c70
> R13: 00007ffc2e486e98 R14: 431bde82d7b634db R15: 00007f4b18b1e03b
>  </TASK>
> 
> Reported-and-tested-by: syzbot+73d8fc29ec7cba8286fa@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=73d8fc29ec7cba8286fa
> Signed-off-by: Lizhi Xu <lizhi.xu@windriver.com>
> ---
>  fs/namei.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 4a4a22a08ac2..f5dbccb3aafc 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -1844,6 +1844,9 @@ static const char *pick_link(struct nameidata *nd, struct path *link,
>  	if (unlikely(error))
>  		return ERR_PTR(error);
>  
> +	if (!S_ISLNK(inode->i_mode))
> +		return ERR_PTR(-EINVAL);
> +

So I don't see how we can get here without inode being a symlink.
pick_link() is called from step_into() which has among other things:

if (likely(!d_is_symlink(path.dentry)) || ...)
	do something and return

so we are checking whether the inode is a symlink before calling
pick_link(). And yes, the d_is_symlink() is using cached type in
dentry->d_flags so they could mismatch. But inode is not supposed to change
its type during its lifetime so if there is a mismatch that is the problem
that needs to be fixed.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2024-11-15 11:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14 18:08 [syzbot] [ntfs3?] general protection fault in pick_link syzbot
2024-11-15  8:26 ` [syzbot] " syzbot
2024-11-15  9:49 ` [PATCH] fs: add check for symlink corrupted Lizhi Xu
2024-11-15 11:43   ` Jan Kara [this message]
2024-11-16  1:02     ` Lizhi Xu
2024-11-16  1:25       ` Al Viro
2024-11-15 13:06   ` Al Viro
2024-11-15 13:24     ` Al Viro
2024-11-16  1:39       ` Lizhi Xu
2024-11-16  2:32         ` Al Viro
2024-11-19 11:29           ` [PATCH V2] fs: improve the check of whether i_link has been set Lizhi Xu
2024-11-19 16:36             ` Al Viro
2024-11-20  3:04               ` [PATCH V3] fs/ntfs3: check if the inode is bad before creating symlink Lizhi Xu
2024-11-20 16:10                 ` Al Viro
2024-11-21  3:13                   ` Lizhi Xu
2024-11-21  3:55                     ` Al Viro
2024-11-21  5:27                       ` Lizhi Xu
2024-11-22  7:49                   ` Lizhi Xu
2024-11-22  8:10                     ` [PATCH V4] " Lizhi Xu
2024-11-22 11:50                       ` Jan Kara
2024-11-23  1:09                     ` [PATCH V5] " Lizhi Xu
2024-11-23  1:32                       ` Al Viro
2024-11-24  4:43                         ` [PATCH V6] fs/ntfs3: check if the inode is bad before instantiating dentry Lizhi Xu

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=20241115114306.5sgqa3opc56rhu4x@quack3 \
    --to=jack@suse.cz \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.xu@windriver.com \
    --cc=ntfs3@lists.linux.dev \
    --cc=syzbot+73d8fc29ec7cba8286fa@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®