Page MenuHomeFreeBSD

nfsclient: Avoid copying uninitialized bytes into statfs
ClosedPublic

Authored by markj on Jul 13 2021, 10:45 PM.
Tags
None
Referenced Files
F157030157: D31167.id92236.diff
Mon, May 18, 1:09 AM
F157024306: D31167.id92161.diff
Mon, May 18, 12:24 AM
F157024222: D31167.id92236.diff
Mon, May 18, 12:24 AM
F157020359: D31167.diff
Sun, May 17, 11:59 PM
F156988926: D31167.id92161.diff
Sun, May 17, 8:12 PM
F156927541: D31167.id.diff
Sun, May 17, 10:19 AM
Unknown Object (File)
Mon, May 11, 12:24 AM
Unknown Object (File)
Sat, May 2, 10:03 AM
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.