Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Avoid undefined behavior in lwp_ctl_alloc()



details:   https://anonhg.NetBSD.org/src/rev/e07e5affe482
branches:  trunk
changeset: 324459:e07e5affe482
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 04 18:13:01 2018 +0000

description:
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>

diffstat:

 sys/kern/kern_lwp.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 365a370c9021 -r e07e5affe482 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Wed Jul 04 17:50:18 2018 +0000
+++ b/sys/kern/kern_lwp.c       Wed Jul 04 18:13:01 2018 +0000
@@ -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 @@
                        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;



Home | Main Index | Thread Index | Old Index