Page MenuHomeFreeBSD

nfsclient: Avoid copying uninitialized bytes into statfs
ClosedPublic

Authored by markj on Jul 13 2021, 10:45 PM.
Tags
None
Referenced Files
F106099003: D31167.diff
Wed, Dec 25, 9:28 AM
Unknown Object (File)
Tue, Dec 10, 5:02 AM
Unknown Object (File)
Nov 14 2024, 1:12 PM
Unknown Object (File)
Oct 7 2024, 11:35 PM
Unknown Object (File)
Sep 27 2024, 1:17 PM
Unknown Object (File)
Sep 24 2024, 11:48 AM
Unknown Object (File)
Sep 23 2024, 2:27 PM
Unknown Object (File)
Sep 22 2024, 5:30 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
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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.