From nobody Wed Apr 1 20:59:10 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 C68873DFC8C for ; Wed, 1 Apr 2026 10:56:32 +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=1775040994; cv=none; b=nSEoV466UFUs2+Y/zVmE5kbOUUrfoLgQwt+kToMFtFKcUhKcGbhPwQU6usR9NUEhVlcVPU3qn6m4Huc1HkOZvg7Makd6F4lhiSYPP2lGK0nAdGEjW8QCVzHn02G/teJHiHS6NEtKxuKc3Y/TiwyUpQt/X+Hd8kP9TBlPaTPJyew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775040994; c=relaxed/simple; bh=MyXYeM8EOJ+bWpDLvDHhshEwu7kHHDCWmI93VztoV1s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RTbsqwpFTWbGVeG6xgPsHlv2FvonLN/oVAxLOLZpiT1vGYsBMDeAdt6aoZEYA0ipF7r/wmojOZkA3CMOD86qwFg67VQTHYaIu9+O2uPuDyv7BQA9Y4exuqzZeKAANL/R45cUFrMh9LmWBRqQrFyXjgbhiHruJrEoeZelHzJgHlE= 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=rUinOOsy; 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="rUinOOsy" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3591cc98871so2958959a91.3 for ; Wed, 01 Apr 2026 03:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775040992; x=1775645792; 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=FmAkJIVOiyu2su4iByfPKFkvSEqhCvUzVY7v1mQwfiI=; b=rUinOOsyoZVrTFi8jkClv7cWjcfLOYBk/FI2/VPXzGCmXGnF+lY8ySybDZjU/PX+7m 0Jfgdv4WnTBW5ErbMFev/wD8UK7TNFpvX4K+MS81UnkL/Vso/XOsk00+02H8GXvHWVI6 iHs9IFDp5T1yF/wwxyuNl7VizZkywOCRKPltF3vQX+LQ0cz0ppJsLHLbsEytzXfrtyFi A+LqP9nff0dcu9tvL97hUA53PpNqk6a2pxtAirB8h7mB9jDBswkDVcA//bNykUBlyR4o RrW+YM1ym+47yhtrhHzccdwD8P/Jlab4yFxhNzUOG7YQ44inHOfDnVHz9qAwlFTzoJYo 5lMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775040992; x=1775645792; 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=FmAkJIVOiyu2su4iByfPKFkvSEqhCvUzVY7v1mQwfiI=; b=Xy/ddQ31aISGbuy82jspg8FwlurzyDQNGbmL+gBabUF/MIMpX+mOhfsiJ6rsL2v+7L /M/BZoL5COUIOhZDRASlImXqqlK+hVi1NeqUpxE1F2YsYsRGhGFdbs+FEiVKmV0kg2Lz sYiFT7mHrM3zRzgjZK9qtW+Egd/Ql9swY153NJf/lj8br6/ZNbK73wH0XVt+li85+X0z /+7ALx1A0pfR94k9+i3PhT54URHJHCYa+N0HuaahmP/bJ1s+UoN0pnqKmQDso8wuuHxC EBsCHlCGQsG9Cv/+YtlSYCyveR4qf2bbF36lmSWK/437KwL3oExyJYV9mGiYJ5FBV1kS 3y2g== X-Forwarded-Encrypted: i=1; AJvYcCXdGn8x8twPZSjU4Ktm3LxPenZ4/9FuKFJDXmaXMPOf/XmG61zy4lA/trl7N7bEMKDCqlAxTs3d7hfkTyE=@vger.kernel.org X-Gm-Message-State: AOJu0YwzKyHKJwaTgt83C7obzIijZjJoy/wKpmQuCvG5jMKxwUyTyG8F VW3uUJSrVYmyvnVLCy4udB2IqobreuuHZd3mlX1plC0ZIboTa4ytH6kE X-Gm-Gg: ATEYQzz5YaifJqLi2IobfRfPmhzZ0b/t8w/3E+rqGJDQxCtnVTV4xS70L9RvoC6ntUk BKKMdO3qvdgzHROrXk4Ykk+6ghZgAneCpXAxz4zhooRJVp+EUjUvXF92Z18FyxH/K2+Jg7p7UUY uGFV5uX5fnRSWCk/WYIQZUQtV4+cxo2a0IznZP32BVeGDF6EzYOfO5PoQYo/TOMhjT0Rk/WQjMb ot46BByrc2oDdb7OPuaaamaXHC69gjGzg6b3J/6eBrpsrk4AVlmfSkoM20iMhjo6yjH+WIZHqWI +kaqlOgdNq6HOWV9Jd9XFJ6CltlPNyCLksSqNeyoKRv02jZoL+M6O4oihlVOckrEmnsA1Kt050x YJDG/kMArqA2jiaF3yxbE/uBjgXj19WJqcJ0hSgfVXts6xw/PvW8Pp2qrIdwYcrD0dmjRr8dtCK z8vDIWiwsY7gZ08FjaRLjO X-Received: by 2002:a17:90b:510d:b0:35a:18b1:c239 with SMTP id 98e67ed59e1d1-35dc6e9a466mr2738424a91.10.1775040991785; Wed, 01 Apr 2026 03:56:31 -0700 (PDT) Received: from lgs.. ([223.80.110.53]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35dba63e80bsm1679868a91.4.2026.04.01.03.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 03:56:31 -0700 (PDT) From: Guangshuo Li To: Chris Mason , David Sterba , Qu Wenruo , Jiasheng Jiang , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Guangshuo Li , stable@vger.kernel.org Subject: [PATCH v2] btrfs: fix double free in create_space_info() error path Date: Wed, 1 Apr 2026 18:56:19 +0800 Message-ID: <20260401105619.1506398-1-lgs201920130244@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" When kobject_init_and_add() fails, the call chain is: create_space_info() -> btrfs_sysfs_add_space_info_type() -> kobject_init_and_add() -> failure -> kobject_put(&space_info->kobj) -> space_info_release() -> kfree(space_info) Then control returns to create_space_info(): btrfs_sysfs_add_space_info_type() returns error -> goto out_free -> kfree(space_info) This causes a double free. Keep the direct kfree(space_info) for the earlier failure path, but after btrfs_sysfs_add_space_info_type() has called kobject_put(), let the kobject release callback handle the cleanup. Fixes: a11224a016d6d ("btrfs: fix memory leaks in create_space_info() error= paths") Cc: stable@vger.kernel.org Reviewed-by: Qu Wenruo Signed-off-by: Guangshuo Li --- v2: - add the full failure path to the changelog fs/btrfs/space-info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 3f08e450f796..d7176eb2fcbf 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -311,7 +311,7 @@ static int create_space_info(struct btrfs_fs_info *info= , u64 flags) =20 ret =3D btrfs_sysfs_add_space_info_type(space_info); if (ret) - goto out_free; + return ret; =20 list_add(&space_info->list, &info->space_info); if (flags & BTRFS_BLOCK_GROUP_DATA) --=20 2.43.0