git: 6186fe5673bb - main - freebsd32: Fix the ffclock estimate conversions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 22 Nov 2026 17:41:27 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=6186fe5673bb0352c5259fe9b69aff761f6da4e1
commit 6186fe5673bb0352c5259fe9b69aff761f6da4e1
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-22 15:30:14 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-22 17:41:07 +0000
freebsd32: Fix the ffclock estimate conversions
The CP() arguments were reversed in both directions, so
ffclock_getestimate() copied out uninitialized stack memory and
ffclock_setestimate() installed it as the system estimate.
Add helper functions to do the conversion, implemented so as to make
such mistakes harder to make.
Fixes: e3e811a3f824 ("freebsd32: add feed foward clock syscalls")
Reviewed by: brooks
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61774
---
sys/compat/freebsd32/freebsd32_misc.c | 58 +++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 37a29878dfb3..59aee5e80b14 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -4134,6 +4134,42 @@ extern struct mtx ffclock_mtx;
extern struct ffclock_estimate ffclock_estimate;
extern int8_t ffclock_updated;
+static void
+ffclock_estimate_from_32(struct ffclock_estimate *dst,
+ const struct ffclock_estimate32 *src)
+{
+ memset(dst, 0, sizeof(*dst));
+ CP(src->update_time, dst->update_time, sec);
+ memcpy(&dst->update_time.frac, &src->update_time.frac,
+ sizeof(uint64_t));
+ FU64_CP(*src, *dst, update_ffcount);
+ FU64_CP(*src, *dst, leapsec_next);
+ FU64_CP(*src, *dst, period);
+ CP(*src, *dst, errb_abs);
+ CP(*src, *dst, errb_rate);
+ CP(*src, *dst, status);
+ CP(*src, *dst, leapsec_total);
+ CP(*src, *dst, leapsec);
+}
+
+static void
+ffclock_estimate_to_32(struct ffclock_estimate32 *dst,
+ const struct ffclock_estimate *src)
+{
+ memset(dst, 0, sizeof(*dst));
+ CP(src->update_time, dst->update_time, sec);
+ memcpy(&dst->update_time.frac, &src->update_time.frac,
+ sizeof(uint64_t));
+ FU64_CP(*src, *dst, update_ffcount);
+ FU64_CP(*src, *dst, leapsec_next);
+ FU64_CP(*src, *dst, period);
+ CP(*src, *dst, errb_abs);
+ CP(*src, *dst, errb_rate);
+ CP(*src, *dst, status);
+ CP(*src, *dst, leapsec_total);
+ CP(*src, *dst, leapsec);
+}
+
int
freebsd32_ffclock_setestimate(struct thread *td,
struct freebsd32_ffclock_setestimate_args *uap)
@@ -4150,16 +4186,7 @@ freebsd32_ffclock_setestimate(struct thread *td,
sizeof(struct ffclock_estimate32))) != 0)
return (error);
- CP(cest.update_time, cest32.update_time, sec);
- memcpy(&cest.update_time.frac, &cest32.update_time.frac, sizeof(uint64_t));
- FU64_CP(cest, cest32, update_ffcount);
- FU64_CP(cest, cest32, leapsec_next);
- FU64_CP(cest, cest32, period);
- CP(cest, cest32, errb_abs);
- CP(cest, cest32, errb_rate);
- CP(cest, cest32, status);
- CP(cest, cest32, leapsec_total);
- CP(cest, cest32, leapsec);
+ ffclock_estimate_from_32(&cest, &cest32);
mtx_lock(&ffclock_mtx);
memcpy(&ffclock_estimate, &cest, sizeof(struct ffclock_estimate));
@@ -4180,16 +4207,7 @@ freebsd32_ffclock_getestimate(struct thread *td,
memcpy(&cest, &ffclock_estimate, sizeof(struct ffclock_estimate));
mtx_unlock(&ffclock_mtx);
- CP(cest32.update_time, cest.update_time, sec);
- memcpy(&cest32.update_time.frac, &cest.update_time.frac, sizeof(uint64_t));
- FU64_CP(cest32, cest, update_ffcount);
- FU64_CP(cest32, cest, leapsec_next);
- FU64_CP(cest32, cest, period);
- CP(cest32, cest, errb_abs);
- CP(cest32, cest, errb_rate);
- CP(cest32, cest, status);
- CP(cest32, cest, leapsec_total);
- CP(cest32, cest, leapsec);
+ ffclock_estimate_to_32(&cest32, &cest);
error = copyout(&cest32, uap->cest, sizeof(struct ffclock_estimate32));
return (error);