glibc/login
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
..
programs Update copyright dates not handled by scripts/update-copyrights. 2018-01-01 00:41:16 +00:00
Makefile Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Versions Move getlogin_r_chk to login/ subdir. 2013-05-06 15:58:44 -07:00
endutxent.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
forkpty.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getlogin.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getlogin_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getlogin_r_chk.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getpt.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutent.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutent_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutid.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutid_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutline.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutline_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutmp.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutmpx.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutxent.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutxid.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getutxline.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
grantpt.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
lastlog.h Update. 1997-06-21 02:59:26 +00:00
login.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
login_tty.c Convert 703 function definitions to prototype style. 2015-10-16 20:21:49 +00:00
logout.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
logwtmp.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
openpty.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ptsname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ptsname_r_chk.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pty.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pututxline.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
setlogin.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
setutxent.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-getlogin.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-grantpt.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-ptsname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-utmp.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-utmpx.c Update. 1998-06-02 12:58:14 +00:00
unlockpt.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
updwtmp.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
updwtmpx.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
utmp-private.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
utmp.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
utmp_file.c Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251) 2018-06-26 13:22:53 -03:00
utmpname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
utmpxname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00