From nobody Tue Jun 16 18:01:53 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 55C20185B48 for ; Thu, 30 Apr 2026 02:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777514647; cv=none; b=bSl6d12XPU5QUDT+Bu7V8aAlV6UWLm5HVsyzvJ7YTgyTXYir5Y4P6l0SryPlb+ESsCMaVj0QtQn3gJGz6u/eiCRtnprq/8NOPCJ9mtdhMPltiS7uoG0syQx0EGXZRHHT8tEN02W+/9y1CQhUEshCvM1n2/yqPk3LspunxSaiR4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777514647; c=relaxed/simple; bh=BPlMwhuat8Z2DNDWGK62GNqN1Lw6WWTq4lLI/wwLvFU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nVwjvRTYMhKJDdZVCTyDq6oEHJjIkGu8FQAIqk7uSlEcJ2lVJPFTjbAz4bx/oAPipQf5z8SM5X0fZtebMqJumS2OlSAww11e5HU8Hmi3cFZQr0n7IPGiCRh1QKb5ILRfWtTITRm2ED3pvqAfDM4XhjuA80t3Xl6/bhTJahKqckc= 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=Gb5AC/GY; arc=none smtp.client-ip=209.85.210.181 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="Gb5AC/GY" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-82f6b592fc7so172693b3a.3 for ; Wed, 29 Apr 2026 19:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777514646; x=1778119446; 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; bh=cvrYR2j0ICuUKwoOORo2Jsr4bEEaaxRMCJzK85U8m3Y=; b=Gb5AC/GYZLDJHw3B23FMI9IFgPzhS0CSCo/gunbN/L9Do1Ba8ylJpxUeMWnu9Hh+7M mNfb8VrlCPk54nwBN/CMN7FBFyP+mkRPCVo6393C0OovJjw8FgN9TtgC/qzcqTzLo+QQ yS++NZfTgmy4pxQX4CLONrgz6g8CzGJ30VjDxhnoMfXUikGpRK5Wx2xuC8K7OLkVRCPR 3ouBHugenCcovpdCOdWrhS4A+4jBb2r1ZrRXlMzvjZfdLPzSSbJazqDE6HYMIZ8EyMGw QgMpgVw1Qga2+F5h1ByISr6Wp5KKyP1+3WfPTXyPfhqsRyoSHnURrsOXeP721t837KT4 a8yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777514646; x=1778119446; 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; bh=cvrYR2j0ICuUKwoOORo2Jsr4bEEaaxRMCJzK85U8m3Y=; b=DepXSUSC7UH1msAxl8EuEb5S1GgIk6Lunm2MztOadvrNtd0HzpLtDmliZU9INtVXil KlsQ9YGoCH1bWdYCdSGVKlrD1wSdSnjdAddIbcvhRDFdNLwStNxL4iGo8eJC86GisHK7 k8CsabbZKjul9K5b1SODPP1HjhSN0wFMSk89XPht61Wrx95YQvO1RIDZwU3mk+qqHnkv /yh7ce8V7s9JzJhmyvqDqtndtPHjByzgQVA+rLSWTdAC7fqZnfPYkv0oZusuTzbckbhF rpoNTubldLhbs8pFRg4ozbXbSnPtkPhGsPGZ/iLB/KD68BM0NjUTDmXdnrMGjxhW/Wrz EHcg== X-Forwarded-Encrypted: i=1; AFNElJ/upffpV3Pv/ulw1AGsRrpsa5lXyKlRarLkbr0v1nzzDMTQhS5VUkFzMSjTQgpm+McktMAXo0s25rCKnnE=@vger.kernel.org X-Gm-Message-State: AOJu0YxTPMIvsUSaaZjnf4KRXiXSTM4Y+PTOZheNT80CrpMZ2bnz6hFt 45bZkrv/1AOJpV2pZKyhqsRMCBrS/PzjkbEq5GS5JiePX9C3ACPcAWr7 X-Gm-Gg: AeBDiesSfuxgGS/tQgwcdznfcy6pAKtG1K70gG9L0Kh7fYSTcy1L6qwQFP+wFV6W97E AnZDl4UiIpSibKFcRJN0XbzIrX6GOOrv8Salco9xMYJoB26XoOXKd/3OaWF2cI/s9/135Doq6Nj 6RKZB5yigaG4WXK48OfmnLroDqGk6YVaezm5gfeLz8ZpevOg2m8e1VY4xWEnby6E9oD3ELWIhsR 2II4EKd1683NnGguiVHAD2SkA8KPJSF4cE1D/YjLfaWwysUXAQ43us6S//qtrSwazFNL3xA9zn5 5K9Hwn/DkKjko0X5TZlmip0E6Zpwt8lyma6RKDxpAG0h4taq7Gm41yoeZceEMFj1bWK0VEQqes8 DanmRTGEsyzVFwzHsex1L75+5HyslhoG8Mjf72qtCv6PrSFyzJhvvc8jbVM9Jx+EzJUV36YWZoM iJHnBX22WtcSHMzY5522fNZQ2YPbSwVsCdEBr9wJDcq5bH+PoUhln2+lEaGpiqMvmtYx85Xk14E OknueiPzfRfgd4wTg== X-Received: by 2002:a05:6a00:8007:b0:82d:24f:2509 with SMTP id d2e1a72fcca58-834fdb19a0emr1170284b3a.1.1777514645497; Wed, 29 Apr 2026 19:04:05 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:e9bf:615b:4859:6e22]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-834ed80ec94sm3431157b3a.52.2026.04.29.19.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 19:04:04 -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 v4] hfsplus: fix null-ptr-deref by creating hidden dir on remount rw Date: Thu, 30 Apr 2026 07:33:58 +0530 Message-ID: <20260430020358.111052-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 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=3Dc0ba772a362e70937dfb 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, stru= ct kstatfs *buf) return 0; } =20 +static int hfsplus_create_hidden_dir(struct super_block *sb) +{ + struct hfsplus_sb_info *sbi =3D HFSPLUS_SB(sb); + struct inode *root =3D d_inode(sb->s_root); + struct qstr str; + int err; + + str.len =3D sizeof(HFSP_HIDDENDIR_NAME) - 1; + str.name =3D HFSP_HIDDENDIR_NAME; + + 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); + return -ENOMEM; + } + + 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; + 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 =3D NULL; + return err; +} + static int hfsplus_reconfigure(struct fs_context *fc) { struct super_block *sb =3D fc->root->d_sb; + struct hfsplus_sb_info *sbi =3D HFSPLUS_SB(sb); =20 sync_filesystem(sb); if ((bool)(fc->sb_flags & SB_RDONLY) =3D=3D sb_rdonly(sb)) return 0; if (!(fc->sb_flags & SB_RDONLY)) { - struct hfsplus_sb_info *sbi =3D HFSPLUS_SB(sb); struct hfsplus_vh *vhdr =3D sbi->s_vhdr; =20 if (!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) { @@ -401,6 +445,12 @@ static int hfsplus_reconfigure(struct fs_context *fc) fc->sb_flags |=3D 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; } =20 @@ -595,38 +645,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); + 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(sbi->hidden_dir, - HFSPLUS_I_CAT_DIRTY); } } =20 @@ -634,9 +655,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