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

Re: [PATCH v2.1 6.5/70] x86/kexec: Annotate embedded data with ELF metadata


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Thu, 17 Feb 2022 12:06:39 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=UwxJpcOon4iEybAaIBAUJENkEQjUrLrGY7Hrv1Ijb3M=; b=Sfl47qjmKdXC+xlTvKYDN10cG13ro4yIP2MZ3tbPM54yh3EIW3Ru1iG8ZoitQ5r3S/HY7A1b7hpc5AsAOII0zvDJpwSLUFX8KlccbNuuNtQ/N7vTFVnmu/5sTWTBpeyKVGqaTxYr7fjfjNReI/uvXSstc8Bq/lq6QuqgSb4xPWgYzwgalyqEK9Dzics5thd+JuQ5WXs+C7U95DMWMOM7QSgMKdAyNN9ruAvuz1VpkgkVeMwA63ZCPJbPG/RoGkDyEHEoIpEif0p1l5xq4mrUq5JeBT1z8S5RKnFXTzwgIfJw31/iX4fl4ZoG7q6sjwHG7GUUZ37uIMPwzIESKImItQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UWZlY8eyWtjGZKVs6CKUSWsEREUYIA1oV0ETBvotN3yzy6MNaTejp0fAhqm/f+sA+mb2Fyq0C0Go6msAGcriPRYNy6mfAg4YoAFZ1nO9aP5Er1VpdRXOmwM6DRHZl0aTrpXk6MqSz7EvzkvrSMmnYibZkQYt+Dh3A+MNMRuMw4aJB0A+tE1r5L52H+DWN0Qo0F1VZREklTS9Wm6lMJhVviXB1fsCSLVGFP3pX+2ZMUCkKc7FksPIHz3tT4UGWmMSiCjHptl/Ghss2nXNf/PI6GkYE0FA75mNMYR8MpIcp9lz80FhGv//sqsTDiazQcCoZBwtMIvf3PwOw4urYRW1Lg==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 17 Feb 2022 12:06:58 +0000
  • Ironport-data: A9a23:9XYcZ6x2mJcFrAQ5Tkp6t+fswSrEfRIJ4+MujC+fZmUNrF6WrkUAx mBOWzjVPqneMTT1KN8laI3goUsPvsWEzYU1TQNk+yAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnvopW1TYhSEUOZugH9IQM8aZfHAhLeNYYH1500g7wbdm2tcAbeWRWGthh /uj+6UzB3f9s9JEGjp8B3Wr8U4HUFza4Vv0j3RmDRx5lAa2e0o9VfrzEZqZPXrgKrS4K8bhL wr1IBNVyUuCl/slIovNfr8W6STmSJaKVeSFoiI+t6RPHnGuD8H9u0o2HKN0VKtZt9mGt9Zj9 /ZxuqS7dSokA/KXouosfSJaQy4raMWq+JefSZS+mcmazkmAeHrw2fR+SkoxOOX0+M4uXzsIr 6ZBbmlQMFbT3Ipaw5riIgVoru0lINPmI8U0vXZ4wCuCJf0nXYrCU+PB4towMDIY2JseQ6uHN ppxhTxHdE6RYgBPC2srJZMjx+imiyLWQ2Z0gQfAzUYwyzeKl1EguFT3C/LFd9rPSchLk0Kwo mPd43+/EhwcLMaYyzeO7jSrnOCntTz/cJIfEvu/7PECqF+Zy3EXCRYWfUCmuvT/gUm7M++zM GRNpHBo9/JrshX2EJ+tBHVUvUJooDYaSeVzL+IC4z2gx5eLuDyXN0Y/TG5OPYlOWNANeRQm0 V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OD8Kadb/DDlytHpuQ699QYUcegCUcgJhG0ZajpzUHcGPzWubaBJTq Z0jfA3wwZIDE5nCPhTcUN1ONQryee79q7OUFojPVoK+QOOhTSn5PrRCB6DxCoTVDtJ3PML7X XFuxaR3NThj9iLjjvnk0PD5ZVfn9XsjvFZAtaXt8QTIjLwzi61eYVaXaGYtjxdmpDs1L9qqq iIn/4TBbU115rjRBDynfIr4Xi47N8a0Q6n9bZfuwq6nSW2fkNgNyMLv/MnTvKQ0TtfgDg76t MX44vRjesmMfuL9h6NluTgRlVkkFG5rmEllvNWh3tDUZEGYLsUtoAH+lhJea1wVh4SxbpXWN WGNvusr8q+sGnqG0zxry1q2pihT34zFhCJTgwLvdGUySFfmDR8w1EDzMISk38c/NZlIqM0q9 jsI+BtjvVDX8UWZaVyCKMIRta2EHXERVbJPHiJKVrqGakbMzbGqoLx4r8y+Oa2EaZ4gacaid DEShdVpGQyc0XhBYmH24BK6AnERCGnUTHk2qhlltFEU33HNczW2AG4OSITevqb0oIi65fgKo WO0bptcoreEVc=
  • Ironport-sdr: jkZzGRfK5o3BLOqBOsLTIGaFQYAoPpCbATj+zgtzoeN1lLCe4IQQCmMAlYSMfm0TB+hVyo5WpH ye50oVLq+p/LbIosIOo7x3EgLPLgPwKaqOq2VRDZ5c2qoNgaYga80O/WT3y6ULOXo7ijsKiBUc Z/czcMXvqE8hiHUW4eRNjY0+16L9Pwd+Qm7oM0/kwn38aI+cRd515W5VvPSQbZ7wjyb9Ag21UA s00k7xANcr4JmNIaN5frcSygZGxjsl24jAdSCns2clO5ffAUfdvNDxoWbA6Ai1AiVCWNnekgb8 U+IhJ3qJLimxTn64ch6OvIxs
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYI+WIB3ag8ccQV0mMbUcu9Q8VKKyXjjSAgAAXo4A=
  • Thread-topic: [PATCH v2.1 6.5/70] x86/kexec: Annotate embedded data with ELF metadata

