Module Name: src
Committed By: martin
Date: Mon Mar 11 18:01:48 UTC 2024
Modified Files:
src/sys/kern [netbsd-9]: sysv_shm.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1814):
sys/kern/sysv_shm.c: revision 1.142
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979
To generate a diff of this commit:
cvs rdiff -u -r1.135.2.4 -r1.135.2.5 src/sys/kern/sysv_shm.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/sysv_shm.c
diff -u src/sys/kern/sysv_shm.c:1.135.2.4 src/sys/kern/sysv_shm.c:1.135.2.5
--- src/sys/kern/sysv_shm.c:1.135.2.4 Thu Oct 10 17:23:45 2019
+++ src/sys/kern/sysv_shm.c Mon Mar 11 18:01:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: sysv_shm.c,v 1.135.2.4 2019/10/10 17:23:45 martin Exp $ */
+/* $NetBSD: sysv_shm.c,v 1.135.2.5 2024/03/11 18:01:48 martin Exp $ */
/*-
* Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.135.2.4 2019/10/10 17:23:45 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.135.2.5 2024/03/11 18:01:48 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_sysv.h"
@@ -961,10 +961,10 @@ shminit(struct sysctllog **clog)
ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)));
if (shminfo.shmmax == 0)
- shminfo.shmmax = uimax(physmem / 4, 1024) * PAGE_SIZE;
+ shminfo.shmall = uimax(physmem / 4, 1024);
else
- shminfo.shmmax *= PAGE_SIZE;
- shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+ shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+ shminfo.shmmax = (uint64_t)shminfo.shmall * PAGE_SIZE;
for (i = 0; i < shminfo.shmmni; i++) {
cv_init(&shm_cv[i], "shmwait");
@@ -1087,7 +1087,7 @@ sysctl_ipc_shmmax(SYSCTLFN_ARGS)
return EINVAL;
shminfo.shmmax = round_page(newsize);
- shminfo.shmall = shminfo.shmmax >> PAGE_SHIFT;
+ shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
return 0;
}