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_free()



details:   https://anonhg.NetBSD.org/src/rev/e1236fdc357e
branches:  trunk
changeset: 833643:e1236fdc357e
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 04 18:15:27 2018 +0000

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

diffstat:

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

diffs (27 lines):

diff -r 60653207bf21 -r e1236fdc357e sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Wed Jul 04 18:13:01 2018 +0000
+++ b/sys/kern/kern_lwp.c       Wed Jul 04 18:15:27 2018 +0000
@@ -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 @@
        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) {



Home | Main Index | Thread Index | Old Index