Skip to contentSkip to conversation

unexport linux/elfcore.h

RFC Al Viro 2 participants 4 messages Jun 11, 2020

Subsystems (5)
x86 VFS Kbuild exec and binfmt +1 more subsystems
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

In include/uapi/linux/elfcore.h we have
...
#include <linux/elf.h>
...
struct elf_prstatus
{
...
elf_gregset_t pr_reg; /* GP registers */

and that ends up in glibc /usr/include/linux/elfcore.h. What does *not* end up in exported headers is
1) include of asm/elf.h from linux/elf.h - asm/elf.h
is not exported at all and linux/elf.h is our uapi/linux/elf.h, which doesn't include asm/elf.h at all
2) and definitions of elf_gregset_t whatsoever.

Now, glibc (as well as other libc variants) does contain such definition - in /usr/include/sys/procfs.h. Along with a definition of struct elf_prstatus.

IOW, #include <linux/elfcore.h> in any userland program is going to blow - either due to redefinition of struct elf_prstatus or due to incomplete type of member in that definition, depending upon the headers we'd pulled in earlier.

Seeing that there's no userland code that would manage to pull that file, is there any point exporting it at all?

author maintainer
#1 lore raw
Quoted 20 lines · Al Viro

In include/uapi/linux/elfcore.h we have
...
#include <linux/elf.h>
...
struct elf_prstatus
{
...
elf_gregset_t pr_reg; /* GP registers */

and that ends up in glibc /usr/include/linux/elfcore.h. What does *not* end up in exported headers is
1) include of asm/elf.h from linux/elf.h - asm/elf.h
is not exported at all and linux/elf.h is our uapi/linux/elf.h, which doesn't include asm/elf.h at all
2) and definitions of elf_gregset_t whatsoever.

Now, glibc (as well as other libc variants) does contain such definition - in /usr/include/sys/procfs.h. Along with a definition of struct elf_prstatus.

Quoted 7 lines

IOW, #include <linux/elfcore.h> in any userland program is going to blow - either due to redefinition of struct elf_prstatus or due to incomplete type of member in that definition, depending upon the headers we'd pulled in earlier.

Seeing that there's no userland code that would manage to pull that file, is there any point exporting it at all?

I mean something like this. Objections?

commit 4d0380050642e4bf4b7a4d90d4bafeceacb1340d

Author: Al Viro <[email protected]>
Date:   Thu Jun 11 11:11:32 2020 -0400

unexport linux/elfcore.h

It's unusable from userland - it uses elf_gregset_t, which is not provided by exported headers. glibc has it in sys/procfs.h, but the same file defines struct elf_prstatus, so linux/elfcore.h can't be included once sys/procfs.h has been pulled. Same goes for uclibc and dietlibc simply doesn't have elf_gregset_t defined anywhere.

IOW, no userland source is including that thing.

arch/x86/kernel/crash_core_32.c +1 -0
index c0159a7bca6d..854ef9a18cca 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/crash_core.h>
+#include <linux/mmzone.h>
 
 #include <asm/pgtable.h>
 #include <asm/setup.h>
arch/x86/kernel/crash_core_64.c +1 -0
index 845a57eb4eb7..909b4c92dc9b 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/crash_core.h>
+#include <linux/mmzone.h>
 
 #include <asm/pgtable.h>
 #include <asm/setup.h>
fs/binfmt_elf.c +1 -0
index ff1b00d0f9ff..8cc050acdeb2 100644
@@ -43,6 +43,7 @@
 #include <linux/cred.h>
 #include <linux/dax.h>
 #include <linux/uaccess.h>
+#include <linux/ptrace.h>
 #include <asm/param.h>
 #include <asm/page.h>
 
include/linux/elfcore.h +62 -3

74 lines not on this page · raw message

include/uapi/linux/elfcore.h deleted +0 -101

101 lines not on this page · raw message

scripts/headers_install.sh +0 -1
index a07668a5c36b..65065f6ebac8 100755
@@ -89,7 +89,6 @@ arch/x86/include/uapi/asm/auxvec.h:CONFIG_X86_64
 arch/x86/include/uapi/asm/mman.h:CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS
 include/uapi/asm-generic/fcntl.h:CONFIG_64BIT
 include/uapi/linux/atmdev.h:CONFIG_COMPAT
-include/uapi/linux/elfcore.h:CONFIG_BINFMT_ELF_FDPIC
 include/uapi/linux/eventpoll.h:CONFIG_PM_SLEEP
 include/uapi/linux/hw_breakpoint.h:CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
 include/uapi/linux/pktcdvd.h:CONFIG_CDROM_PKTCDVD_WCACHE
usr/include/Makefile +0 -1
index b568a95d1f62..4b637ea50bef 100644
@@ -24,7 +24,6 @@ no-header-test += linux/am437x-vpfe.h
 no-header-test += linux/android/binder.h
 no-header-test += linux/android/binderfs.h
 no-header-test += linux/coda.h
-no-header-test += linux/elfcore.h
 no-header-test += linux/errqueue.h
 no-header-test += linux/fsmap.h
 no-header-test += linux/hdlc/ioctl.h
#2 lore raw
Quoted 2 lines · Al Viro

I mean something like this. Objections?

I'm not seeing that alot of people would care.

That said, is there any reason not to try to fix it instead and expose elf_gregset_t some way?

But I do suspect it all really boils down to "nobody cares". If you can't find somebody to speak up for it, might as well remove it.

Linus

author maintainer
#3 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 2 lines · Al Viro

I mean something like this. Objections?

I'm not seeing that alot of people would care.

That said, is there any reason not to try to fix it instead and expose elf_gregset_t some way?

But I do suspect it all really boils down to "nobody cares". If you can't find somebody to speak up for it, might as well remove it.

Anyone who wants to use that stuff includes sys/procfs.h anyway (since 1996). As for the reasons... I would love to kill off these gems, for example:
#define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296) #define SET_PR_FPVALID(S, V, R) \
do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \
while (0)
(x86 asm/compat.h) And being able to massage the definition of elf_prstatus (while keeping the size and layout - it describes a part of file format, after all) would simplify the life alot.

struct __kernel_elf_prstatus would be an obvious solution, but... nobody in userland pulls the definition in linux/elfcore.h and hadn't been able to do that for at least a decade (if not more than that). So I'd rather get rid of exporting it.