Module Name:    src
Committed By:   kamil
Date:           Wed Jul  4 18:13:01 UTC 2018

Modified Files:
        src/sys/kern: kern_lwp.c

Log Message:
Avoid undefined behavior in lwp_ctl_alloc()

Do not left shift signed integer in a way that the signedness bit is
changed.

sys/kern/kern_lwp.c:1849:27, 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.192 -r1.193 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.192 src/sys/kern/kern_lwp.c:1.193
--- src/sys/kern/kern_lwp.c:1.192	Mon Apr 23 15:51:00 2018
+++ src/sys/kern/kern_lwp.c	Wed Jul  4 18:13:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.192 2018/04/23 15:51:00 christos Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.193 2018/07/04 18:13:01 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.192 2018/04/23 15:51:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.193 2018/07/04 18:13:01 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1846,7 +1846,7 @@ lwp_ctl_alloc(vaddr_t *uaddr)
 			i = 0;
 	}
 	bit = ffs(lcp->lcp_bitmap[i]) - 1;
-	lcp->lcp_bitmap[i] ^= (1 << bit);
+	lcp->lcp_bitmap[i] ^= (1U << bit);
 	lcp->lcp_rotor = i;
 	lcp->lcp_nfree--;
 	l->l_lcpage = lcp;

Reply via email to