net/core: work around section mismatch warning for ptp_classifier
Subsystems (2)
cover net/core: work around section mismatch warning for ptp_classifier
While preparing KASLR for s390, I stumbled over a section mismatch warning after enabling -fPIE compiler option:
WARNING: vmlinux.o(.data+0x31070): Section mismatch in reference from the variable print_fmt_kfree_skb to the variable .init.data:ptp_filter.51760
I found a patch that would address this issue as part of a KASLR patch series for ARM from Ard Biesheuvel:
https://marc.info/?l=kernel-hardening&m=150444052819798&w=2
https://marc.info/?l=kernel-hardening&m=150444051919794&w=2
That patch series did not make it upstream, and there seems to be no other arch using -fpic/pie so far, so this fix is still missing.
Dave, could you please pick it up, as we will see this warning on s390 after my KASRL patches go upstream.
Ard Biesheuvel (1):
net/core: work around section mismatch warning for ptp_classifier
net/core/ptp_classifier.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/1 net/core: work around section mismatch warning for ptp_classifier
From: Ard Biesheuvel <[email protected]>
The routine ptp_classifier_init() uses an initializer for an automatic struct type variable which refers to an __initdata symbol. This is perfectly legal, but may trigger a section mismatch warning when running the compiler in -fpic mode, due to the fact that the initializer may be emitted into an anonymous .data section thats lack the __init annotation. So work around it by using assignments instead.
--- net/core/ptp_classifier.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/core/ptp_classifier.c +4 -3
@@ -185,9 +185,10 @@ void __init ptp_classifier_init(void) { 0x16, 0, 0, 0x00000000 }, { 0x06, 0, 0, 0x00000000 }, }; -struct sock_fprog_kern ptp_prog = { - .len =ARRAY_SIZE (ptp_filter), .filter = ptp_filter, - }; +struct sock_fprog_kern ptp_prog; + + ptp_prog.len =ARRAY_SIZE (ptp_filter); + ptp_prog.filter = ptp_filter;BUG_ON (bpf_prog_create (&ptp_insns, &ptp_prog)); }
Signature · 1 line
2.16.4
From: Gerald Schaefer <[email protected]>
Date: Mon, 15 Apr 2019 19:14:45 +0200
Quoted 10 lines
From: Ard Biesheuvel <[email protected]>
The routine
ptp_classifier_init()uses an initializer for an automatic struct type variable which refers to an__initdatasymbol. This is perfectly legal, but may trigger a section mismatch warning when running the compiler in -fpic mode, due to the fact that the initializer may be emitted into an anonymous .data section thats lack the__initannotation. So work around it by using assignments instead.
Quoted 2 lines
Signed-off-by Ard Biesheuvel <[email protected]>Signed-off-by Gerald Schaefer <[email protected]>
Applied.