Page MenuHomeFreeBSD

libnv: fix heap overflow in nvlist_recv()
ClosedPublic

Authored by oshogbo on Apr 10 2026, 9:28 AM.
Tags
None
Referenced Files
F156696075: D56342.id176313.diff
Fri, May 15, 6:10 PM
Unknown Object (File)
Fri, May 15, 11:09 AM
Unknown Object (File)
Thu, May 14, 2:47 PM
Unknown Object (File)
Thu, May 14, 9:43 AM
Unknown Object (File)
Thu, May 14, 12:32 AM
Unknown Object (File)
Thu, May 14, 12:32 AM
Unknown Object (File)
Wed, May 13, 11:51 PM
Unknown Object (File)
Wed, May 13, 11:32 PM
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 Not Applicable
Unit
Tests Not Applicable

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.Tue, Apr 28, 2:41 PM