[PATCH] ipc 3/3 enforce SEMVMX limit for undo

From: Manfred Spraul
Date: Sat Jul 03 2004 - 12:45:50 EST


Hi,

Independant from the other patches:
undo operations should not result in out of range semaphore values. The test for newval > SEMVMX is missing. The attached patch adds the test and a comment.

Andrew - could you add it to -mm?

Signed-Off-By: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx> --- 2.6/ipc/sem.c 2004-07-03 18:15:25.555921328 +0200
+++ build-2.6/ipc/sem.c 2004-07-03 17:40:02.511673112 +0200
@@ -1263,8 +1263,23 @@
struct sem * sem = &sma->sem_base[i];
if (u->semadj[i]) {
sem->semval += u->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 <manfred@xxxxxxxxxxxxxxxx>
+ */
if (sem->semval < 0)
- sem->semval = 0; /* shouldn't happen */
+ sem->semval = 0;
+ if (sem->semval > SEMVMX)
+ sem->semval = SEMVMX;
sem->sempid = current->tgid;
}
}