This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] libebl: Fix reading GNU_PROPERTY_STACK_SIZE reading from 32bit notes.
- From: Mark Wielaard <mark at klomp dot org>
- To: elfutils-devel at sourceware dot org
- Cc: mcermak at redhat dot com, Mark Wielaard <mark at klomp dot org>
- Date: Mon, 3 Dec 2018 00:15:46 +0100
- Subject: [PATCH] libebl: Fix reading GNU_PROPERTY_STACK_SIZE reading from 32bit notes.
When reading a GNU_PROPERTY_STACK_SIZE we need to use the proper data
type. GElf_Addr is 64bit always and when reading a 32bit size part of
it would not be initialized. Use either Elf32_Addr or Elf64_Addr to
read and print the data.
Add 32bit and 64bit, little and big endian testcases.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libebl/ChangeLog | 5 ++
libebl/eblobjnote.c | 20 ++++--
tests/ChangeLog | 9 +++
tests/Makefile.am | 4 ++
tests/run-readelf-n.sh | 101 ++++++++++++++++++++++++++++
tests/testfile_gnu_props.32be.o.bz2 | Bin 0 -> 225 bytes
tests/testfile_gnu_props.32le.o.bz2 | Bin 0 -> 215 bytes
tests/testfile_gnu_props.64be.o.bz2 | Bin 0 -> 238 bytes
tests/testfile_gnu_props.64le.o.bz2 | Bin 0 -> 233 bytes
9 files changed, 134 insertions(+), 5 deletions(-)
create mode 100644 tests/testfile_gnu_props.32be.o.bz2
create mode 100644 tests/testfile_gnu_props.32le.o.bz2
create mode 100644 tests/testfile_gnu_props.64be.o.bz2
create mode 100644 tests/testfile_gnu_props.64le.o.bz2
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index a2f89562f..0174f331a 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,8 @@
+2018-12-02 Mark Wielaard <mark@klomp.org>
+
+ * eblobjnte.c (ebl_object_note): For GNU_PROPERTY_STACK_SIZE use
+ an Elf32_Addr or Elf64_Addr to read and print the size.
+
2018-11-15 Mark Wielaard <mark@klomp.org>
* eblobjnotetypename.c (ebl_object_note_type_name): Don't update
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
index 58ac86d7e..c19ea37fc 100644
--- a/libebl/eblobjnote.c
+++ b/libebl/eblobjnote.c
@@ -360,15 +360,22 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
if (prop.pr_type == GNU_PROPERTY_STACK_SIZE)
{
printf ("STACK_SIZE ");
- if (prop.pr_datasz == 4 || prop.pr_datasz == 8)
+ union
+ {
+ Elf64_Addr a64;
+ Elf32_Addr a32;
+ } addr;
+ if ((elfclass == ELFCLASS32 && prop.pr_datasz == 4)
+ || (elfclass == ELFCLASS64 && prop.pr_datasz == 8))
{
- GElf_Addr addr;
in.d_type = ELF_T_ADDR;
out.d_type = ELF_T_ADDR;
in.d_size = prop.pr_datasz;
- out.d_size = sizeof (addr);
+ out.d_size = prop.pr_datasz;
in.d_buf = (void *) desc;
- out.d_buf = (void *) &addr;
+ out.d_buf = (elfclass == ELFCLASS32
+ ? (void *) &addr.a32
+ : (void *) &addr.a64);
if (gelf_xlatetom (ebl->elf, &out, &in,
elfident[EI_DATA]) == NULL)
@@ -376,7 +383,10 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
printf ("%s\n", elf_errmsg (-1));
return;
}
- printf ("%#" PRIx64 "\n", addr);
+ if (elfclass == ELFCLASS32)
+ printf ("%#" PRIx32 "\n", addr.a32);
+ else
+ printf ("%#" PRIx64 "\n", addr.a64);
}
else
printf (" (garbage datasz: %" PRIx32 ")\n",
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 225a51d5c..1382e40af 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,12 @@
+2018-12-02 Mark Wielaard <mark@klomp.org>
+
+ * testfile_gnu_props.32le.o.bz2: New testfile.
+ * testfile_gnu_props.64le.o.bz2: Likewise.
+ * testfile_gnu_props.32be.o.bz2: Likewise.
+ * testfile_gnu_props.64be.o.bz2: Likewise.
+ * Makefile (EXTRA_DIST): Add new testfiles.
+ * run-readelf-n.sh: Run tests on new testfiles.
+
2018-11-28 Mark Wielaard <mark@klomp.org>
* backtrace-data.c (main): Improve error message.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ca0e1c22..bc8c19a63 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -278,6 +278,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-readelf-types.sh \
run-readelf-n.sh \
testfile-gnu-property-note.bz2 testfile-gnu-property-note.o.bz2 \
+ testfile_gnu_props.32le.o.bz2 \
+ testfile_gnu_props.64le.o.bz2 \
+ testfile_gnu_props.32be.o.bz2 \
+ testfile_gnu_props.64be.o.bz2 \
run-allfcts-multi.sh \
test-offset-loop.bz2 test-offset-loop.alt.bz2 \
run-prelink-addr-test.sh \
diff --git a/tests/run-readelf-n.sh b/tests/run-readelf-n.sh
index c2db2ce2a..cc7d7f66a 100755
--- a/tests/run-readelf-n.sh
+++ b/tests/run-readelf-n.sh
@@ -125,3 +125,104 @@ Note section [22] '.note.gnu.property' of 48 bytes at offset 0x40c:
X86 0xc0000000 data: 00 00 00 00
X86 0xc0000001 data: 00 00 00 00
EOF
+
+#
+# = gnu_props.S
+#
+# #define NT_GNU_PROPERTY_TYPE_0 5
+# #define GNU_PROPERTY_STACK_SIZE 1
+# #define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
+
+# /* Normal notes always have alignment and padding of 4 bytes,
+# but GNU Property notes use 4 byte words, with 8 byte padding
+# for ELFCLASS64. */
+# #if __SIZEOF_PTRDIFF_T__ == 8
+# # define ALIGN 3
+# #elif __SIZEOF_PTRDIFF_T__ == 4
+# # define ALIGN 2
+# #endif
+#
+# .section ".note.gnu.property", "a"
+# .p2align ALIGN
+# /* First note. */
+# .long 1f - 0f /* name length. */
+# .long 4f - 2f /* data length. */
+# .long NT_GNU_PROPERTY_TYPE_0 /* note type. */
+# 0:
+# .asciz "GNU" /* vendor name. */
+# 1:
+# .p2align ALIGN /* Padding. */
+# 2:
+# .long GNU_PROPERTY_STACK_SIZE /* pr_type. */
+# .long 4f - 3f /* pr_datasz. */
+# 3:
+# .dc.a 0x280000 /* Stack size. */
+# 4:
+# .p2align ALIGN
+#
+# /* Second note. */
+# .long 6f - 5f /* name length. */
+# .long 8f - 7f /* data length. */
+# .long NT_GNU_PROPERTY_TYPE_0 /* note type. */
+# 5:
+# .asciz "GNU" /* vendor name. */
+# 6:
+# .p2align ALIGN /* Padding. */
+# 7:
+# .long GNU_PROPERTY_NO_COPY_ON_PROTECTED /* pr_type. */
+# .long 0 /* pr_datasz. */
+# /* No data. */
+# 8:
+# .p2align ALIGN
+#
+# On x86_64
+# gcc -m64 -c -o testfile_gnu_props_64le.o gnu_props.S
+# gcc -m32 -c -o testfile_gnu_props_32le.o gnu_props.S
+
+testfiles testfile_gnu_props.32le.o testfile_gnu_props.64le.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.32le.o << EOF
+
+Note section [ 4] '.note.gnu.property' of 52 bytes at offset 0x34:
+ Owner Data size Type
+ GNU 12 GNU_PROPERTY_TYPE_0
+ STACK_SIZE 0x280000
+ GNU 8 GNU_PROPERTY_TYPE_0
+ NO_COPY_ON_PROTECTION
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.64le.o << EOF
+
+Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40:
+ Owner Data size Type
+ GNU 16 GNU_PROPERTY_TYPE_0
+ STACK_SIZE 0x280000
+ GNU 8 GNU_PROPERTY_TYPE_0
+ NO_COPY_ON_PROTECTION
+EOF
+
+# On ppc64
+# gcc -m32 -c -o testfile_gnu_props.32be.o gnu_props.S
+# gcc -m64 -c -o testfile_gnu_props.64be.o gnu_props.S
+
+testfiles testfile_gnu_props.32be.o testfile_gnu_props.64be.o
+
+testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.32be.o << EOF
+
+Note section [ 4] '.note.gnu.property' of 52 bytes at offset 0x34:
+ Owner Data size Type
+ GNU 12 GNU_PROPERTY_TYPE_0
+ STACK_SIZE 0x280000
+ GNU 8 GNU_PROPERTY_TYPE_0
+ NO_COPY_ON_PROTECTION
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf -n testfile_gnu_props.64be.o << EOF
+
+Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40:
+ Owner Data size Type
+ GNU 16 GNU_PROPERTY_TYPE_0
+ STACK_SIZE 0x280000
+ GNU 8 GNU_PROPERTY_TYPE_0
+ NO_COPY_ON_PROTECTION
+EOF
diff --git a/tests/testfile_gnu_props.32be.o.bz2 b/tests/testfile_gnu_props.32be.o.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..60a39fe54d0802bcd82f809f874616e14c314764
GIT binary patch
literal 225
zcmV<703QEBT4*^jL0KkKS(}aMr~m-K|A_zWWDFq11OS7DLI5_y-e7=W06;JRwlPG=
zG|&J501XBp)MSQ0ni)L+OhyO>f<-2iL7*7`02u%lf+<_Mt-v2(VbGPDfr2AJd|&CO
zHl-Y2B=Y9fAPH!(gC&_a&84NLm@N%JWgn`MWneaj(i;S&Vi9qm(9lle`Fr=&i(x^z
zYmrXXJfM{A951LKwHPFn&ijDmaAj}f2)Kj&UZSeWdlZ4^3BWW7XldkrB?%!)35rXF
bfRyo+BQDSe<7OmK2l00#Q-ui$xZa9@tqflc
literal 0
HcmV?d00001
diff --git a/tests/testfile_gnu_props.32le.o.bz2 b/tests/testfile_gnu_props.32le.o.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..cb5d23c289abcd727a41cc2ffd129a07f68d0982
GIT binary patch
literal 215
zcmV;|04V=LT4*^jL0KkKSx;K4LjVB0e~AC=U<jhc1OS7DLI5_y-e7=W06;JRwlPyj
zs69;p00003ArfYjKmY&$001OOBR~T{007VcF(hCQlt3U!A`BoPQkaGB*kE89R2y;w
zkbo|>`VM<0l3B52kf39u^`osp31c4yh=>Ta0JTvQG_JH0G>$&~^d@Z;wkKjr!&c?S
zK(}X53U-oH?}%=3!AtnUO@sYR9cd%6KzGEulKA5GN@e8#90W-ag+;iiaL6f@V2U)!
Rf>)CKUC9*TLP0%htqhX`R6GCx
literal 0
HcmV?d00001
diff --git a/tests/testfile_gnu_props.64be.o.bz2 b/tests/testfile_gnu_props.64be.o.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..784c98bc85541cfe9b51261addb469cf81ece771
GIT binary patch
literal 238
zcmV<K01^K}T4*^jL0KkKS<LGg=>P!Fe}Mn#dQ2e2KtRKV0suC{-eBMWFaXvehK8B|
zXaF<-10kSlXcYZZGKPVp)X2~c13>Z#6e&EW(i(eIz)c>b4FD!4;0l?cTH^C*IW3p=
z1&|gMn5f7oV$_+Cr2>xH>dJs`4p<1A^vmyDtZ4JHzqtVhC0i3?V4DF2ED5kh4&L3j
zDJwC(3aJxwW`;?sEr}JY3W7(oM4CgY2`j7!--Jt!2M67jyOa))asT1Wc=A0BKwSh}
o6%tKWr{tq0nTl|)c|@&z@+sJ1PUQzZy%;YSaz!{$kj(2C>2rc*n*aa+
literal 0
HcmV?d00001
diff --git a/tests/testfile_gnu_props.64le.o.bz2 b/tests/testfile_gnu_props.64le.o.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..09df3d1eff17170bd012db5fd9435a26d389982f
GIT binary patch
literal 233
zcmV<F02cp3T4*^jL0KkKS(70y=l}r6e}Mn!=t!W&KtscY0suC{-eBMWFaXR@(rKw4
zlf?rgG=KmGnjTQYLrnlQ02%-RkkBMbOh%(=F#}DZq}ntZgEbnN^vCT8l13KEwJZkW
zcwQAE!I|JAjgZJxFglv%B7JhnGpaqR%P4`cBp8IN%?AdEhzMyqVJaABVimXF&0wXD
z$}9O!QMHre61AewbpTMsiK7cp(g<RX5g~!WbN*$m&jYGppZ@8NmmY;cTLQE$Dm@)e
j=|)J#3a3q~imrQPrp&;%LdQPz5biGIig2MJCPH1%3t?q*
literal 0
HcmV?d00001
--
2.19.1