Page MenuHomeFreeBSD

nfsclient: Avoid copying uninitialized bytes into statfs
ClosedPublic

Authored by markj on Jul 13 2021, 10:45 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jan 14, 8:31 AM
Unknown Object (File)
Tue, Jan 14, 8:29 AM
Unknown Object (File)
Sun, Jan 12, 11:48 AM
Unknown Object (File)
Dec 25 2024, 10:31 PM
Unknown Object (File)
Dec 25 2024, 9:40 PM
Unknown Object (File)
Dec 25 2024, 9:28 AM
Unknown Object (File)
Dec 10 2024, 5:02 AM
Unknown Object (File)
Nov 14 2024, 1:12 PM
Subscribers

Details

Summary

hst will be nul-terminated but may be followed by uninitialized bytes.
Avoid copying all of them since they are exported to userland via
statfs(2).

Reported by: KMSAN
MFC after: 2 weeks

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 40458
Build 37347: arc lint + arc unit

Event Timeline

This looks ok to me. It does assume that "mnt_stat" is initialized '0', but that is the case.

Alternately, you could add M_ZERO to the malloc() for hst, and then it doesn't matter
if mnt_stat is properly initialized.

I'll let you decide which you prefer.

This revision is now accepted and ready to land.Jul 13 2021, 11:45 PM

This looks ok to me. It does assume that "mnt_stat" is initialized '0', but that is the case.

Alternately, you could add M_ZERO to the malloc() for hst, and then it doesn't matter
if mnt_stat is properly initialized.

I'll let you decide which you prefer.

I thought about using M_ZERO but I think this approach is more internally consistent: there are other strings allocated when mounting that don't require M_ZERO, and NFS itself doesn't care whether the hostname buffer is zeroed.