Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Apr 2024 20:13:32 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d18377cbb723 - stable/14 - kboot: Avoid UB in signed shift
Message-ID:  <202404162013.43GKDWlP039797@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=d18377cbb7233ca9a468728596718884c64d6cb1

commit d18377cbb7233ca9a468728596718884c64d6cb1
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-03-11 20:15:10 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 19:54:29 +0000

    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
    
    (cherry picked from commit 8b1925f29c54f5791db3c8dcdf2b67541bb8ab32)
---
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404162013.43GKDWlP039797>