From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82453332EBA for ; Wed, 29 Apr 2026 01:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777427896; cv=none; b=B7EKLrKzs9eCYsKOaNcXpFFeUmD6+0djFUHkfDlGvH1U777BLB4sMxzuHKSk7WoPzLYgo2dUYg5QDwTMT6Oam+eXyUI35REfwAUx625lXzAdp2/4k9NPKe0rrgh7Xb5YgBzzm9fdlYjNccnLHPo9oYjnjDOalEgdKNXRL35ZwIA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777427896; c=relaxed/simple; bh=WPmUiisgvEUcLHOFuGpX1v5/nubO70lUW01im3QIgtA=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=WTC00CcwcvJOWyNPGE+vXDjUT1zhk2JqP3OFNgarumNIOOhc+5KdepaNpexscEAcQsJJCxP8h9mNxhylkWhflthmO4jhXMBqX6VGGGnup8li7xOahzR7JMU+g9P3Lp+ijMZpaGZT00vxYUEYnn72ahuDN1NKSx+WfpLZ0fTiVnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-6949ebccfcdso8743065eaf.2 for ; Tue, 28 Apr 2026 18:58:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777427893; x=1778032693; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fe7UxhYUz1+0+oySo5SkFI1eApSoSCUpkSYiUEdJdEE=; b=OJe4B6O+ZbpKSaGfo+4kQyg6OD5qOMaUROwJ84WnygsZbJvKQiKZNzQYC5g8/uW7Eh zQdQPWualPjyN6vwpu9vr6RzH80BVyO3k6YqVb4cgW2GV4CCJhJeK9xXtoJ00YGTFVZu 02723bdJERnSVcnkhYG1E8UM0lPjmEwF/yP8jB5dkdABg/XzYW9kzzhssAGuR5TWzMbo d0XOBep7hahNvsHuDu3CFCTtOnZlwGsBuZlNZyM1xiO3I/iCpSQ9drjcHN0sV1BJK44Y ea4SANiwJSAkG4mz2plDUi5m/xodlbGRrwkpvzNcg21EeJYJamLCV4XneAOMQlat3mVQ nZTA== X-Gm-Message-State: AOJu0Yyt8l1kExnGULfvUg5SequNRCMDcDAPHnNZ9Ws4Ls0jh/CMU03Q VYBfWeT9l9XpLTEmAHjb3FAtZge+bh1wUWwf7npK1+51plTFybFIDjb6Y1SFOXjbKCRiUio8//b Hir/Gu2wRNTUu9c62qeKIT7xTJXoSol5M/uVtyNWZpklcKNkkym1XEYY9iXQ= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:298f:b0:694:9206:5bd9 with SMTP id 006d021491bc7-6965c90d886mr2769206eaf.0.1777427893628; Tue, 28 Apr 2026 18:58:13 -0700 (PDT) Date: Tue, 28 Apr 2026 18:58:13 -0700 In-Reply-To: <69dd652c.a00a0220.475f0.002d.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69f165b5.170a0220.34e5b8.0012.GAE@google.com> Subject: Forwarded: [PATCH] hfsplus: fix null-ptr-deref by creating hidden dir on remount rw From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] hfsplus: fix null-ptr-deref by creating hidden dir on remount rw Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master hfsplus_reconfigure() does not create the hidden directory when remounting from read-only to read-write, leaving sbi->hidden_dir as NULL. This causes a null-ptr-deref when any subsequent link/unlink/rename operation dereferences it. Extract hidden directory creation into a helper and call it from hfsplus_reconfigure() when switching to read-write mode. Reported-by: syzbot+c0ba772a362e70937dfb@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c0ba772a362e70937dfb Signed-off-by: Deepanshu Kartikey --- Changes in v4: - Correct fix: extract hidden dir creation into helper and call from hfsplus_reconfigure() on remount rw, as suggested by Vyacheslav Dubeyko. Changes in v3: - Correct fix location: guard sbi->hidden_dir in hfsplus_link() and hfsplus_unlink() in dir.c. Changes in v2: - Fixed commit message: hfsplus_delete_cat() has multiple callers, not just hfsplus_unlink() as incorrectly stated in v1. --- fs/hfsplus/super.c | 88 ++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index 7229a8ae89f9..8b5c39ce4d48 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -372,15 +372,59 @@ static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf) return 0; } +static int hfsplus_create_hidden_dir(struct super_block *sb) +{ + struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); + struct inode *root = d_inode(sb->s_root); + struct qstr str; + int err; + + str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1; + str.name = HFSP_HIDDENDIR_NAME; + + mutex_lock(&sbi->vh_mutex); + sbi->hidden_dir = hfsplus_new_inode(sb, root, S_IFDIR); + if (!sbi->hidden_dir) { + mutex_unlock(&sbi->vh_mutex); + return -ENOMEM; + } + + err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root, + &str, sbi->hidden_dir); + if (err) { + mutex_unlock(&sbi->vh_mutex); + goto out_put_hidden_dir; + } + + err = hfsplus_init_security(sbi->hidden_dir, root, &str); + if (err == -EOPNOTSUPP) + err = 0; + else if (err) { + hfsplus_delete_cat(sbi->hidden_dir->i_ino, root, &str); + mutex_unlock(&sbi->vh_mutex); + goto out_put_hidden_dir; + } + + mutex_unlock(&sbi->vh_mutex); + hfsplus_mark_inode_dirty(sbi->hidden_dir, + HFSPLUS_I_CAT_DIRTY); + return 0; + +out_put_hidden_dir: + iput(sbi->hidden_dir); + sbi->hidden_dir = NULL; + return err; +} + static int hfsplus_reconfigure(struct fs_context *fc) { struct super_block *sb = fc->root->d_sb; + struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); sync_filesystem(sb); if ((bool)(fc->sb_flags & SB_RDONLY) == sb_rdonly(sb)) return 0; if (!(fc->sb_flags & SB_RDONLY)) { - struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); struct hfsplus_vh *vhdr = sbi->s_vhdr; if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) { @@ -401,6 +445,12 @@ static int hfsplus_reconfigure(struct fs_context *fc) fc->sb_flags |= SB_RDONLY; } } + /* + * Create hidden dir if remounting read-write and it does + * not exist - required for link/unlink/rename operations. + */ + if (!sb_rdonly(sb) && !sbi->hidden_dir) + return hfsplus_create_hidden_dir(sb); return 0; } @@ -595,38 +645,9 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc) hfsplus_sync_fs(sb, 1); if (!sbi->hidden_dir) { - mutex_lock(&sbi->vh_mutex); - sbi->hidden_dir = hfsplus_new_inode(sb, root, S_IFDIR); - if (!sbi->hidden_dir) { - mutex_unlock(&sbi->vh_mutex); - err = -ENOMEM; + err = hfsplus_create_hidden_dir(sb); + if (err) goto out_put_root; - } - err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root, - &str, sbi->hidden_dir); - if (err) { - mutex_unlock(&sbi->vh_mutex); - goto out_put_hidden_dir; - } - - err = hfsplus_init_security(sbi->hidden_dir, - root, &str); - if (err == -EOPNOTSUPP) - err = 0; /* Operation is not supported. */ - else if (err) { - /* - * Try to delete anyway without - * error analysis. - */ - hfsplus_delete_cat(sbi->hidden_dir->i_ino, - root, &str); - mutex_unlock(&sbi->vh_mutex); - goto out_put_hidden_dir; - } - - mutex_unlock(&sbi->vh_mutex); - hfsplus_mark_inode_dirty(sbi->hidden_dir, - HFSPLUS_I_CAT_DIRTY); } } @@ -634,9 +655,6 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc) sbi->nls = nls; return 0; -out_put_hidden_dir: - cancel_delayed_work_sync(&sbi->sync_work); - iput(sbi->hidden_dir); out_put_root: dput(sb->s_root); sb->s_root = NULL; -- 2.43.0