Bug#888782: fp-compiler-3.0.4: fpselect segfaults on arm64
Tags 888782 +patch Thanks Freepascal upstream noted that this bug was not present in trunk, but didn't research when/how it was fixed, so I decided to do some digging in the source. It turns out that the "generic syscalls" implementation of fpSelect (used for aarch64) translates the timeout parameter from a timeval (seconds and microseconds) to a timespec (seconds and nanoseconds) before passing it to the "pselect6" system call. Unfortunately the version of the code in Debian 3.0.4 fails to check if the timeout is nil, dereferences the nil pointer and segfaults. Using the "blame" tool on an unofficial github mirror of the freepascal source found the commit fixing the issue. https://github.com/graemeg/freepascal/commit/e8335a145bfe3af52eed8d0d74ae3a461bbe9d1e I turned the commit into a quilt patch, added it to the quilt series, built the compiler and was able to confirm it fixed the issue. Debdiff is attatched, if noone else gets round to it first I'll probably commit and upload within the next week or so. diff -Nru fpc-3.0.4+dfsg/debian/changelog fpc-3.0.4+dfsg/debian/changelog --- fpc-3.0.4+dfsg/debian/changelog 2019-01-16 09:14:10.0 + +++ fpc-3.0.4+dfsg/debian/changelog 2019-01-24 23:27:02.0 + @@ -1,3 +1,10 @@ +fpc (3.0.4+dfsg-22) UNRELEASED; urgency=medium + + * debian/patches/arm64-select.patch +- Fix fpSelect with nil timestamp on aarch64 (closes: 888782) + + -- Peter Michael Green Thu, 24 Jan 2019 23:27:02 + + fpc (3.0.4+dfsg-21) unstable; urgency=medium [ Paul Gevers ] diff -Nru fpc-3.0.4+dfsg/debian/patches/arm64-select.patch fpc-3.0.4+dfsg/debian/patches/arm64-select.patch --- fpc-3.0.4+dfsg/debian/patches/arm64-select.patch1970-01-01 00:00:00.0 + +++ fpc-3.0.4+dfsg/debian/patches/arm64-select.patch2019-01-24 23:26:42.0 + @@ -0,0 +1,37 @@ +This patch is based on the commit detailed below with paths adjusted +to match the Debian fpc package --plugwash +commit e8335a145bfe3af52eed8d0d74ae3a461bbe9d1e +Author: Marco van de Voort +Date: Wed Mar 30 19:21:05 2016 + + + * fix timespec=nil for -dgeneric_linux_syscalls (aarch64) case. + + +git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@33392 3ad0048d-3df7-0310-abae-a5850022a9f2 + +diff --git a/rtl/linux/bunxsysc.inc b/rtl/linux/bunxsysc.inc +index c8d7849672..c6d18be4e9 100644 +--- a/fpcsrc/rtl/linux/bunxsysc.inc b/fpcsrc/rtl/linux/bunxsysc.inc +@@ -463,12 +463,18 @@ Function fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cin + {$if defined(generic_linux_syscalls)} + + var ts : timespec; ++pts : PTimeSpec; + begin +- ts.tv_sec := timeout^.tv_sec; +- ts.tv_nsec := timeout^.tv_usec * 1000; ++ pts:=nil; ++ if assigned(timeout) then ++begin ++ pts:=@ts; ++ ts.tv_sec := timeout^.tv_sec; ++ ts.tv_nsec := timeout^.tv_usec * 1000; ++end; + fpSelect:=do_syscall(syscall_nr_pselect6,n, +tsysparam(readfds),tsysparam(writefds), +- tsysparam(exceptfds),tsysparam(@ts),0); ++ tsysparam(exceptfds),tsysparam(pts),0); + end; + + {$else} diff -Nru fpc-3.0.4+dfsg/debian/patches/series fpc-3.0.4+dfsg/debian/patches/series --- fpc-3.0.4+dfsg/debian/patches/series2019-01-16 08:33:37.0 + +++ fpc-3.0.4+dfsg/debian/patches/series2019-01-24 23:26:55.0 + @@ -34,3 +34,4 @@ fpcmake-m68k.patch ncurses6.patch fpc-r38400.patch +arm64-select.patch
Bug#888782: fp-compiler-3.0.4: fpselect segfaults on arm64
Control: forwarded -1 https://bugs.freepascal.org/view.php?id=34534 On 10-11-18 19:22, Paul Gevers wrote: > I'll forward this upstream today. Done. Paul signature.asc Description: OpenPGP digital signature
Bug#888782: fp-compiler-3.0.4: fpselect segfaults on arm64
Hi Adam, Thanks for reporting this issue. Sorry for not responding earlier, it must have slipped through the cracks. I'll forward this upstream today. Paul On Mon, 29 Jan 2018 21:46:22 +0100 Adam Borowski wrote: > Package: fp-compiler-3.0.4 > Version: 3.0.4+dfsg-14 > Severity: normal > > Hi! > The following program segfaults on arm64: > > . > uses baseunix; > begin > fpselect(input, nil) > end. > ` > (Segfault in fpc doesn't give a message, just silently aborts the program > with return code 216.) > > On amd64 and armhf, all is ok -- the above program waits for something to be > available on stdin, then completes successfully. > > > Meow! > -- System Information: > Debian Release: buster/sid > APT prefers unstable-debug > APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental') > Architecture: arm64 (aarch64) > > Kernel: Linux 4.15.0-00183-ga494935d9d25 (SMP w/4 CPU cores; PREEMPT) > Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C.UTF-8 > (charmap=UTF-8) > Shell: /bin/sh linked to /bin/dash > Init: sysvinit (via /sbin/init) > > Versions of packages fp-compiler-3.0.4 depends on: > ii binutils 2.29.90.20180122-1 > ii debconf [debconf-2.0] 1.5.65 > ii fp-units-rtl-3.0.4 3.0.4+dfsg-14 > ii libc6 2.26-6 > > Versions of packages fp-compiler-3.0.4 recommends: > ii fp-utils-3.0.4 3.0.4+dfsg-14 > > Versions of packages fp-compiler-3.0.4 suggests: > ii fp-docs-3.0.4 3.0.4+dfsg-14 > > -- debconf information: > fp-compiler/windres: > fp-compiler/rename_cfg: true > fp-compiler/windres-select: Select manually > > signature.asc Description: OpenPGP digital signature
Bug#888782: fp-compiler-3.0.4: fpselect segfaults on arm64
Package: fp-compiler-3.0.4 Version: 3.0.4+dfsg-14 Severity: normal Hi! The following program segfaults on arm64: . uses baseunix; begin fpselect(input, nil) end. ` (Segfault in fpc doesn't give a message, just silently aborts the program with return code 216.) On amd64 and armhf, all is ok -- the above program waits for something to be available on stdin, then completes successfully. Meow! -- System Information: Debian Release: buster/sid APT prefers unstable-debug APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental') Architecture: arm64 (aarch64) Kernel: Linux 4.15.0-00183-ga494935d9d25 (SMP w/4 CPU cores; PREEMPT) Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: sysvinit (via /sbin/init) Versions of packages fp-compiler-3.0.4 depends on: ii binutils 2.29.90.20180122-1 ii debconf [debconf-2.0] 1.5.65 ii fp-units-rtl-3.0.4 3.0.4+dfsg-14 ii libc6 2.26-6 Versions of packages fp-compiler-3.0.4 recommends: ii fp-utils-3.0.4 3.0.4+dfsg-14 Versions of packages fp-compiler-3.0.4 suggests: ii fp-docs-3.0.4 3.0.4+dfsg-14 -- debconf information: fp-compiler/windres: fp-compiler/rename_cfg: true fp-compiler/windres-select: Select manually