From nobody Sat Jul 25 05:17:28 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 92C65418A3A for ; Fri, 17 Jul 2026 13:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784296639; cv=none; b=OEGitWPn1kkUz4vkcEwk0I3dJfrD/ET7WV9W2KmMNBPEJxrXi/hQDIoRYKYwDy+/vm9hWbYI8rE9djRvdO9k5E1DT2ckuP0FOB5G6dDITmp2sylSwOZkNKpiAmo1wjlFT8/OwiaoEWYuZFC3px3o899sMMYXktHV8lOiHmyUQ94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784296639; c=relaxed/simple; bh=caOKfx6B2XcA3ehRz8C1l7+eNtvfKH4daoD9G2NW1zQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZyuyLfBc5By14S+ZXg89SoNlfbKWdkdEp1TfJZhME0NQttLkoOX45TtOF31Fs2KbvgZWQ2Kmx4bbuLYd0m/ckr98aaJyxKoFh+oo39lQNCNA5bNs1GBwH+TSoW/MoQ9VYYz6s+xkUYgpe8+xkXi0eKCmdazKy3K6UooDPlGJ+c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZJQX+QAC; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZJQX+QAC" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-381c51fde6bso7780359a91.2 for ; Fri, 17 Jul 2026 06:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784296637; x=1784901437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Zt4gTOHlvvJNaD8TVC3OR3v/eBR3xfE1fkkvJ/nYdqs=; b=ZJQX+QACImV+g7x6PEqU+c947qN42A1QvxQauAmiNd5PkWpCMtYnYY42+fdo2Z6bag 486QhQ4LZSEQAatFRqDuXNFhbngQ+rhPAD+S3kQSTOz79gVqlJeDTNidHhyol8+YnHEp BpybEOLPRcL28NrL6Harcvv5/9tMlPnyACL8xM8SZmGqdWr6RogqvUr855/0T9yze4Lc HMuvXqLsP3m58fiUjt5/eaiTk8FlHg9VNQY6qAbwoYvUzj/57OUreVuWpdwOjnJ2veBA 2VLqttzhQGBP9W7tbM3PcZXIJJqrXxN0URuu+4QqCewYa2W1qPlRe8ZxIXVkeWaGb3An Z83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784296637; x=1784901437; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Zt4gTOHlvvJNaD8TVC3OR3v/eBR3xfE1fkkvJ/nYdqs=; b=g5L3PtKlXyobkD/VABKTZPL8kVvEISXoxN3GWV2emRsL90+/m38CZMvxltsiO6iZQO DeMXXHeSNghR3+aIOlDmSREmRH5iJGsyxFQNOUZiAUvNjfnUCMNGNrNu/pbmugg8RzeA ZfaErrA4Pjk12uMRBALiq1Q1zPJdM5N+j59ifHq2mlSxmAJHQgxA0ObLRX13eF+QUzyc aVsRzmN2Oa3vlul0qVZzj8bTSkqNnKklzUusgUucNopluEs3Jib48lmL6hk1XtyBkihm xk5WFEWtYZ8Lch352gehlLylgy1MTyqaZJ3zAwkBjKxIEASoqqnDVM2znTXSp9RnRVW/ Hc5Q== X-Forwarded-Encrypted: i=1; AHgh+Ro5UqLnsRpuLJOwMpuA/fKdnmCWrvq6YgH/dA/cnbQYc9zlaPKfMWIuEtsZCo8lyZoQ3FOc1zClBu+nkzY=@vger.kernel.org X-Gm-Message-State: AOJu0YxXJueRux74cxHR29Bym7MHiuw/uGYX4CrROq2UgpWQRhb1qP0q h2X+hkPWuTDn2Mw957N0MLYts/VGDY/MimEaPC8Z4mVz+dq4XSij/WB3 X-Gm-Gg: AfdE7cmqpvjO6hDFiANwSW3oNf7bDKZPTFQRXQ4vfPYhG4XIBpu8K880NZ3OTlFzbom 7qL9xONV+3JejY0s+3QUcZEd69orp2/84NfvUw4lIlsOo0e2tV93tXDrFrOLkpYKHBd+KrZA+5y /sZcZU6f/H57izmWA6T/T7btEx5NeTj/0AYaobmM5E7n5Irjf9K+UaL+FqgrIBZj+rdhr3yfWzJ 1feeJIbXAnHykKvQD5+SGuYnVZTfCTZOZjMZiyC4z53B3J2VgaVvP3UvWmsMBET6Oo7e4xpwcBQ gDPZRYBCGYIBNnTTdHzbWqnG0I4MYfAZyeTYnw1oslHKduIBHbrxw5Vv7jqX2Rkz38R0pyPrZQF mLoJRjQn8yS199cQaBfmSE3NMYAI2EldhVz2a+iQ7J4VUHVkyu0tCnkDFgcUcscezx6UdDbICap Foa8uYThM4UEtuuNjxGoh4KD5QSn5KMGvGERZOMc8ZDvp1Nhu/BoiPxOKgRw== X-Received: by 2002:a17:90b:2dcc:b0:38d:e0c4:c955 with SMTP id 98e67ed59e1d1-38e4b447015mr2905293a91.15.1784296636811; Fri, 17 Jul 2026 06:57:16 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:d901:b10d:5266:6c96]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31429f9d44fsm7009406eec.1.2026.07.17.06.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 06:57:16 -0700 (PDT) From: Deepanshu Kartikey To: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+c0ba772a362e70937dfb@syzkaller.appspotmail.com Subject: [PATCH v7] hfsplus: fix null-ptr-deref by creating hidden dir on remount rw Date: Fri, 17 Jul 2026 19:27:06 +0530 Message-ID: <20260717135706.42918-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3Dc0ba772a362e70937dfb Signed-off-by: Deepanshu Kartikey --- Changes in v7: - Call hfsplus_prepare_volume_header_for_commit() and hfsplus_sync_fs() for all rw remounts in reconfigure not just when hidden_dir is NULL, as suggested by Vyacheslav Dubeyko. - Remove redundant inner hidden_dir NULL check. 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 reconfigure and compound literal cast in fill_super. - 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 | 102 ++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index 40a0feda716b..3983e8160302 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -375,6 +375,52 @@ static int hfsplus_statfs(struct dentry *dentry, struc= t kstatfs *buf) return 0; } =20 +static int hfsplus_create_hidden_dir(struct super_block *sb, + const struct qstr *str) +{ + struct hfsplus_sb_info *sbi =3D HFSPLUS_SB(sb); + struct inode *root =3D d_inode(sb->s_root); + int err; + + mutex_lock(&sbi->vh_mutex); + sbi->hidden_dir =3D hfsplus_new_inode(sb, root, S_IFDIR); + if (!sbi->hidden_dir) { + err =3D -ENOMEM; + goto out; + } + + err =3D hfsplus_create_cat(sbi->hidden_dir->i_ino, root, + str, sbi->hidden_dir); + if (err) + goto out; + + err =3D hfsplus_init_security(sbi->hidden_dir, root, str); + if (err =3D=3D -EOPNOTSUPP) + err =3D 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 =3D NULL; + return err; +} + static int hfsplus_reconfigure(struct fs_context *fc) { struct super_block *sb =3D fc->root->d_sb; @@ -403,6 +449,20 @@ static int hfsplus_reconfigure(struct fs_context *fc) sb->s_flags |=3D SB_RDONLY; fc->sb_flags |=3D 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)) { + hfsplus_prepare_volume_header_for_commit(vhdr); + hfsplus_sync_fs(sb, 1); + if (!sbi->hidden_dir) { + struct qstr str =3D QSTR_INIT(HFSP_HIDDENDIR_NAME, + sizeof(HFSP_HIDDENDIR_NAME) - 1); + return hfsplus_create_hidden_dir(sb, &str); + } + } } return 0; } @@ -589,8 +649,8 @@ static int hfsplus_fill_super(struct super_block *sb, s= truct fs_context *fc) goto out_put_alloc_file; } =20 - str.len =3D sizeof(HFSP_HIDDENDIR_NAME) - 1; - str.name =3D HFSP_HIDDENDIR_NAME; + str =3D (struct qstr)QSTR_INIT(HFSP_HIDDENDIR_NAME, + sizeof(HFSP_HIDDENDIR_NAME) - 1); err =3D hfsplus_get_hidden_dir_entry(sb, &str, &entry); if (err =3D=3D -ENOENT) { /* @@ -620,40 +680,9 @@ static int hfsplus_fill_super(struct super_block *sb, = struct fs_context *fc) hfsplus_sync_fs(sb, 1); =20 if (!sbi->hidden_dir) { - mutex_lock(&sbi->vh_mutex); - sbi->hidden_dir =3D hfsplus_new_inode(sb, root, S_IFDIR); - if (!sbi->hidden_dir) { - mutex_unlock(&sbi->vh_mutex); - err =3D -ENOMEM; + err =3D hfsplus_create_hidden_dir(sb, &str); + if (err) goto out_put_root; - } - err =3D 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 =3D hfsplus_init_security(sbi->hidden_dir, - root, &str); - if (err =3D=3D -EOPNOTSUPP) - err =3D 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); } } =20 @@ -661,9 +690,6 @@ static int hfsplus_fill_super(struct super_block *sb, s= truct fs_context *fc) sbi->nls =3D nls; return 0; =20 -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 =3D NULL; --=20 2.43.0