Re: [PATCH v2] fpga: dfl: Fix NULL pointer dereference in dfl_fpga_feature_devs_enumerate()

From: Xiang Mei

Date: Fri Dec 04 2026 - 17:02:23 EST


On Wed, Dec 2, 2026 at 8:48 PM Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx> wrote:
>
> On Mon, Nov 30, 2026 at 04:02:15PM -0700, Xiang Mei wrote:
> > From: Yang Zi <2959243019@xxxxxx>
> >
> > 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
>
> Have you hit the issue on any real device, or do you know which device
> has the all-unsupported feature header?
>
Thanks for your review!

I don't have DFL hardware, so no real device. I reproduced it in QEMU
with a stock -device ivshmem-plain bound to dfl-pci via
/sys/bus/pci/drivers/dfl-pci/new_id.

The all-unsupported header was a bad example - it's not the case I hit.
The real issue is that build_info_free() runs on both exits of
dfl_fpga_feature_devs_enumerate(), but the only INIT_LIST_HEAD() for
binfo->sub_features is inside parse_feature_fiu(). Any return from
parse_feature_list() before that point leaves build_info_free() walking
a {NULL, NULL} head.

What I hit is just a DFL region too small to contain a feature:
parse_feature_list() returns -EINVAL, then build_info_free() at
dfl.c:1608 dereferences NULL.

RIP: 0010:build_info_free (drivers/fpga/dfl.c:950)
RBX: 0000000000000000 <- binfo->sub_features.next
dfl_fpga_feature_devs_enumerate (drivers/fpga/dfl.c:1608)
cci_pci_probe (drivers/fpga/dfl-pci.c:337)
new_id_store / vfs_write / do_syscall_64

I left Yang Zi's wording as he wrote it. I'll send a v3 with the
confirmed case instead if you prefer.

Xiang

> > 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@xxxxxxxxxxxxxxx
> > Signed-off-by: Yang Zi <2959243019@xxxxxx>
> > Reported-by: co+9f3b5ea84e1e6799@xxxxxxx
> > Tested-by: Xiang Mei <xmei5@xxxxxxx>
> > Signed-off-by: Xiang Mei <xmei5@xxxxxxx>
> > ---
> > 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@xxxxxx/
> >
> > 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
> >
> >