Page MenuHomeFreeBSD

ipfilter: Don't trust userland supplied iph_size
ClosedPublic

Authored by cy on Oct 22 2025, 11:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 8 2025, 2:50 AM
Unknown Object (File)
Nov 6 2025, 9:49 PM
Unknown Object (File)
Nov 4 2025, 5:38 PM
Unknown Object (File)
Nov 3 2025, 4:23 PM
Unknown Object (File)
Oct 31 2025, 1:07 AM
Unknown Object (File)
Oct 31 2025, 12:17 AM
Unknown Object (File)
Oct 27 2025, 3:58 AM
Unknown Object (File)
Oct 26 2025, 10:48 PM

Details

Summary

ipf_htable_create() trusts a user-supplied iph_size from iphtable_t
and computes the allocation size as iph->iph_size * sizeof(*iph->iph_table)
without checking for integer overflow. A sufficiently large iph_size
causes the multiplication to wrap, resulting in an under-sized allocation
for the table pointer array. Subsequent code (e.g., in ipf_htent_insert())
can then write past the end of the allocated buffer, corrupting kernel
memory and causing DoS or potential privilege escalation.

Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>
MFC after: 1 day

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cy requested review of this revision.Oct 22 2025, 11:35 PM
markj added inline comments.
sys/netpfil/ipfilter/netinet/ip_htable.c
367

Should we clamp the size to the maximum instead?

This revision is now accepted and ready to land.Oct 24 2025, 12:56 PM
cy marked an inline comment as done.Oct 24 2025, 11:34 PM
cy added inline comments.
sys/netpfil/ipfilter/netinet/ip_htable.c
367

Yes. To softh->ipf_htable_size_max. You're right the last test is extraneous.

But this patch is missing a part yet to be submitted.

cy marked an inline comment as done.

Fix the last of the issues Ilja Van Sprundel had identified in his
email regarding ip_htable.c.

Also address and fix a question by markj@.

This revision now requires review to proceed.Oct 24 2025, 11:39 PM

I really should have tested this before submitting the updated diff. I will test it now.

This review is still active.

sys/netpfil/ipfilter/netinet/ip_htable.c
369
374

I don't see why this cast is needed? iph_size is already a size_t.

cy marked an inline comment as done.

Removal of two size_t casts.

This revision is now accepted and ready to land.Oct 31 2025, 1:15 AM
This revision was automatically updated to reflect the committed changes.