From 8b1925f29c54f5791db3c8dcdf2b67541bb8ab32 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 11 Mar 2024 14:15:10 -0600 Subject: [PATCH] kboot: Avoid UB in signed shift offset is signed. Copy it to the unsigned res before shifting. This avoids any possible undefined behavior for right shifting signed numbers. No functional change intended (and the code generated is the nearly same for aarch64). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44285 --- stand/kboot/kboot/hostfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stand/kboot/kboot/hostfs.c b/stand/kboot/kboot/hostfs.c index 02afa885d833..7c0600fc35a0 100644 --- a/stand/kboot/kboot/hostfs.c +++ b/stand/kboot/kboot/hostfs.c @@ -133,8 +133,9 @@ hostfs_seek(struct open_file *f, off_t offset, int whence) * from V7 later ISO-C). Also assumes we have to support powerpc still, * it's interface is weird for legacy reasons.... */ - offl = offset & 0xffffffff; - offh = (offset >> 32) & 0xffffffff; + res = (uint64_t)offset; + offl = res & 0xfffffffful; + offh = (res >> 32) & 0xfffffffful; err = host_llseek(hf->hf_fd, offh, offl, &res, whence); if (err < 0) return (err);