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



details:   https://anonhg.NetBSD.org/src/rev/41f5e00e6f61
branches:  trunk
changeset: 991248:41f5e00e6f61
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 04 02:19:02 2018 +0000

description:
Avoid undefined behavior in pr_item_notouch_put()

Do not left shift a signed integer changing its signedness bit.

sys/kern/subr_pool.c:251:30, 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/subr_pool.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 4b8e0bcc607a -r 41f5e00e6f61 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Wed Jul 04 02:02:15 2018 +0000
+++ b/sys/kern/subr_pool.c      Wed Jul 04 02:19:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.222 2018/07/04 01:42:37 kamil Exp $    */
+/*     $NetBSD: subr_pool.c,v 1.223 2018/07/04 02:19:02 kamil Exp $    */
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.222 2018/07/04 01:42:37 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.223 2018/07/04 02:19:02 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -248,7 +248,7 @@
 {
        unsigned int idx = pr_item_notouch_index(pp, ph, obj);
        pool_item_bitmap_t *bitmap = ph->ph_bitmap + (idx / BITMAP_SIZE);
-       pool_item_bitmap_t mask = 1 << (idx & BITMAP_MASK);
+       pool_item_bitmap_t mask = 1U << (idx & BITMAP_MASK);
 
        KASSERT((*bitmap & mask) == 0);
        *bitmap |= mask;



Home | Main Index | Thread Index | Old Index