Page MenuHomeFreeBSD

libnv: Fix strict-aliasing violation with cookie
ClosedPublic

Authored by jilles on Oct 22 2017, 8:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 10, 5:53 PM
Unknown Object (File)
Thu, Dec 5, 12:38 AM
Unknown Object (File)
Tue, Nov 26, 7:10 PM
Unknown Object (File)
Oct 5 2024, 11:43 AM
Unknown Object (File)
Oct 4 2024, 4:10 PM
Unknown Object (File)
Oct 2 2024, 5:09 PM
Unknown Object (File)
Oct 2 2024, 5:09 PM
Unknown Object (File)
Oct 2 2024, 5:09 PM
Subscribers

Details

Summary

In rS323851, some casts were adjusted in calls to nvlist_next() and
nvlist_get_pararr() in order to make scan-build happy. I think these changes
just confused scan-build into not reporting the strict-aliasing violation.

For example, nvlist_xdescriptors() is causing nvlist_next() to write to its
local variable nvp of type nvpair_t * using the lvalue *cookiep of type
void *, which is not allowed. Given the APIs of nvlist_next(),
nvlist_get_parent() and nvlist_get_pararr(), one possible fix is to create a
local void *cookie in nvlist_xdescriptors() and other places, and to convert
the value to nvpair_t * when necessary. This patch implements that fix.

An rg '\(void\s*\*\*\)\s*&' finds many cases in the kernel where an
address of something is cast to void **, but only few in userland. This
matches that the kernel configures the compiler for a dialect of C without
type based aliasing restrictions (i.e., -fno-strict-aliasing), but userland
does not.

Test Plan

Install world and kernel in a VM and run lib/libnv and lib/libcasper tests.
All tests passed except the cap_dns ones which failed the same way as
unpatched (because my VM does not have a direct network connection).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Oct 25 2017, 7:24 PM
This revision was automatically updated to reflect the committed changes.