On 17/02/2022 10:42, Jan Beulich wrote:
> On 17.02.2022 11:01, Andrew Cooper wrote:
>> Scanning for embedded endbranch instructions involves parsing the .text
>> disassembly.  Data in the kexec trampoline has no ELF metadata, so objdump
>> treats it as instructions and tries to disassemble.  Convert:
>>
>>   ffff82d040396108 <compatibility_mode_far>:
> What about the (possible) padding ahead of this? Should the .align
> there perhaps specify a filler character?

What about it?  It's just long nops like all other padding in .text

ffff82d040396101:       ff d5                   call   *%ebp
ffff82d040396103:       0f 0b                   ud2    
ffff82d040396105:       0f 1f 00                nopl   (%eax)

ffff82d040396108 <compatibility_mode_far>:
ffff82d040396108:       00 00 00 00 10
00                                   ......

And for this problem, we don't need to care about the behaviour of any
pre-CET version of binutils.

>>   ffff82d040396108:       00 00                   add    %al,(%rax)
>>   ffff82d04039610a:       00 00                   add    %al,(%rax)
>>   ffff82d04039610c:       10 00                   adc    %al,(%rax)
>>
>>   ffff82d04039610e <compat_mode_gdt_desc>:
>>   ffff82d04039610e:       17                      (bad)
>>           ...
>>
>>   ffff82d040396118 <compat_mode_gdt>:
>>           ...
>>   ffff82d040396120:       ff                      (bad)
>>   ffff82d040396121:       ff 00                   incl   (%rax)
>>   ffff82d040396123:       00 00                   add    %al,(%rax)
>>   ffff82d040396125:       93                      xchg   %eax,%ebx
>>   ffff82d040396126:       cf                      iret
>>   ffff82d040396127:       00 ff                   add    %bh,%bh
>>   ffff82d040396129:       ff 00                   incl   (%rax)
>>   ffff82d04039612b:       00 00                   add    %al,(%rax)
>>   ffff82d04039612d:       9b                      fwait
>>   ffff82d04039612e:       cf                      iret
>>           ...
>>
>>   ffff82d040396130 <compat_mode_idt>:
>>           ...
>>
>>   ffff82d0403961b6 <kexec_reloc_size>:
>>   ffff82d0403961b6:       b6 01                   mov    $0x1,%dh
>>           ...
>>
>> to:
>>
>>   ffff82d040396108 <compatibility_mode_far>:
>>   ffff82d040396108:       00 00 00 00 10 00                               
>> ......
>>
>>   ffff82d04039610e <compat_mode_gdt_desc>:
>>   ffff82d04039610e:       17 00 00 00 00 00 00 00 00 00                   
>> ..........
>>
>>   ffff82d040396118 <compat_mode_gdt>:
>>           ...
>>   ffff82d040396120:       ff ff 00 00 00 93 cf 00 ff ff 00 00 00 9b cf 00 
>> ................
>>
>>   ffff82d040396130 <compat_mode_idt>:
>>   ffff82d040396130:       00 00 00 00 00 00                               
>> ......
> With the .size directives added, can we rely on consistent (past,
> present, and future) objcopy behavior for padding gaps?

