Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern rasctl(2): Avoid overflow in address range arithmetic.
details: https://anonhg.NetBSD.org/src/rev/de91bd4987a8
branches: trunk
changeset: 368765:de91bd4987a8
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Aug 03 09:40:25 2022 +0000
description:
rasctl(2): Avoid overflow in address range arithmetic.
Remove various contortions to suppress warnings. Rely on
-Wno-type-limits instead.
Reported-by: syzbot+8b0f1ced3fce82031535%syzkaller.appspotmail.com@localhost
https://syzkaller.appspot.com/bug?id=e9055200701cffd653d5b13491d85c34e07f06a3
diffstat:
sys/kern/kern_ras.c | 25 ++++++-------------------
1 files changed, 6 insertions(+), 19 deletions(-)
diffs (55 lines):
diff -r 9e65c18677ec -r de91bd4987a8 sys/kern/kern_ras.c
--- a/sys/kern/kern_ras.c Wed Aug 03 09:37:36 2022 +0000
+++ b/sys/kern/kern_ras.c Wed Aug 03 09:40:25 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ras.c,v 1.40 2019/12/14 16:58:25 riastradh Exp $ */
+/* $NetBSD: kern_ras.c,v 1.41 2022/08/03 09:40:25 riastradh Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.40 2019/12/14 16:58:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.41 2022/08/03 09:40:25 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -156,14 +156,6 @@
#if defined(__HAVE_RAS)
-#if __GNUC_PREREQ__(4, 8)
-#define __WARNING_PUSH_LESS_NULL_PTR _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wextra\"")
-#define __WARNING_POP_LESS_NULL_PTR _Pragma("GCC diagnostic pop")
-#else
-#define __WARNING_PUSH_LESS_NULL_PTR
-#define __WARNING_POP_LESS_NULL_PTR
-#endif
-
/*
* Install the new sequence. If it already exists, return
* an error.
@@ -180,17 +172,12 @@
if (len == 0)
return EINVAL;
- endaddr = (char *)addr + len;
-
- /* Do not warn about < NULL pointer comparison */
- __WARNING_PUSH_LESS_NULL_PTR
- if (addr < (void *)VM_MIN_ADDRESS || addr > (void *)VM_MAXUSER_ADDRESS)
+ if ((uintptr_t)addr < VM_MIN_ADDRESS ||
+ (uintptr_t)addr > VM_MAXUSER_ADDRESS)
return EINVAL;
- if (endaddr > (void *)VM_MAXUSER_ADDRESS)
+ if (len > VM_MAXUSER_ADDRESS - (uintptr_t)addr)
return EINVAL;
- if (endaddr < addr)
- return EINVAL;
- __WARNING_POP_LESS_NULL_PTR
+ endaddr = (char *)addr + len;
newrp = kmem_alloc(sizeof(*newrp), KM_SLEEP);
newrp->ras_startaddr = addr;
Home |
Main Index |
Thread Index |
Old Index