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)
Thu, Mar 7, 6:15 PM
Unknown Object (File)
Feb 12 2024, 12:24 AM
Unknown Object (File)
Jan 16 2024, 6:08 PM
Unknown Object (File)
Jan 14 2024, 4:40 AM
Unknown Object (File)
Dec 10 2023, 12:38 AM
Unknown Object (File)
Nov 19 2023, 3:16 PM
Unknown Object (File)
Nov 19 2023, 12:51 PM
Unknown Object (File)
Nov 17 2023, 3:33 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.