From nobody Sun Feb 8 05:29:17 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 CFF04345CA3 for ; Sun, 1 Feb 2026 13:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769951559; cv=none; b=NR07DqqaBmZEkuYb1l6VvhxKJcCcV+45FYmJdSP6/1DFv7aoKAdfTDu2tfmfHW6gSSKW9LObR11pvSNaQkKkfdoIn+OZ5EIm2wOqYAdIcc6gVRdm/Z/81AzfhoUCMqxUdWdCoODMNn80s58LYt97hIGAoUNeu3As7nxhxPtmGhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769951559; c=relaxed/simple; bh=JXeaXtpB82Xtgp9hOcE4hSwkhfWEypULlw6HciVzaxE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=FBKLsm7Kg2tzvH5GR9GQ/ZoHuo5Gh9jUKZTrJ2FIuoX5IWIi9JDsWgnELGi6XqIyhOwjlMy+2Gu2fYJh53hzvvYBXDUGott2csj/xv41FmGtxKbYwoVHah5qb7t5+G2p+irTG78+ZNr+PFfWR8FFULA/NGWTakBuCbpNqXqhtXw= 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=FtZtPBbZ; arc=none smtp.client-ip=209.85.215.182 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="FtZtPBbZ" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c5513f598c0so1460492a12.0 for ; Sun, 01 Feb 2026 05:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769951557; x=1770556357; 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=ts58/HVJVntlC9t6K8nf8iDwbH90uPeoGmbeeGFT5Mo=; b=FtZtPBbZYobcFUERc+ZEfA8p2WMjoP8SzuYoJwRjoqfqznYIifaBxeXMZ2yIcEbC4i v05UHBgaXzus0fyFYwsF8E3txE17ngops/bc/x8zIsf2CoerpycBZDfRV+Zm7qHKCB1U DXKnsRrIYq/9+zs9hl3mpJQ0aHyztw7VcSkbaXYkJW8ZoxXuxtoPD0WlhhRcN5D9VXbS kp9SZlT6tam/TgdSB9iSqIO0PNSTWNMAZNDCD5RRmSIuIQikPgBMKZk8QhAr4kjOfyYT rf1Ays7a4Pl5TMV5rWm+02jLBooypsuAN2Ru8DlFFeQoz9pyU27+ibvvMVpxsGF13oyo ro8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769951557; x=1770556357; 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=ts58/HVJVntlC9t6K8nf8iDwbH90uPeoGmbeeGFT5Mo=; b=RcnsytVv/llinkORloI2O4d7xBRq05Hkx6h3B5TXvmguE3wLJuh9FtQmRlQChXPqY9 gNeI8ZRt4Xippv88AL2bhuJoO2fw5kxTUoE7Et5fZe4wR7MFIz1c5cQxXRjq9TmcFHpl KUl3fiPqwgPjFp4SGbKqDS3a0RmJoWnsGWCQFOa85DT4r/0Tt/+YzzUnm0WQR579scYS 494RAplG1WeTQYfTZncu10hB/X6/NdDbryubqqCzcPVZq4ZIEJpkkmeQdpVhuQ/3m1vd PC89TpK6ZC++07/cWSs9CmiWzH4xWqPzQYtbHAT/XGlPGFBDpl9hVa6wisBz7YY+QPMV pSsw== X-Forwarded-Encrypted: i=1; AJvYcCVgbWIfoBaj8sERkP/Fq9Fa1ByoEjjKbus2VxO8v3ZNwbtQcJOoJ6NJjR/LxfkMni42SlAGR+EM+yGLWOI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9h92Ln0YYxHbzO+J76JjhPgLOIxDkiAGrdRjHIh8yg2z4choM sQSxou19OzCFrZ1m1laXRof8rSf6THnwZ7MTOZMTmZB5dgHZaKWbKvlh X-Gm-Gg: AZuq6aKm6skBZaqHL3lyTB59cNHdPxNX16n3CIn3yRQtpLuerPpX2U8VqylfV7CDbRs O3dYhOkebR/tuzfRDFIM4bc53rxx3hoSPXqQDUIq2wSRKQ1N6ubt42OCJhR06IkPSSe8U4xoS5y L5cV9WB8oCsuNry/c29j20ctG01vgS8J9kqBRK6rj/u49EUPTAsnjSLsd6j1XeSvjDq/mAJF4ID cBXJrnm3DCtX+j0BwaxBNgCs6FYXiy4i2/sSHBISFDBnjRDNLaqJvTreNbJzS3IOduYzh86VNvQ 5f1K5+FuqfX7feCQRabew7/rqHDZLTYz/AZbg7U6ptArUdCxMPL+f8hsgTTKD+Li/kw1ivUVffW gwp+6zjxskv5DH2DaYhnLWkdej7X6hxzYQ4lTmLMchg32HsZ/1HbXIQD40BuWtun6MHVpoySbD2 uBmydnWEEbvs1vaYv3mbpDFWbUxk/lObLob34JUME= X-Received: by 2002:a17:903:11ce:b0:2a7:d93a:a3b2 with SMTP id d9443c01a7336-2a8d8951448mr96558255ad.0.1769951557039; Sun, 01 Feb 2026 05:12:37 -0800 (PST) Received: from Shardul.tailddf38c.ts.net ([223.185.36.73]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a88b4c3df6sm121636485ad.49.2026.02.01.05.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 05:12:36 -0800 (PST) From: Shardul Bankar X-Google-Original-From: Shardul Bankar To: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, brauner@kernel.org, janak@mpiricsoftware.com, shardulsb08@gmail.com, Shardul Bankar , syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com Subject: [PATCH v2] hfsplus: fix s_fs_info leak on mount setup failure Date: Sun, 1 Feb 2026 18:42:29 +0530 Message-Id: <20260201131229.4009115-1-shardul.b@mpiricsoftware.com> X-Mailer: git-send-email 2.34.1 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" Syzkaller reported a memory leak in hfsplus where s_fs_info (sbi) is allocated in hfsplus_init_fs_context() but never freed if the mount setup fails during setup_bdev_super(). In get_tree_bdev_flags(), if setup_bdev_super() fails, the superblock is torn down via deactivate_locked_super(). Since this failure occurs before fill_super() is called, the superblock's operations (sb->s_op) are not yet set. Consequently, the standard ->put_super() callback cannot be invoked, and the allocated s_fs_info remains leaked. Fix this by implementing a custom ->kill_sb() handler, hfsplus_kill_sb(), which explicitly frees s_fs_info using RCU synchronization. This ensures cleanup happens regardless of whether fill_super() succeeded or ->put_super() was called. To support this new lifecycle: 1. In hfsplus_put_super(), remove the call_rcu() call. The actual freeing of s_fs_info is deferred to hfsplus_kill_sb(). 2. In hfsplus_fill_super(), remove the explicit cleanup of sbi (both kfree and unload_nls) in the error path. The VFS will call ->kill_sb() on failure, so retaining these would result in double-frees or refcount underflows. 3. Implement hfsplus_kill_sb() to invoke kill_block_super() and then free s_fs_info via RCU. Reported-by: syzbot+99f6ed51479b86ac4c41@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D99f6ed51479b86ac4c41 Signed-off-by: Shardul Bankar --- v1: - tried to fix the leak in fs/super.c (VFS layer). - Link: https://lore.kernel.org/all/20260201082724.GC3183987@ZenIV/ v2: - abandons the VFS changes in favor of a driver-specific fix in hfsplus, implementing a custom ->kill_sb() to handle the cleanup lifecycle, as suggested by Al Viro. fs/hfsplus/super.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index aaffa9e060a0..cc80cd545a3e 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -311,14 +311,6 @@ void hfsplus_mark_mdb_dirty(struct super_block *sb) spin_unlock(&sbi->work_lock); } =20 -static void delayed_free(struct rcu_head *p) -{ - struct hfsplus_sb_info *sbi =3D container_of(p, struct hfsplus_sb_info, r= cu); - - unload_nls(sbi->nls); - kfree(sbi); -} - static void hfsplus_put_super(struct super_block *sb) { struct hfsplus_sb_info *sbi =3D HFSPLUS_SB(sb); @@ -344,7 +336,6 @@ static void hfsplus_put_super(struct super_block *sb) hfs_btree_close(sbi->ext_tree); kfree(sbi->s_vhdr_buf); kfree(sbi->s_backup_vhdr_buf); - call_rcu(&sbi->rcu, delayed_free); =20 hfs_dbg("finished\n"); } @@ -648,9 +639,7 @@ static int hfsplus_fill_super(struct super_block *sb, s= truct fs_context *fc) kfree(sbi->s_vhdr_buf); kfree(sbi->s_backup_vhdr_buf); out_unload_nls: - unload_nls(sbi->nls); unload_nls(nls); - kfree(sbi); return err; } =20 @@ -709,10 +698,27 @@ static int hfsplus_init_fs_context(struct fs_context = *fc) return 0; } =20 +static void delayed_free(struct rcu_head *p) +{ + struct hfsplus_sb_info *sbi =3D container_of(p, struct hfsplus_sb_info, r= cu); + + unload_nls(sbi->nls); + kfree(sbi); +} + +static void hfsplus_kill_sb(struct super_block *sb) +{ + struct hfsplus_sb_info *sbi =3D sb->s_fs_info; + + kill_block_super(sb); + if (sbi) + call_rcu(&sbi->rcu, delayed_free); +} + static struct file_system_type hfsplus_fs_type =3D { .owner =3D THIS_MODULE, .name =3D "hfsplus", - .kill_sb =3D kill_block_super, + .kill_sb =3D hfsplus_kill_sb, .fs_flags =3D FS_REQUIRES_DEV, .init_fs_context =3D hfsplus_init_fs_context, }; --=20 2.34.1