makefs: Fix 32-bit issues in ZFS time attributes setting
authorJessica Clarke <jrtc27@FreeBSD.org>
Thu, 18 Aug 2022 01:46:27 +0000 (02:46 +0100)
committerJessica Clarke <jrtc27@FreeBSD.org>
Thu, 18 Aug 2022 01:46:27 +0000 (02:46 +0100)
commitb0ce7dfc5e28650980d52f45aadd79e10012c291
treee270d19502fe3c381b64bbbc4c22f89452161c8a
parent2541dcaf4430a7d732c73b8f9190791e85c79b1c
makefs: Fix 32-bit issues in ZFS time attributes setting

Currently the code copies a struct timespec's raw bits as a pair of
uint64_t. On 64-bit systems this has the same representation, but on
32-bit issues there are two issues:

1. tv_sec is a time_t which is 32-bit on i386 specifically
2. tv_nsec is a long not a 64-bit integer

On i386, this means the assertion should fire as the size doesn't match.
On other 32-bit systems there are 4 bytes of padding after tv_nsec,
which in practice are probably 0, as this data is ultimately coming from
the kernel, so it's deterministic (though the padding bytes are not
required to be preserved by the compiler, so are strictly unspecified).
However, on 32-bit big-endian systems, the padding bytes are in the
wrong half to be harmless, resulting in the nanoseconds being multiplied
by 2^32.

Fix this all by marshalling via a real uint64_t pair like is done by the
real ZFS_TIME_ENCODE.

Reviewed by: markj
Fixes: 240afd8c1fcc ("makefs: Add ZFS support")
Differential Revision: https://reviews.freebsd.org/D36131
usr.sbin/makefs/zfs/fs.c