summaryrefslogtreecommitdiffstats
path: root/ipc/sem.c
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2016-03-22 17:27:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-22 18:36:02 -0400
commita5f4db877177d2a3d7ae62a7bac3a5a27e083d7f (patch)
tree9cda3b63b32e98b041764acc97dd668eac070526 /ipc/sem.c
parentdde5cf39d4d2cce71f2997c37210dd624d0e4bf6 (diff)
ipc/sem: make semctl setting sempid consistent
As indicated by bug#112271, Linux sets the sempid value upon semctl, and not only for semop calls. However, within semctl we only do this for SETVAL, leaving SETALL without updating the field, and therefore rather inconsistent behavior when compared to other Unices. There is really no documentation regarding this and therefore users should not make assumptions. With this patch, along with updating semctl.2 manpages, this scenario should become less ambiguous As such, set sempid on SETALL cmd. Also update some in-code documentation, specifying where the sempid is set. Passes ltp and custom testcase where a child (fork) does SETALL to the set. Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Reported-by: Philip Semanchuk <linux_kernel.20.ick@spamgourmet.com> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Herton R. Krzesinski <herton@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/sem.c')
-rw-r--r--ipc/sem.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ipc/sem.c b/ipc/sem.c
index cddd5b5fde51..b3757ea0694b 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -92,7 +92,14 @@
92/* One semaphore structure for each semaphore in the system. */ 92/* One semaphore structure for each semaphore in the system. */
93struct sem { 93struct sem {
94 int semval; /* current value */ 94 int semval; /* current value */
95 int sempid; /* pid of last operation */ 95 /*
96 * PID of the process that last modified the semaphore. For
97 * Linux, specifically these are:
98 * - semop
99 * - semctl, via SETVAL and SETALL.
100 * - at task exit when performing undo adjustments (see exit_sem).
101 */
102 int sempid;
96 spinlock_t lock; /* spinlock for fine-grained semtimedop */ 103 spinlock_t lock; /* spinlock for fine-grained semtimedop */
97 struct list_head pending_alter; /* pending single-sop operations */ 104 struct list_head pending_alter; /* pending single-sop operations */
98 /* that alter the semaphore */ 105 /* that alter the semaphore */
@@ -1444,8 +1451,10 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
1444 goto out_unlock; 1451 goto out_unlock;
1445 } 1452 }
1446 1453
1447 for (i = 0; i < nsems; i++) 1454 for (i = 0; i < nsems; i++) {
1448 sma->sem_base[i].semval = sem_io[i]; 1455 sma->sem_base[i].semval = sem_io[i];
1456 sma->sem_base[i].sempid = task_tgid_vnr(current);
1457 }
1449 1458
1450 ipc_assert_locked_object(&sma->sem_perm); 1459 ipc_assert_locked_object(&sma->sem_perm);
1451 list_for_each_entry(un, &sma->list_id, list_id) { 1460 list_for_each_entry(un, &sma->list_id, list_id) {