<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Manfred Spraul &lt;manfred@colorfullife.com&gt;

Independent from the other patches:

undo operations should not result in out of range semaphore values.  The test
for newval &gt; SEMVMX is missing.  The attached patch adds the test and a
comment.

Signed-Off-By: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 25-akpm/ipc/sem.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletion(-)

diff -puN ipc/sem.c~ipc-3-3-enforce-semvmx-limit-for-undo ipc/sem.c
--- 25/ipc/sem.c~ipc-3-3-enforce-semvmx-limit-for-undo	2004-07-03 13:09:20.804207792 -0700
+++ 25-akpm/ipc/sem.c	2004-07-03 13:09:20.808207184 -0700
@@ -1286,8 +1286,23 @@ found:
 			struct sem * sem = &amp;sma-&gt;sem_base[i];
 			if (u-&gt;semadj[i]) {
 				sem-&gt;semval += u-&gt;semadj[i];
+				/*
+				 * Range checks of the new semaphore value,
+				 * not defined by sus:
+				 * - Some unices ignore the undo entirely
+				 *   (e.g. HP UX 11i 11.22, Tru64 V5.1)
+				 * - some cap the value (e.g. FreeBSD caps
+				 *   at 0, but doesn't enforce SEMVMX)
+				 *
+				 * Linux caps the semaphore value, both at 0
+				 * and at SEMVMX.
+				 *
+				 * 	Manfred &lt;manfred@colorfullife.com&gt;
+				 */
 				if (sem-&gt;semval &lt; 0)
-					sem-&gt;semval = 0; /* shouldn't happen */
+					sem-&gt;semval = 0;
+				if (sem-&gt;semval &gt; SEMVMX)
+					sem-&gt;semval = SEMVMX;
 				sem-&gt;sempid = current-&gt;tgid;
 			}
 		}
_
</pre></body></html>