Of course not.  We don't know how things will develop in the future. 
The best we can do is hope that it doesn't change too much.

But on that note, the way this would go wrong is the binary scan finding
an endbr that wasn't disassembled properly here, for whatever reason.

>  It just so
> happens that there's no 4-byte gap between compat_mode_gdt_desc and
> compat_mode_gdt. Changing the .align ahead of compatibility_mode_far
> would eliminate the risk of padding appearing if the code further up
> changed.

Gaps will be formed of long nops because we're in .text, and they merge
with the previous data blob (see below).

>
>>   ffff82d040396136 <reloc_stack>:
>>           ...
> Now this is particularly puzzling: Us setting %rsp to an unaligned
> address is clearly not ABI-conforming. Since you're fiddling with
> all of this already anyway, how about fixing this at the same time?
> Of course there would then appear padding ahead of the stack, unless
> the stack was moved up some.

Oh - I'd not even noticed that.  Luckily there is no ABI which matters,
because it's the call/push/pop's in this file alone.

With an align 8, we get:

ffff82d0403a7138 <compat_mode_idt>:
ffff82d0403a7138:       00 00 00 00 00 00 66
90                             ......f.

ffff82d0403a7140 <reloc_stack>:
        ...

where the 66 90 in compat_mode_idt is the padding.  Recall c/s 9fd181540c7e6

>
>> @@ -175,10 +175,16 @@ compatibility_mode_far:
>>          .long 0x00000000             /* set in call_32_bit above */
>>          .word 0x0010
>>  
>> +        .type compatibility_mode_far, @object
>> +        .size compatibility_mode_far, . - compatibility_mode_far
>> +
>>  compat_mode_gdt_desc:
>>          .word .Lcompat_mode_gdt_end - compat_mode_gdt -1
>>          .quad 0x0000000000000000     /* set in call_32_bit above */
>>  
>> +        .type compat_mode_gdt_desc, @object
>> +        .size compat_mode_gdt_desc, . - compat_mode_gdt_desc
> Side note: We really ought to gain something like OBJECT(name) to avoid
> c'n'p mistakes not updating correctly all three symbol name instances.

I've got an intern working on it.

>
>> --- a/xen/arch/x86/xen.lds.S
>> +++ b/xen/arch/x86/xen.lds.S
>> @@ -87,6 +87,7 @@ SECTIONS
>>         *(.text.unlikely)
>>         *(.fixup)
>>         *(.text.kexec)
>> +       kexec_reloc_end = .;
> Does this maybe want aligning on a 4- or even 8-byte boundary? If
> so, imo preferably not here, but by adding a trailing .align in the
> .S file.

There's no special need for it to be aligned, and it is anyway as the
stack is the last object in it.

The sole user is the memcpy() size calculation moving the trampoline to
its destination page in the kexec reserved area.

~Andrew

 


Rackspace

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