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)
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
Unknown Object (File)
Sep 17 2024, 4:26 PM
Unknown Object (File)
Sep 17 2024, 7:36 AM
Unknown Object (File)
Sep 16 2024, 8:25 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.