From: Danny Milosavljevic <dannym@scratchpost.org>
To: 43591@debbugs.gnu.org
Cc: Danny Milosavljevic <dannym@scratchpost.org>
Subject: [bug#43591] [PATCH v2 core-updates] gnu: glibc-final: Catch all cases of a glibc user not requesting 64-bit offsets and then using readdir regardless.
Date: Fri, 25 Sep 2020 12:42:43 +0200 [thread overview]
Message-ID: <20200925104243.2298-1-dannym@scratchpost.org> (raw)
In-Reply-To: <20200925122004.38275411@scratchpost.org>
* gnu/packages/commencement.scm (glibc-final): Catch all cases of a glibc user not
requesting 64-bit offsets and then using readdir.
---
gnu/packages/commencement.scm | 68 ++++++++++++++++++++++++++++++++++-
1 file changed, 67 insertions(+), 1 deletion(-)
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index e5a4caa95c..284fa65d20 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -3462,7 +3462,73 @@ exec ~a/bin/~a-~a -B~a/lib -Wl,-dynamic-linker -Wl,~a/~a \"$@\"~%"
,hurd-headers-boot0)
'())
,@(package-outputs glibc-final-with-bootstrap-bash))
- ,@(package-arguments glibc-final-with-bootstrap-bash)))))
+ ,@(substitute-keyword-arguments
+ (package-arguments glibc-final-with-bootstrap-bash)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'unpack 'patch-dirent
+ (lambda* (#:key outputs #:allow-other-keys)
+ ;; Linux kernel file offsets are always 64 bits.
+ ;; But userspace can be built to use 32 bit offsets.
+ ;;
+ ;; "struct dirent", returned by readdir, uses d_off to store
+ ;; such an "offset" that it got from the Linux kernel.
+ ;; In the case of ext4 that "offset" is actually a 64 bit
+ ;; cookie which includes a hash value.
+ ;;
+ ;; Therefore, there are cases where such an offset that it got
+ ;; from the Linux kernel does not fit in the "struct dirent"
+ ;; field "d_off".
+ ;;
+ ;; If the guest system's glibc is 32 bit AND uses 32 bit
+ ;; file offsets it is going to be very confused.
+ ;; It does check whether d_off fits into the structure
+ ;; it gives back to the user--and it doesn't fit. Hence readdir
+ ;; fails, with errno == EOVERFLOW (which is undocumented and thus
+ ;; an API error).
+ ;; This manifests itself in simple directory reads not working
+ ;; anymore in parts of cmake, for example.
+ ;;
+ ;; This manifested in Guix when building stuff for
+ ;; ARMHF on a x86_64 build host using QEMU transparent emulation.
+ ;;
+ ;; There is a very simple and complete way to avoid this problem:
+ ;; Just always use 64 bit offsets in user space programs (also
+ ;; on 32 bit machines). The Linux kernel does that already
+ ;; anyway.
+ ;;
+ ;; Note: We might want to avoid using 64 bit when bootstrapping
+ ;; using mescc (since mescc doesn't directly support 64 bit
+ ;; values)--but then bootstrapping has to be done on a
+ ;; file system other than ext4, or on ext4 with the feature
+ ;; "dir_index" disabled.
+ ;;
+ ;; The change below does not affect 64 bit users.
+ ;;
+ ;; See <https://issues.guix.gnu.org/43513>.
+ (let ((port (open-file "dirent/dirent.h" "a")))
+ (display "
+#ifndef _LIBC
+#if __SIZEOF_LONG__ < 8
+#ifndef __USE_FILE_OFFSET64
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 32
+#warning \"Using -D_FILE_OFFSET_BITS=32 and using readdir is a bad idea, see <https://bugzilla.kernel.org/show_bug.cgi?id=205957>\"
+#else
+#undef readdir
+#define readdir @READDIR_WITHOUT_FILE_OFFSET64_IS_A_REALLY_BAD_IDEA@
+#endif
+#endif
+#endif
+#endif
+" port)
+ (close-port port))
+ ;; This file includes <dirent.h> and thus checks sanity already.
+ ;; TODO: Check dirent/scandir-tail.c, dirent/scandir64-tail.c.
+ (substitute* "posix/glob.c"
+ (("(#[ ]*define[ ][ ]*readdir)") "
+#undef readdir
+#define readdir"))
+ #t)))))))))
(define/system-dependent gcc-boot0-wrapped
;; Make the cross-tools GCC-BOOT0 and BINUTILS-BOOT0 available under the
next prev parent reply other threads:[~2020-09-25 10:44 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 14:12 [bug#43591] [PATCH core-updates] gnu: glibc-final: Catch all cases of a glibc user not requesting 64-bit offsets and then using readdir Danny Milosavljevic
2020-09-24 14:16 ` Danny Milosavljevic
2020-09-24 18:17 ` Marius Bakke
2020-09-24 20:27 ` Danny Milosavljevic
2020-09-24 23:11 ` Marius Bakke
2020-09-25 10:20 ` Danny Milosavljevic
2020-09-25 10:42 ` Danny Milosavljevic [this message]
2020-09-25 13:36 ` Danny Milosavljevic
2020-09-25 15:33 ` Danny Milosavljevic
2020-09-26 1:42 ` Danny Milosavljevic
2020-09-26 1:49 ` Danny Milosavljevic
2020-09-29 14:51 ` Danny Milosavljevic
2020-09-27 6:43 ` Efraim Flashner
2020-09-25 20:03 ` Andreas Enge
2020-09-26 10:50 ` Danny Milosavljevic
2020-09-29 20:52 ` Ludovic Courtès
2020-09-29 22:09 ` Danny Milosavljevic
2020-09-30 9:32 ` Ludovic Courtès
2020-09-30 10:28 ` Danny Milosavljevic
2020-10-01 7:14 ` Ludovic Courtès
2020-10-02 7:18 ` Danny Milosavljevic
2020-10-02 8:12 ` Danny Milosavljevic
2020-10-02 9:47 ` Danny Milosavljevic
2020-10-02 9:32 ` Danny Milosavljevic
2020-10-06 15:39 ` Danny Milosavljevic
2020-09-25 10:24 ` Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 0/5] " Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 1/5] gnu: glibc-final: Catch all cases of a glibc user not requesting 64-bit offsets and then using readdir regardless Danny Milosavljevic
2020-09-30 16:55 ` Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 2/5] build-system/gnu: Explicity declare the _FILE_OFFSET_BITS we want Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 3/5] gnu: glibc: Do not explicitly set _FILE_OFFSET_BITS Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 4/5] gnu: glibc-mesboot0: " Danny Milosavljevic
2020-09-30 8:45 ` [bug#43591] [PATCH core-updates v2 5/5] gnu: rhash: Explicity declare the _FILE_OFFSET_BITS we want Danny Milosavljevic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200925104243.2298-1-dannym@scratchpost.org \
--to=dannym@scratchpost.org \
--cc=43591@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).