summaryrefslogtreecommitdiff
path: root/src/ipc/semctl.c
AgeCommit message (Collapse)AuthorFilesLines
2020-03-14fix corrupt sysvipc timestamps on 32-bit archs with old kernelsRich Felker1-0/+10
kernel commit 4693916846269d633a3664586650dbfac2c5562f (first included in release v4.14) silently fixed a bug whereby the reserved space (which was later used for high bits of time) in IPC_STAT structures was left untouched rather than zeroed. this means that a caller that wants to read the high bits needs to pre-zero the memory. since it's not clear that these operations are permitted to modify the destination buffer on failure, use a temp buffer and copy back to the caller's buffer on success.
2019-07-31sysvipc: overhaul {sem,shm,msg}ctl for time64Rich Felker1-6/+15
being "ctl" functions that take command numbers, these will be handled like ioctl/sockopt/etc., using new command numbers for the time64 variants with an "IPC_TIME64" bit added to their values. to obtain such a reserved bit, we reuse the IPC_64 bit, 0x100, which served only as part of the libc-to-kernel interface, not as a public interface of the libc functions. using new command numbers avoids the need for compat shims (in ABIs doing time64 through symbol redirection and compat shims) and, by virtue of having a fixed time64 bit for all commands, we can ensure that libc can perform the appropriate translations, even if the application is using new commands from a newer version of the libc headers than the libc available at runtime. for the vast majority of 32-bit archs, the kernel {sem,shm,msq}id64_ds definitions left padding space intended for expanding their time_t fields to 64 bits in-place, and it would have been really nice to be able to do time64 support that way. however the padding was almost always in little-endian order (except on powerpc, and for msqid_ds only on mips, where it matched the arch's byte order), and more importantly, the alignment was overlooked. in semid_ds and msqid_ds, the time_t members were not suitably aligned to be expanded to 64-bit, due to the ipc_perm header consisting of 9 32-bit words -- except on powerpc where ipc_perm contains an extra padding word. in shmid_ds, the time_t members were suitably aligned, except that mips (accidentally?) omitted the padding for them alltogether. as a result, we're stuck with adding new time_t fields on the end of the structures, and assembling the 32-bit lo/hi parts (or 16-bit hi parts, for mips shmid_ds, which lacked sufficient reserved space for full 32-bit hi parts) to fill them in. all of the functional changes here are conditional on the IPC_TIME64 macro having a nonzero definition, which will only happen when IPC_STAT is redefined for 32-bit archs, and on time_t being larger than long, so for now the new code is all dead code.
2019-07-31fix semctl with SEM_STAT_ANYRich Felker1-1/+1
due to the variadic signature, semctl needs to be made aware of any new commands that take arguments. this was overlooked when commit af55070eae5438476f921d827b7ae49e8141c3fe added SEM_STAT_ANY.
2019-07-01ipc: prefer SYS_ipc when it is definedSzabolcs Nagy1-1/+1
Linux v5.1 introduced ipc syscalls on targets where previously only SYS_ipc was available, change the logic such that the ipc code keeps using SYS_ipc which works backward compatibly on older kernels. This changes behaviour on microblaze which had both mechanisms, now SYS_ipc will be used instead of separate syscalls.
2018-06-20work around broken kernel struct ipc_perm on some big endian archsRich Felker1-2/+24
the mode member of struct ipc_perm is specified by POSIX to have type mode_t, which is uniformly defined as unsigned int. however, Linux defines it with type __kernel_mode_t, and defines __kernel_mode_t as unsigned short on some archs. since there is a subsequent padding field, treating it as a 32-bit unsigned int works on little endian archs, but the order is backwards on big endian archs with the erroneous definition. since multiple archs are affected, remedy the situation with fixup code in the affected functions (shmctl, semctl, and msgctl) rather than repeating the same shims in syscall_arch.h for every affected arch.
2014-03-13semctl: fix UB causing crashes on powerpcrofl0r1-4/+8
it's UB to fetch variadic args when none are passed, and this caused real crashes on ppc due to its calling convention, which defines that for variadic functions aggregate types be passed as pointers. the assignment caused that pointer to get dereferenced, resulting in a crash.
2014-01-08fix inadvertent use of struct in place of union for semunRich Felker1-3/+3
2014-01-08fix type of semctl variadic argumentRich Felker1-4/+10
per POSIX, the variadic argument has type union semun, which may contain a pointer or int; the type read depends on the command being issued. this allows the userspace part of the implementation to be type-correct without requiring special-casing for different commands. the kernel always expects to receive the argument interpreted as unsigned long (or equivalently, a pointer), and does its own handling of extracting the int portion from the representation, as needed. this change fixes two possible issues: most immediately, reading the argument as a (signed) long and passing it to the syscall would perform incorrect sign-extension of pointers on the upcoming x32 target. the other possible issue is that some archs may use different (user-space) argument-passing convention for unions, preventing va_arg from correctly obtaining the argument when the type long (or even unsigned long or void *) is passed to it.
2012-09-22fix IPC_64 in msgctl tooRich Felker1-4/+0
2012-09-22fix broken semctl on systems that don't use IPC_64 flagRich Felker1-2/+6
not tested on mips and arm; they may still be broken. x86_64 should be ok now.
2011-04-13numerous fixes to sysv ipcRich Felker1-1/+1
some of these definitions were just plain wrong, others based on outdated ancient "non-64" versions of the kernel interface. as much as possible has now been moved out of bits/* these changes break abi (the old abi for these functions was wrong), but since they were not working anyway it can hardly matter.
2011-04-06consistency: change all remaining syscalls to use SYS_ rather than __NR_ prefixRich Felker1-1/+1
2011-03-20global cleanup to use the new syscall interfaceRich Felker1-2/+2
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker1-0/+18