Skip to content

Commit a5f4db8

Browse files
Davidlohr Buesotorvalds
authored andcommitted
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>
1 parent dde5cf3 commit a5f4db8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ipc/sem.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@
9292
/* One semaphore structure for each semaphore in the system. */
9393
struct sem {
9494
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;
96103
spinlock_t lock; /* spinlock for fine-grained semtimedop */
97104
struct list_head pending_alter; /* pending single-sop operations */
98105
/* that alter the semaphore */
@@ -1444,8 +1451,10 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
14441451
goto out_unlock;
14451452
}
14461453

1447-
for (i = 0; i < nsems; i++)
1454+
for (i = 0; i < nsems; i++) {
14481455
sma->sem_base[i].semval = sem_io[i];
1456+
sma->sem_base[i].sempid = task_tgid_vnr(current);
1457+
}
14491458

14501459
ipc_assert_locked_object(&sma->sem_perm);
14511460
list_for_each_entry(un, &sma->list_id, list_id) {

0 commit comments

Comments
 (0)