Module Name: src Committed By: kamil Date: Wed Jul 4 18:15:28 UTC 2018
Modified Files: src/sys/kern: kern_lwp.c Log Message: Avoid undefined behavior in lwp_ctl_free() Do not left shift signed integer in a way that the signedness bit is changed. sys/kern/kern_lwp.c:1892:29, left shift of 1 by 31 places cannot be represented in type 'int' Detected with Kernel Undefined Behavior Sanitizer. Reported by <Harry Pantazis> To generate a diff of this commit: cvs rdiff -u -r1.193 -r1.194 src/sys/kern/kern_lwp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_lwp.c diff -u src/sys/kern/kern_lwp.c:1.193 src/sys/kern/kern_lwp.c:1.194 --- src/sys/kern/kern_lwp.c:1.193 Wed Jul 4 18:13:01 2018 +++ src/sys/kern/kern_lwp.c Wed Jul 4 18:15:27 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lwp.c,v 1.193 2018/07/04 18:13:01 kamil Exp $ */ +/* $NetBSD: kern_lwp.c,v 1.194 2018/07/04 18:15:27 kamil Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -211,7 +211,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.193 2018/07/04 18:13:01 kamil Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.194 2018/07/04 18:15:27 kamil Exp $"); #include "opt_ddb.h" #include "opt_lockdebug.h" @@ -1889,7 +1889,7 @@ lwp_ctl_free(lwp_t *l) mutex_enter(&lp->lp_lock); lcp->lcp_nfree++; map = offset >> 5; - lcp->lcp_bitmap[map] |= (1 << (offset & 31)); + lcp->lcp_bitmap[map] |= (1U << (offset & 31)); if (lcp->lcp_bitmap[lcp->lcp_rotor] == 0) lcp->lcp_rotor = map; if (TAILQ_FIRST(&lp->lp_pages)->lcp_nfree == 0) {