Re: [PATCH] vhost/net: bound the count of VHOST_SET_FEATURES_ARRAY
From: Michael S. Tsirkin
Date: Sun Nov 22 2026 - 14:14:22 EST
On Sun, Nov 22, 2026 at 09:38:29AM -0500, Hengyu Liang wrote:
> On Sun, Nov 22, 2026 at 09:25:37AM -0500, Michael S. Tsirkin wrote:
> > this is followed by:
> >
> > virtio_features_zero(all_features);
> > argp += sizeof(u64);
> > copied = min(count, (u64)VIRTIO_FEATURES_U64S);
> > if (copy_from_user(all_features, argp, copied * sizeof(u64)))
> > return -EFAULT;
> >
> > copies at most 8 bytes.
> >
> >
> > did you test that this patch actually helps anything?
>
> That first copy is bounded, yes. The unbounded part is the loop right
> after it, which is outside the diff context:
>
> for (i = copied; i < count; ++i) {
> if (copy_from_user(&features, featurep + 1 + i,
> sizeof(features)))
> return -EFAULT;
> if (features)
> return -EOPNOTSUPP;
> }
I see. So all it is doing is checking that these features
are > 0 and erroring out.
Let's just not do it - we don't have to.
> It reads one u64 per iteration up to the count from user space. With
> count = U64_MAX and a large zero-filled mapping, it only stops at the
> first unreadable address.
>
> Yes, I tested it, on the vhost tree at 44293796526f (KASAN + lockdep),
> count = U64_MAX:
>
> 1 GiB zero-filled mapping:
> without the patch: EFAULT after 27.4 s
> with the patch: E2BIG at once
>
> 2 GiB mapping, SIGKILL sent 1 s into the ioctl:
> without the patch: the process is reaped 46.7 s after the kill
> with the patch: the ioctl has already returned
>
> I have a small reproducer (a few lines of C). Since I found this with
> the help of an LLM, Documentation/process/security-bugs.rst asks me to
> treat it as public and not post the reproducer to a public list, so I
> have not included it here. I am happy to send it to you off-list if it
> would help.
>
> Thanks,
> Hengyu