From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (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 636E143D4FB for ; Tue, 14 Jul 2026 09:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784020993; cv=none; b=cOP5noKuP0+AGqD4Kg7t5hseiCMnesc75DU7gMYTT9Q0lRJDN/bVmlttRYtllNWLY3DtmMciRU3qiJSM7Twaa7lQ6uX+T6WibYK4USXfvW0LI+lSF1qtoQTSQdV7Q1Cc61ytTWo06kNWfdRAY3tmqJy4C8fIm5uoziNXU3M+lCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784020993; c=relaxed/simple; bh=Ob+xaVmV7dDw898KkBs9aO0qoPPqxKF0/NBqL3MBsFg=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=srvy3V742rIep8dJzhpMOCmm8iC3LP5q+l1JA9qpaP3q0GNgSBgTbmdyfcSApa+M00Bt6vgs4XhWhBv4VYmdM7j7EmO7QLJIwW5kPTkWiyS0l2Ae3atCIe9XGw+ZRbW0/T+C8gLIMBGKooX+uANLPVB8oJZ7W4iSm8Wtwx9vuaY= 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.167.197 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-oi1-f197.google.com with SMTP id 5614622812f47-49d4cb3ca23so7485718b6e.3 for ; Tue, 14 Jul 2026 02:23:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784020990; x=1784625790; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=kFSncGlZ/VuOhj+6FWbRIXiUlbJ92HH6FWjRFHn7tvw=; b=UKQOac2tRrxKOX3SAMVI+jpgP/ulacJvIiUlma7R3t1iDUh1tb+twwZuylpuQdlH7F MFpXYolYQLxXgRxnA5of1G9wafCBuqDURIQhjYmg0pF/4RttL+aQuZUtXZv2BZh3NIhf JqeVwIyN8Dz8yft27K2bHHSdoiylTVWc1sL82kn6uh2w2HQVmxdyB6GrYL6E9oabeU0V Fm5V3pKjN7wxhJsEyPlJYrSuPI+5YH7XH3342fDrpm2+GbLS2hCZHHUdxcCmpF9qnxO/ HA1O/X0S2jDJenMSv4Bj6/pQcKoCT8hJ1Lwwe0Uy7FRQI7IU2Z1GLbDPjl33hWBASMCX Qquw== X-Gm-Message-State: AOJu0YzLplkpDORXaiLyGIW9WEHKLHlxC7Tb3lg/4h+0bIP+53uAjK+J MpzH7VkN9q1Qn9D3tfpGfUTLvmr22MN0DTQHlgbcUu3VKSQHNdD2BTejT8Y8cpc6p/QB3TRleYt t+QijMPfT2bNUCjbciweeFwNo6+L8fSn/EQsylF3srWnTYex9st3vJ/67ZPI= 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:6808:1308:b0:486:503a:ce99 with SMTP id 5614622812f47-4a47282f4f9mr1607821b6e.27.1784020990301; Tue, 14 Jul 2026 02:23:10 -0700 (PDT) Date: Tue, 14 Jul 2026 02:23:10 -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: <6a55fffe.c90005c7.37d349.001d.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 logic from hfsplus_fill_super() into a new helper hfsplus_create_hidden_dir() and call it from hfsplus_reconfigure() when switching to read-write mode and hidden_dir is NULL, ensuring hidden_dir is always valid on any read-write mount. Reported-by: syzbot+c0ba772a362e70937dfb@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c0ba772a362e70937dfb Signed-off-by: Deepanshu Kartikey --- Changes in v6: - Use single mutex_unlock() in error path of helper. - Rename label out_put_hidden_dir to out inside helper. - Use QSTR_INIT() in both fill_super and reconfigure. - Add hfsplus_prepare_volume_header_for_commit() and hfsplus_sync_fs() before creating hidden dir in reconfigure to avoid inconsistent state on crash, as suggested by Vyacheslav Dubeyko. Changes in v5: - Pass str as input argument to hfsplus_create_hidden_dir() to avoid duplication, as suggested by Vyacheslav Dubeyko. - Use !(fc->sb_flags & SB_RDONLY) as guard in reconfigure instead of !sb_rdonly(sb). - Restore cancel_delayed_work_sync() in cleanup path. - Restore HFSPLUS_CAT_TREE_I dirty mark. 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 | 100 ++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index 40a0feda716b..56138881c35f 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -375,6 +375,52 @@ static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf) return 0; } +static int hfsplus_create_hidden_dir(struct super_block *sb, + const struct qstr *str) +{ + struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb); + struct inode *root = d_inode(sb->s_root); + int err; + + mutex_lock(&sbi->vh_mutex); + sbi->hidden_dir = hfsplus_new_inode(sb, root, S_IFDIR); + if (!sbi->hidden_dir) { + err = -ENOMEM; + goto out; + } + + err = hfsplus_create_cat(sbi->hidden_dir->i_ino, root, + str, sbi->hidden_dir); + if (err) + goto out; + + 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); + goto out; + } + + mutex_unlock(&sbi->vh_mutex); + hfsplus_mark_inode_dirty(HFSPLUS_CAT_TREE_I(sb), + HFSPLUS_I_CAT_DIRTY); + hfsplus_mark_inode_dirty(sbi->hidden_dir, + HFSPLUS_I_CAT_DIRTY); + return 0; + +out: + mutex_unlock(&sbi->vh_mutex); + cancel_delayed_work_sync(&sbi->sync_work); + 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; @@ -403,6 +449,18 @@ static int hfsplus_reconfigure(struct fs_context *fc) sb->s_flags |= SB_RDONLY; fc->sb_flags |= SB_RDONLY; } + + /* + * Create hidden dir if remounting read-write and it + * does not exist - required for link/unlink/rename. + */ + if (!(fc->sb_flags & SB_RDONLY) && !sbi->hidden_dir) { + struct qstr str = QSTR_INIT(HFSP_HIDDENDIR_NAME, + sizeof(HFSP_HIDDENDIR_NAME) - 1); + hfsplus_prepare_volume_header_for_commit(vhdr); + hfsplus_sync_fs(sb, 1); + return hfsplus_create_hidden_dir(sb, &str); + } } return 0; } @@ -589,8 +647,8 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc) goto out_put_alloc_file; } - str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1; - str.name = HFSP_HIDDENDIR_NAME; + str = (struct qstr)QSTR_INIT(HFSP_HIDDENDIR_NAME, + sizeof(HFSP_HIDDENDIR_NAME) - 1); err = hfsplus_get_hidden_dir_entry(sb, &str, &entry); if (err == -ENOENT) { /* @@ -620,40 +678,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, &str); + 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(HFSPLUS_CAT_TREE_I(sb), - HFSPLUS_I_CAT_DIRTY); - hfsplus_mark_inode_dirty(sbi->hidden_dir, - HFSPLUS_I_CAT_DIRTY); } } @@ -661,9 +688,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