Commit a5f4db87 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

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: default avatarDavidlohr Bueso <dbueso@suse.de>
Reported-by: default avatarPhilip 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dde5cf39
...@@ -92,7 +92,14 @@ ...@@ -92,7 +92,14 @@
/* One semaphore structure for each semaphore in the system. */ /* One semaphore structure for each semaphore in the system. */
struct sem { struct sem {
int semval; /* current value */ int semval; /* current value */
int sempid; /* pid of last operation */ /*
* PID of the process that last modified the semaphore. For
* Linux, specifically these are:
* - semop
* - semctl, via SETVAL and SETALL.
* - at task exit when performing undo adjustments (see exit_sem).
*/
int sempid;
spinlock_t lock; /* spinlock for fine-grained semtimedop */ spinlock_t lock; /* spinlock for fine-grained semtimedop */
struct list_head pending_alter; /* pending single-sop operations */ struct list_head pending_alter; /* pending single-sop operations */
/* that alter the semaphore */ /* that alter the semaphore */
...@@ -1444,8 +1451,10 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum, ...@@ -1444,8 +1451,10 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
goto out_unlock; goto out_unlock;
} }
for (i = 0; i < nsems; i++) for (i = 0; i < nsems; i++) {
sma->sem_base[i].semval = sem_io[i]; sma->sem_base[i].semval = sem_io[i];
sma->sem_base[i].sempid = task_tgid_vnr(current);
}
ipc_assert_locked_object(&sma->sem_perm); ipc_assert_locked_object(&sma->sem_perm);
list_for_each_entry(un, &sma->list_id, list_id) { list_for_each_entry(un, &sma->list_id, list_id) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment