glibc/sysdeps/posix
Adhemerval Zanella 06ab719d30 Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251)
This patch fixes the OFD ("file private") locks for architectures that
support non-LFS flock definition (__USE_FILE_OFFSET64 not defined). The
issue in this case is both F_OFD_{GETLK,SETLK,SETLKW} and
F_{SET,GET}L{W}K64 expects a flock64 argument and when using old
F_OFD_* flags with a non LFS flock argument the kernel might interpret
the underlying data wrongly.  Kernel idea originally was to avoid using
such flags in non-LFS syscall, but since GLIBC uses fcntl with LFS
semantic as default it is possible to provide the functionality and
avoid the bogus struct kernel passing by adjusting the struct manually
for the required flags.

The idea follows other LFS interfaces that provide two symbols:

  1. A new LFS fcntl64 is added on default ABI with the usual macros to
     select it for FILE_OFFSET_BITS=64.

  2. The Linux non-LFS fcntl use a stack allocated struct flock64 for
     F_OFD_{GETLK,SETLK,SETLKW} copy the results on the user provided
     struct.

  3. Keep a compat symbol with old broken semantic for architectures
     that do not define __OFF_T_MATCHES_OFF64_T.

So for architectures which defines __USE_FILE_OFFSET64, fcntl64 will
aliased to fcntl and no adjustment would be required.  So to actually
use F_OFD_* with LFS support the source must be built with LFS support
(_FILE_OFFSET_BITS=64).

Also F_OFD_SETLKW command is handled a cancellation point, as for
F_SETLKW{64}.

Checked on x86_64-linux-gnu and i686-linux-gnu.

	[BZ #20251]
	* NEWS: Mention fcntl64 addition.
	* csu/check_fds.c: Replace __fcntl_nocancel by __fcntl64_nocancel.
	* login/utmp_file.c: Likewise.
	* sysdeps/posix/fdopendir.c: Likewise.
	* sysdeps/posix/opendir.c: Likewise.
	* sysdeps/unix/pt-fcntl.c: Likewise.
	* include/fcntl.h (__libc_fcntl64, __fcntl64,
	__fcntl64_nocancel_adjusted): New prototype.
	(__fcntl_nocancel_adjusted): Remove prototype.
	* io/Makefile (routines): Add fcntl64.
	(CFLAGS-fcntl64.c): New rule.
	* io/Versions [GLIBC_2.28] (fcntl64): New symbol.
	[GLIBC_PRIVATE] (__libc_fcntl): Rename to __libc_fcntl64.
	* io/fcntl.h (fcntl64): Add prototype and redirect if
	__USE_FILE_OFFSET64 is defined.
	* io/fcntl64.c: New file.
	* manual/llio.text: Add a note for which commands fcntl acts a
	cancellation point.
	* nptl/Makefile (CFLAGS-fcntl64.c): New rule.
	* sysdeps/mach/hurd/fcntl.c: Alias fcntl to fcntl64 symbols.
	* sysdeps/mach/hurd/i386/libc.abilist [GLIBC_2.28] (fcntl, fcntl64):
	New symbols.
	* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Fix F_GETLK64,
	F_OFD_GETLK, F_SETLK64, F_SETLKW64, F_OFD_SETLK, and F_OFD_SETLKW for
	non-LFS case.
	* sysdeps/unix/sysv/linux/fcntl64.c: New file.
	* sysdeps/unix/sysv/linux/fcntl_nocancel.c (__fcntl_nocancel): Rename
	to __fcntl64_nocancel.
	(__fcntl_nocancel_adjusted): Rename to __fcntl64_nocancel_adjusted.
	* sysdeps/unix/sysv/linux/not-cancel.h (__fcntl_nocancel): Rename
	to __fcntl64_nocancel.
	* sysdeps/unix/sysv/linux/tst-ofdlocks.c: New file.
	* sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c: Likewise.
	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-ofdlocks.
	(tests-internal): Add tst-ofdlocks-compat.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist [GLIBC_2.28]
	(fcntl64): New symbol.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist: Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist [GLIBC_2.28] (fcntl,
	fcntl64): Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilis: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
2018-06-26 13:22:53 -03:00
..
alarm.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
clock_getres.c hurd: Avoid some PLTs in libc and librt 2018-04-02 19:07:52 +00:00
clock.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
closedir.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ctermid.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
cuserid.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
dirfd.c hurd: Avoid PLT for dirfd 2018-04-05 01:52:29 +02:00
dirstream.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
dl-fileid.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
dup2.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
dup.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
euidaccess.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
fdopendir.c Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251) 2018-06-26 13:22:53 -03:00
flock.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
fpathconf.c Reject invalid definitions of _POSIX_CHOWN_RESTRICTED, _POSIX_NO_TRUNC, _POSIX_VDISABLE 2018-01-29 22:21:21 +01:00
gai_strerror-strs.h
gai_strerror.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getaddrinfo.c Switch IDNA implementation to libidn2 [BZ #19728] [BZ #19729] [BZ #22247] 2018-05-23 15:27:24 +02:00
getcwd.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getdtsz.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
gethostname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getpagesize.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
gettimeofday.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
isatty.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
isfdtype.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
killpg.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc_fatal.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Makefile
mkfifo.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
mkfifoat.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
nice.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
open64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
opendir.c Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251) 2018-06-26 13:22:53 -03:00
pathconf.c Reject invalid definitions of _POSIX_CHOWN_RESTRICTED, _POSIX_NO_TRUNC, _POSIX_VDISABLE 2018-01-29 22:21:21 +01:00
pause.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
posix_fallocate64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
posix_fallocate.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pread64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pread.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
preadv2.c preadv2/pwritev2: Handle offset == -1 [BZ #22753] 2018-02-02 10:46:26 +01:00
preadv64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
preadv64v2.c preadv2/pwritev2: Handle offset == -1 [BZ #22753] 2018-02-02 10:46:26 +01:00
preadv_common.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
preadv.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
profil.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pwrite64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pwrite.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pwritev2.c preadv2/pwritev2: Handle offset == -1 [BZ #22753] 2018-02-02 10:46:26 +01:00
pwritev64.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pwritev64v2.c preadv2/pwritev2: Handle offset == -1 [BZ #22753] 2018-02-02 10:46:26 +01:00
pwritev_common.c hurd: Fix pwritev* 2018-01-07 13:31:36 +01:00
pwritev.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
raise.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
readdir_r.c Consolidate Linux readdir{64}{_r} implementation 2018-04-06 17:49:02 -03:00
readdir.c Consolidate Linux readdir{64}{_r} implementation 2018-04-06 17:49:02 -03:00
readv.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
remove.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
rename.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
rewinddir.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
seekdir.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
shm_open.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
shm_unlink.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
shm-directory.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
shm-directory.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigblock.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigignore.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigintr.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
signal.c Filter out NPTL internal signals (BZ #22391) 2018-04-03 13:30:49 -03:00
sigpause.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigset.c Filter out NPTL internal signals (BZ #22391) 2018-04-03 13:30:49 -03:00
sigsetmask.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigsuspend.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sigwait.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sleep.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
spawni.c posix: Fix posix_spawnp to not execute invalid binaries in non compat mode (BZ#23264) 2018-06-08 17:27:46 -03:00
sprofil.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Subdirs Make sysdeps/posix bring in login subdir. 2015-07-23 17:04:22 -07:00
sysconf.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
system.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
sysv_signal.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
telldir.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tempname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
time.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
timespec_get.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
truncate.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ttyname_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ttyname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ulimit.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
usleep.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
utime.c Add missing start-of-file descriptive comment. 2018-03-06 09:21:04 +01:00
utimes.c Add missing start-of-file descriptive comment. 2018-03-06 09:21:04 +01:00
wait3.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
wait.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
waitid.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
writev.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00