From 11e104c50f443e34435715acbb7b58c3d9252bf5 Mon Sep 17 00:00:00 2001 From: Don Lewis Date: Mon, 12 May 2014 20:22:42 +0000 Subject: [PATCH] Be even more paranoid about overflow. Requested by: ache --- sys/kern/subr_rman.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c index b53030a5574b..4101c867a8b1 100644 --- a/sys/kern/subr_rman.c +++ b/sys/kern/subr_rman.c @@ -466,8 +466,8 @@ rman_reserve_resource_bound(struct rman *rm, u_long start, u_long end, } amask = (1ul << RF_ALIGNMENT(flags)) - 1; - if (start + amask < start) { - DPRINTF(("start+amask wrapped around\n")); + if (start > ULONG_MAX - amask) { + DPRINTF(("start+amask would wrap around\n")); goto out; } @@ -487,8 +487,8 @@ rman_reserve_resource_bound(struct rman *rm, u_long start, u_long end, s->r_start, end)); break; } - if (s->r_start + amask < s->r_start) { - DPRINTF(("s->r_start (%#lx) + amask (%#lx) wrapped\n", + if (s->r_start > ULONG_MAX - amask) { + DPRINTF(("s->r_start (%#lx) + amask (%#lx) too large\n", s->r_start, amask)); break; }