Page MenuHomeFreeBSD

libnv: fix heap overflow in nvlist_recv()
ClosedPublic

Authored by oshogbo on Apr 10 2026, 9:28 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 7, 5:41 PM
Unknown Object (File)
Thu, Jun 4, 8:56 PM
Unknown Object (File)
Thu, Jun 4, 12:08 PM
Unknown Object (File)
Thu, Jun 4, 12:08 PM
Unknown Object (File)
Wed, Jun 3, 10:31 AM
Unknown Object (File)
Wed, Jun 3, 5:22 AM
Unknown Object (File)
Mon, May 18, 2:35 AM
Unknown Object (File)
Mon, May 18, 2:27 AM
Subscribers

Details

Summary

nvlist_check_header() validated nvlh_size for overflow before
performing conversion. An mallicous user can set
NV_FLAG_BIG_ENDIAN in the header and craft nvlh_size so that
the orginall value passes the check, but after the conversion the
sizeof(nvlist_header) + size can overflow.
This can lead to a heap buffer overflow.

Fixes: 36fa90dbde0060aacb5677d0b113ee168e839071

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 72505
Build 69388: arc lint + arc unit

Event Timeline

The commit log should include a "Fixes" tag. Presumably it also deserves an SA and a regression test?

Thanks for the review markj@

oshogbo edited the summary of this revision. (Show Details)
lib/libnv/tests/Makefile
6 ↗(On Diff #175905)

Why make it conditional on ASAN?

8 ↗(On Diff #175905)

Why not just add this test to the existing send_recv_test file?

lib/libnv/tests/nvlist_header_overflow_test.c
2 ↗(On Diff #175905)

Missing an SPDX license identifier.

43 ↗(On Diff #175905)

We should test both the little-endian and big-endian cases.

lib/libnv/tests/Makefile
6 ↗(On Diff #175905)

Because without ASAN this test will not detect the bug as the heap override is to small. In such case this will give a false-positive that everything works.

This is why I also moved this to separate file.

lib/libnv/tests/Makefile
6 ↗(On Diff #175905)

The other file has this NO_ASAN hack to accomplish the same goal, so I still don't see why it needs to be a separate file.

I think our tests should be run unconditionally, and we should just run our tests with ASAN enabled by default. One step at a time. The disadvantage of disabling the test when ASAN is not configured is that you don't get any coverage at all. If I run the test suite with UBSAN enabled instead, this test doesn't run, even though it could find a new bug.

lib/libnv/tests/Makefile
6 ↗(On Diff #175905)

Oh, thats fair point. Somehow I didn't realize we have NO_ASAN already in the test. Thats fair point. I will rewrite this.

Add little endian test. Merge files.

This revision is now accepted and ready to land.Apr 28 2026, 2:41 PM