From: Yang Zi <2959243019@qq.com> The build_info struct (binfo) is zeroed by devm_kzalloc(), but its sub_features list head is not initialized there; INIT_LIST_HEAD() is only called later inside parse_feature_fiu(). If parsing ends without ever reaching parse_feature_fiu() (for example, when every feature header in the list is an unsupported type), binfo->sub_features is still all-zero instead of a valid empty list head. build_info_free() then runs list_for_each_entry_safe() over that list, which reads head->next == NULL and dereferences a NULL pointer. KASAN report: BUG: KASAN: null-ptr-deref in build_info_free drivers/fpga/dfl.c:950 [inline] BUG: KASAN: null-ptr-deref in dfl_fpga_feature_devs_enumerate+0x59ba/0x60d0 drivers/fpga/dfl.c:1611 Read of size 8 at addr 0000000000000000 by task syz.0.2/1096 Initialize binfo->sub_features right after allocating binfo so that build_info_free() and the other sub_features consumers always see a valid list head. Fixes: 59c265babab6 ("fpga: dfl: store platform device id in feature device data") Cc: stable@vger.kernel.org Signed-off-by: Yang Zi <2959243019@qq.com> Reported-by: co+9f3b5ea84e1e6799@bugs.sh Tested-by: Xiang Mei Signed-off-by: Xiang Mei --- v2 (resent by Xiang Mei on Yang Zi's behalf): - Fix the whitespace-damaged diff of v1 so it applies; code unchanged. - Add Fixes: and Cc: stable. I hit the same bug independently and reproduced it in QEMU (ivshmem-plain bound to dfl-pci via new_id); this patch fixes it. v1: https://lore.kernel.org/all/tencent_EFA15EDE0B67CF3347A9EFD9A05E6A620D08@qq.com/ drivers/fpga/dfl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index 6f5fa7b2fc54..700540ffd31e 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c @@ -1589,6 +1589,8 @@ dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info) goto unregister_region_exit; } + INIT_LIST_HEAD(&binfo->sub_features); + binfo->type = DFL_ID_MAX; binfo->dev = info->dev; binfo->cdev = cdev; -- 2.43.0