[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 2/2] xen: Fix latent check-endbr.sh bug with 32bit build environments


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Mon, 18 Jul 2022 09:31:45 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=g6TxDv8L6D3sVlzAgOLhq2K8/C0ssrD28Etz2HezzaM=; b=Jd9cqJhPCuTqvssTg28O64NIBocJuU4uwjSNvNp3UcmfKEzADiZ1uXnv06WITBxu14uxvid8iZXpXs7bezga7bI3a+VE0ymv7+aO2jN1nNzr/H9sp6bv9hA4dVEBUPRpfJtFtogy5NoF9zkhOUssjIVH9c+S8RCzc8Xf+4j58w7lrzPX6bUcJBpmKnVl85AwgoCKsc4C8cxYegAXJe/AXGF4Wnif2z+mwhEPiIO0byCSSGwbZSHNQZv4flAl4BKNY4KUdyV9krE05F+BXflcWnD9PpZWs18wDpHMe2UtJ6cS0TyCqH/XJFTiOgW23JBtsXKWFCDiiITb6jf+l+/Oiw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HURXq/rgyC+PfMiyS4DNgbBm06CkQqbgXbRBGO0d0mCoPuP9Zr5s53ujajKQ/qJMo/6GRk0ijMsscqqHKyJggH8PTiCpHaXVf8lXqiJX4fq/jwbkel0aEbFcgIgonJImuWZHkTUaQSO3At7bsVWjL1w17twjwVuhFK4QR3yBdVR+ltdYq2CIGBlLxbjAhmCjQbNV0RpNtl9vcCNamzOb+dnFPTpfuKvvTXWSqZK3SdCP0otZQbuENiYmEPUiHdiFJOOzXG/kyMDM0P14nzJHaCFib9cHsYSn+jUaZwH+SwQfQ/542NquJNcYWFEjvSZ9LgxIxl9yxF7cRUqiDMKaow==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: George Dunlap <George.Dunlap@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Luca Fancellu <Luca.Fancellu@xxxxxxx>, Mathieu Tarral <mathieu.tarral@xxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 18 Jul 2022 09:32:04 +0000
  • Ironport-data: A9a23:nxA9F6veFMkVNnufsug0GxU+yufnOphVZtUHDcmfNp3fP3jJ3xfKXnsEbRFcyGXui9imYTMeS5SwoJmzjKRV9u3v4DYpZuM8h77rr09jo4IdxTGCvyVmeAIwTsNIyoBSI6Af0iPgdrLZQ2WD+PpWMVcanmDXhGfVcMvItJs5CcbsPrqLUGUPz53XtP5MjYBzlU91T8fRt5BGY92KCbBxkO8yNJ+YjCDGHyhP9/75wbiV3MhypkGfBzBQMCGFwPPiF3yiCMBpSA8O8qH3zQ5JoKbk5IqSVu/5FmMhUDud10jCyyKPJ5SZCBV+UFqt301czi4e/jBHVxRn+WOgo4+MTDloAox57B5V/1N7+FlXgeR90QOITOAb4Wd04958z8Pg+o/F+TOOrI5MpsLztEg9J/r6OeOrVVzTyiA0XYvJ+jPM8zf4wB7pVMb+kZomc2s1HX5lco/7PZkgO00dOfSw5yaGCPfVKHu479qgt+iGjUWWdfhaWCZyiZExzdQCIdaNrEYooD1kXUipgdZj/NWgAPWwvNEDmw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project.org>
  • Thread-index: AQHYmE6f3nf19rITF02bMhbJMzY4w62D3CgAgAAFn4A=
  • Thread-topic: [PATCH v2 2/2] xen: Fix latent check-endbr.sh bug with 32bit build environments

On 18/07/2022 10:11, Jan Beulich wrote:
> On 15.07.2022 15:26, Andrew Cooper wrote:
>> While Xen's current VMA means it works, the mawk fix (i.e. using $((0xN)) in
>> the shell) isn't portable in 32bit shells.  See the code comment for the fix.
>>
>> The fix found a second latent bug.  Recombining $vma_hi/lo should have used
>> printf "%s%08x" and only worked previously because $vma_lo had bits set in
>> it's top nibble.  Combining with the main fix, %08x becomes %07x.
>>
>> Fixes: $XXX patch 1
>> Reported-by: Jan Beulich <JBeulich@xxxxxxxx>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>

Thanks, but...

> with, I guess, ...
>
>> --- a/xen/tools/check-endbr.sh
>> +++ b/xen/tools/check-endbr.sh
>> @@ -61,19 +61,36 @@ ${OBJDUMP} -j .text $1 -d -w | grep '    endbr64 *$' | 
>> cut -f 1 -d ':' > $VALID &
>>  #    the lower bits, rounding integers to the nearest 4k.
>>  #
>>  #    Instead, use the fact that Xen's .text is within a 1G aligned region, 
>> and
>> -#    split the VMA in half so AWK's numeric addition is only working on 32 
>> bit
>> -#    numbers, which don't lose precision.
>> +#    split the VMA so AWK's numeric addition is only working on <32 bit
>> +#    numbers, which don't lose precision.  (See point 5)
>>  #
>>  # 4) MAWK doesn't support plain hex constants (an optional part of the POSIX
>>  #    spec), and GAWK and MAWK can't agree on how to work with hex constants 
>> in
>>  #    a string.  Use the shell to convert $vma_lo to decimal before passing 
>> to
>>  #    AWK.
>>  #
>> +# 5) Point 4 isn't fully portable.  POSIX only requires that $((0xN)) be
>> +#    evaluated as long, which in 32bit shells turns negative if bit 31 of 
>> the
>> +#    VMA is set.  AWK then interprets this negative number as a double 
>> before
>> +#    adding the offsets from the binary grep.
>> +#
>> +#    Instead of doing an 8/8 split with vma_hi/lo, do a 9/7 split.
>> +#
>> +#    The consequence of this is that for all offsets, $vma_lo + offset needs
>> +#    to be less that 256M (i.e. 7 nibbles) so as to be successfully 
>> recombined
>> +#    with the 9 nibbles of $vma_hi.  This is fine; .text is at the start of 
>> a
>> +#    1G aligned region, and Xen is far far smaller than 256M, but leave 
>> safety
>> +#    check nevertheless.
>> +#
>>  eval $(${OBJDUMP} -j .text $1 -h |
>> -    $AWK '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 8), 
>> substr($4, 9, 16)}')
>> +    $AWK '$2 == ".text" {printf "vma_hi=%s\nvma_lo=%s\n", substr($4, 1, 9), 
>> substr($4, 10, 16)}')
>>  
>>  ${OBJCOPY} -j .text $1 -O binary $TEXT_BIN
>>  
>> +bin_sz=$(stat -c '%s' $TEXT_BIN)
>> +[ "$bin_sz" -ge $(((1 << 28) - $vma_lo)) ] &&
>> +    { echo "$MSG_PFX Error: .text offsets can exceed 256M" >&2; exit 1; }
> ... s/can/cannot/ ?

Why?  "Can" is correct here.  If the offsets can't exceed 256M, then
everything is good.

~Andrew

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.