Bug 112271
Summary: | SysV semaphore sempid should not be set by call to semctl() | ||
---|---|---|---|
Product: | Other | Reporter: | Philip Semanchuk (linux_kernel.20.ick) |
Component: | Other | Assignee: | other_other |
Status: | NEW --- | ||
Severity: | low | CC: | manfred, mtk.manpages |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 3.2.0-23-generic | Subsystem: | |
Regression: | No | Bisected commit-id: |
Description
Philip Semanchuk
2016-02-10 17:11:29 UTC
The code was probably like this since 0.99. And: At least Opensolaris and Apple Darwin also have the same behavior. Thus I'm a bit reluctant to change the Linux behavior, it may break applications. I can confirm that Darwin/OS X behaves the same. (I’m on a Mac so it’s easy to test.) Apple’s SysV and POSIX IPC implementations are not typically held up as exemplars, but I agree it’s significant here that Darwin is one of several systems that behaves like this. I wonder how AIX and HP-UX behave? It seems like all the BSDs (Open/Net/Free and derivatives) behave correctly. I’ve only tested FreeBSD, but it’s pretty easy to spot in the source code where the others set sempid. AFAICT FreeBSD never had this bug. The oldest version of the relevant FreeBSD file (sysv_sem.c) that I can find is from 1994 when SysV IPC support was added. The commit comment says “Added SYSV ipcs. Obtained from: NetBSD and FreeBSD-1.1.5”: https://github.com/freebsd/freebsd/commit/580fe46632ff236a0f268c29705d04d44ad2f89a Darwin is supposedly based on a lot of code from BSD but apparently Apple didn’t copy their SysV implementation, or they copied it and then modified it. So Linux, OpenSolaris, and Darwin have the bug. The BSDs do not. We don’t know about AIX and HP-UX, and I don’t have a way to test them. I’m ambivalent about whether or not it should be fixed. I agree that fixing the bug may break existing apps, but not fixing it makes code non-portable across Linux & BSD. In either case, the impact is probably small because I don’t think this feature of SysV IPC is used a lot. If the Linux code doesn’t change, the man pages that I referenced (for semop, svipc, and semctl) need an update. (In the Feb 2016 mail thread that tried to modify the Linux behavior, "[PATCH] Don't set sempid in semctl syscall", Manfred Spraul added a pointer to a useful page he created long ago. Adding the URL here for reference: http://calculix-rpm.sourceforge.net/sysvsem.html) So, given that there is implementation variation that probably predates POSIX.1 (I'm assuming that the OpenSolaris behavior has an ancestry that stretches way back), I'd argue that the fault here lies with POSIX, inasmuch as it failed to capture the full variation in existing implementation behavior. (The BSD implementations of System V IPC were post facto.) Generally POSIX.1 does not try to prescribe away existing implementation behavior, but instead creates a loose spec, not that an implementation "may do such and such". I've added the following text to the semctl(2) man page: The sempid value POSIX.1 defines sempid as the "process ID of [the] last opera‐ tion" on a semaphore, and explicitly notes that this value is set by a successful semop(2) call, with the implication that no other interface affects the sempid value. While some implementations conform to the behavior specified in POSIX.1, others do not. (The fault here probably lies with POSIX.1 inasmuch as it likely failed to capture the full range of existing implementation behaviors.) Various other implemen‐ tations also update sempid for the other operations that update the value of a semaphore: the SETVAL and SETALL operations, as well as the semaphore adjustments performed on process termina‐ tion as a consequence of the use of the SEM_UNDO flag (see semop(2)). Linux also updates sempid for SETVAL operations and semaphore adjustments. However, somewhat inconsistently, it does not update sempid for SETALL operations. While the SETALL behavior might be viewed as a bug, the behavior is longstanding, and is probably unlikely to change. These man pages might need a tweak too, since they explicitly state that sempid is the “ID of process that did last op”: http://man7.org/linux/man-pages/man2/semop.2.html http://man7.org/linux/man-pages/man7/svipc.7.html Thanks, Phil. Done.(In reply to Philip Semanchuk from comment #4) > These man pages might need a tweak too, since they explicitly state that > sempid is the “ID of process that did last op”: > http://man7.org/linux/man-pages/man2/semop.2.html > http://man7.org/linux/man-pages/man7/svipc.7.html Thanks. Tweaked! |