diff options
author | alc <alc@FreeBSD.org> | 2011-12-07 07:03:14 +0000 |
---|---|---|
committer | alc <alc@FreeBSD.org> | 2011-12-07 07:03:14 +0000 |
commit | 93edaa86af569d5577e73cd279dca1030c442bb5 (patch) | |
tree | 853cee4e5ba95ecc267b4d9cde8149aedab21f07 /sys/kern/kern_malloc.c | |
parent | 35ed2c25b8ec93055876b08f910f8c92cac90de6 (diff) | |
download | FreeBSD-src-93edaa86af569d5577e73cd279dca1030c442bb5.zip FreeBSD-src-93edaa86af569d5577e73cd279dca1030c442bb5.tar.gz |
Eliminate the possibility of 32-bit arithmetic overflow in the calculation
of vm_kmem_size that may occur if the system administrator has specified a
vm.vm_kmem_size tunable value that exceeds the hard cap.
PR: 162741
Submitted by: Adam McDougall
Reviewed by: bde@
MFC after: 3 weeks
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r-- | sys/kern/kern_malloc.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 9b61ecd..cd6ca07 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -740,11 +740,11 @@ kmeminit(void *dummy) /* * Limit kmem virtual size to twice the physical memory. * This allows for kmem map sparseness, but limits the size - * to something sane. Be careful to not overflow the 32bit - * ints while doing the check. + * to something sane. Be careful to not overflow the 32bit + * ints while doing the check or the adjustment. */ - if (((vm_kmem_size / 2) / PAGE_SIZE) > cnt.v_page_count) - vm_kmem_size = 2 * cnt.v_page_count * PAGE_SIZE; + if (vm_kmem_size / 2 / PAGE_SIZE > mem_size) + vm_kmem_size = 2 * mem_size * PAGE_SIZE; #ifdef DEBUG_MEMGUARD tmp = memguard_fudge(vm_kmem_size, vm_kmem_size_max); |