In commit c0748e "libelf: More checking of valid sh_addralign values." we adjusted bogus alignment of data buffers if they were greater than the offset of the data in the file. This works OK, except when there is no data in the file. So make sure to not adjust any NOBITS sections. Also adds a test that shows the issue and makes sure elflint is called with --gnu in run-strip-test.sh. https://bugzilla.redhat.com/show_bug.cgi?id=1303845 Signed-off-by: Mark Wielaard --- libelf/ChangeLog | 5 +++++ libelf/elf_getdata.c | 4 ++-- tests/ChangeLog | 10 ++++++++++ tests/Makefile.am | 5 ++++- tests/run-strip-nobitsalign.sh | 35 +++++++++++++++++++++++++++++++++++ tests/run-strip-test.sh | 4 ++-- tests/testfile-nobitsalign.bz2 | Bin 0 -> 2921 bytes tests/testfile-nobitsalign.strip.bz2 | Bin 0 -> 1723 bytes 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100755 tests/run-strip-nobitsalign.sh create mode 100755 tests/testfile-nobitsalign.bz2 create mode 100755 tests/testfile-nobitsalign.strip.bz2 diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 9536ced..41eaa00 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2016-02-04 Mark Wielaard + + * elf_getdata.c (__libelf_set_rawdata_wrlock): Don't adjust align + for SHT_NOBITS sections. + 2016-01-28 Mark Wielaard * elf.h: Update from glibc. Add new i386 and x86_64 relocations. diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c index 4ec94b9..d1fafbf 100644 --- a/libelf/elf_getdata.c +++ b/libelf/elf_getdata.c @@ -1,5 +1,5 @@ /* Return the next data element from the section after possibly converting it. - Copyright (C) 1998-2005, 2006, 2007, 2015 Red Hat, Inc. + Copyright (C) 1998-2005, 2006, 2007, 2015, 2016 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper , 1998. @@ -363,7 +363,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn) at least an ehdr this will only trigger for alignment values > 64 which should be uncommon. */ align = align ?: 1; - if (align > offset) + if (type != SHT_NOBITS && align > offset) align = offset; scn->rawdata.d.d_align = align; if (elf->class == ELFCLASS32 diff --git a/tests/ChangeLog b/tests/ChangeLog index 234ae56..defb8ae 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,13 @@ +2016-02-04 Mark Wielaard + + * run-strip-nobitsalign.sh: New test. + * testfile-nobitsalign.bz2: New testfile. + * testfile-nobitsalign.strip.bz2: Likewise. + * Makefile.am (TESTS): Add run-strip-nobitsalign.sh. + (EXTRA_DIST): Add run-strip-nobitsalign.sh, testfile-nobitsalign.bz2 + and testfile-nobitsalign.strip.bz2. + * run-strip-test.sh: Add --gnu to elflint calls. + 2016-01-13 Mark Wielaard * system-elf-libelf-test.c: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index 7b9e108..f3e7c01 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 1996-2015 Red Hat, Inc. +## Copyright (C) 1996-2016 Red Hat, Inc. ## This file is part of elfutils. ## ## This file is free software; you can redistribute it and/or modify @@ -80,6 +80,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-strip-test6.sh run-strip-test7.sh run-strip-test8.sh \ run-strip-test9.sh run-strip-test10.sh \ run-strip-groups.sh run-strip-reloc.sh run-strip-strmerge.sh \ + run-strip-nobitsalign.sh \ run-unstrip-test.sh run-unstrip-test2.sh \ run-unstrip-test3.sh run-unstrip-M.sh run-elfstrmerge-test.sh \ run-ecp-test.sh run-ecp-test2.sh run-alldts.sh \ @@ -163,6 +164,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-strip-test4.sh run-strip-test5.sh run-strip-test6.sh \ run-strip-test7.sh run-strip-test8.sh run-strip-groups.sh \ run-strip-test9.sh run-strip-test10.sh run-strip-strmerge.sh \ + run-strip-nobitsalign.sh \ + testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \ run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \ hello_ppc64.ko.bz2 hello_s390.ko.bz2 hello_aarch64.ko.bz2 \ run-unstrip-test.sh run-unstrip-test2.sh \ diff --git a/tests/run-strip-nobitsalign.sh b/tests/run-strip-nobitsalign.sh new file mode 100755 index 0000000..db9b1d9 --- /dev/null +++ b/tests/run-strip-nobitsalign.sh @@ -0,0 +1,35 @@ +#! /bin/sh +# Copyright (C) Red Hat, Inc., 2016. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# static unsigned char buffer[4096] __attribute((aligned (4096))); +# +# char +# f (int i) +# { +# return buffer[i]; +# } +# +# int +# main (int argc, char **argv) +# { +# return buffer[argc] == 0; +# } + +original=testfile-nobitsalign +stripped=testfile-nobitsalign.strip + +. $srcdir/run-strip-test.sh diff --git a/tests/run-strip-test.sh b/tests/run-strip-test.sh index 43d27e5..42aa988 100755 --- a/tests/run-strip-test.sh +++ b/tests/run-strip-test.sh @@ -34,13 +34,13 @@ status=0 cmp $stripped testfile.temp || status=$? # Check elflint and the expected result. -testrun ${abs_top_builddir}/src/elflint -q testfile.temp || status=$? +testrun ${abs_top_builddir}/src/elflint --gnu -q testfile.temp || status=$? test -z "$debugfile" || { cmp $debugfile testfile.debug.temp || status=$? # Check elflint and the expected result. -testrun ${abs_top_builddir}/src/elflint -q -d testfile.debug.temp || status=$? +testrun ${abs_top_builddir}/src/elflint --gnu -q -d testfile.debug.temp || status=$? # Now test unstrip recombining those files. testrun ${abs_top_builddir}/src/unstrip -o testfile.unstrip testfile.temp testfile.debug.temp diff --git a/tests/testfile-nobitsalign.bz2 b/tests/testfile-nobitsalign.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..7f0d4249a028e73766908f9ac221174a5b4d33db GIT binary patch literal 2921 zcmV-v3zqakT4*^jL0KkKSu3LM{{RXtfB*mg|Nrj)|NsC0|84*O|Mu^H^;FD$(`@he z>)wBV?_b~vyzVzuKr*&9Y4y~Mv!1il!BlO%?6_)a8d0W<(rDRDOeWBSPeW4>)6(a)Xa zG-y3Q0MHsV8UqtUMt~Y=qtpW?ng9(3hC!#HJws|58e$%x(13swLTx6QLp3o*8BG9Y zqedox88pxh13&{ndYS+RfCEE7000dErho>30g$Qb29qQvBO0EQG=`f=rh$>P0%@j3 znW>r)k)sKwn2Z82h6u(a)tfF_2RjWpT;GHAkLG{67}iGoCkniEYKQ`!{tY8WVHnqfT? z(V}UljS;mxqx43Yj6sk?Pf?8;MhL)$A))D{8es-#0MI6ZiRc72h(G`u000dEriP6H zpwJBgplD(PLlDRSWMt8x41fU8G|&b>0gy5P0B8bKYHDpteu`=8G|*^zfuljEs0N0b z05StZAkYSb)CPb6&`Kny?zfDDZq13&-(4yyW?y_)^KwD)ya+-JFxa*Um&6-`jx zxQqy2HxdAwZ5^oKW*dQxjg2&)SyYQtg++Vy7<;@*&P6J^W27u*79pnu#+C^H4jOT$ zF+xVfK*E|xlt(L6G`y66vxb4F5I}(jl36oOPYI(DVfGNK&b2WpQPQgj641`2nS`0T z?`;OE(lRBn>59cF7qx)w9rIndu}(n~L=kUMwox;JpuDTC1_92949ppskZB~@dM)~k ze~*c&%*BC*G&N*qEnqgchG9^w$%Y)TWfGyp;sKxeQ-pxL1ZGB8#mInpI($t=R;JI> zubd|Wn2f0e;Gj%(yNvDM%6R=2ohMcG%8S`HvGvi|{OrAh>R)#eiG;}jw2WVKrp`$S zT24kankMzXK+!U9(a)_7-b>T9GU$L)v_#H2Kfx$PGIeiX(q0yK;O4Ia40HeMK6XjlU( zsl_2A1L;$eR1`6Y*4mwm`6t5YEYh5%Y*nn1e7 z2^ee=Sj=0dgN|y33T_yZY!G9#l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Dt6&|pj)xc} z?&9N6R+CeCO*_T8>WgaJ_7%LQ(a)U&|x>sIoxci9ueWXOnFi#5MahPDh9xasLk#;3HS zKgGmK^DAMH7I~@}DGYG4d(a)Sba;SIMGp;pz3(T)?N(}sxwbB*dOli3;J)`;9h7Qb{; zkVWGlMRniJU!0|BU~%cR(a)j%jylLp7mvJlkc`mmsRyI)1%E5k*{<)d(1S1&9R79Ca! zpspfzHpfwnsNtvcFLzn>68IwUMv+8d53^^ zfVgFBRtH>LDzkTl0+Mba2*bniF47-Jw4nx7tO-$e^Dyv~ugfMRlv4#E1PG|H^*gLO zO9Pw|rCUeCTr?n>K*@-P0lL$om(a)QPLqvvTI z?j=BkK-?}R746wDYXUNfGY$fk3`(vJjL4#HHQM4Ia?Mxk>ud}vb3*jWT9h@*R(Z9s zqI^2hUmXkk)=1au7ws7sI7-Sw&7dfXWSZ70_)$sNV6@b8l2w`Bav}lnRp!Or)EJ&p85nogX&|CXODf|R?sC{n&_)B4xJa~wP z!uf;}H5vj8BFp{lX&=69%4wL`EZ{IAd?{QjAGqU(a)RZEqe)*k-0VclHw!v(a)el2Vl`} zZuiT$YU9<#CF-ZxxV70x9Td2JQOX6DHaVphcN8cUoyr-ipKFsb&I#7BYeE>vBn!{A zNIQ^C5oZX?^{=giWl2wa3eJYC1&ok*aBx$^WWgHvfaZcTeC|}JV;ctY-+Lk$X|p%g TcR5*om;V=XML1B9E28fIfSNm= literal 0 HcmV?d00001 diff --git a/tests/testfile-nobitsalign.strip.bz2 b/tests/testfile-nobitsalign.strip.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..f72000cc58e6f469bd817c1f13875153b7e64b93 GIT binary patch literal 1723 zcmV;s21NNnT4*^jL0KkKSr|VCdH(a)B3|NsC0_x$$n|NsB*{?GsS|90K(a)g zXc`SNWCnm505l$xKn*esn3)Ap8&EMc9;SdaG-3?^4K&a+83vkY1|Ve60BC3p4FQle z8ZrO|fCeKV#0^YIk)mkS@|u~H)6!!^4H^ccPY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