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

Re: [for-4.18] [PATCH v2] arm/ioreq: guard interaction data on read/write operations


  • To: Julien Grall <julien@xxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Thu, 5 Oct 2023 12:34:04 +0000
  • Accept-language: zh-CN, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.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=7Nof8inWieRpZAyEbPoB6s8OOSWDaMBY29C1EDB/U0g=; b=Y5I0CUqdtxi0jFDX1eoap3GoKotf2VHKd7yE+8U5T4wEncRPZ/aYwi+Cx+1Q2POFQ+IJTJbn7niRE1YXY2JCpuEx0HEDvwp4nk1QS6sH/GTl1DMUCee3gZHeK2vgSvuv2p6CODbgAvFOPRBK5o/yZ1aatWnlgzktWKBEzk0dracGq3/ZU6997JOXxxIN/JRavPrQ+U3qvaU5sYx6NXe1ns74ZomRqYO+cG98A+HjcBG6gVIjr5zluvMO9axbraTGdsW6E+2SmmtFPdm+p0c6sbVE+alsPDVSZjKXJSYPPxa2ftPNmEU92aTBHaLTw0kDt4S3Xrhr0XxrKhIyda0FcQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LEMCSBAWGnBqXLaKq0h4MK3sItybG9x5El9T7t5lcc3DRGZs5WzqQnepmI1T6yq210xR/x3THHbkgtE5V9U0iel6SXaXuzxttp0FuyEpLxhiIIVD+wZVG14YIHm/SbINc2Y+rV0HK7bzLVs9r5Zq/dljI08Wezt9vVS17I7zRLVFOiN6nCSoRnpFUIwKwxjCrBjfwkkd224gKUjFQm65m0X1zSTq0yGQOsnNlBxwJf1qVJ3/6seAcPyL/Mah3Q229cI6cxdaT2XulxGTjmLVdFZ7+WOK+Qts3HsJMNuV3BkT/S5JrSCsk60mgufAQkHquO6uAXSE4V5YGpZ5OpYQxQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Andrii Chepurnyi <Andrii_Chepurnyi@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>, "andrii.chepurnyi82@xxxxxxxxx" <andrii.chepurnyi82@xxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Thu, 05 Oct 2023 12:34:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZ94g6DuMy5FujckaIS3DlGIWhGQ==
  • Thread-topic: [for-4.18] [PATCH v2] arm/ioreq: guard interaction data on read/write operations

Hi Julien,

> On Oct 5, 2023, at 20:30, Julien Grall <julien@xxxxxxx> wrote:
> 
> (+ Henry)

Thanks.

> 
> Hi Andrii,
> 
> @Henry, this patch is a candidate for Xen 4.18. The fix is self-contained in 
> the IOREQ code which is in tech preview. So I think the risk is limited.

Sure, with your comments below properly addressed, I think it is fine
to include this patch in 4.18, so:

Release-acked-by: Henry Wang <Henry.Wang@xxxxxxx>

Kind regards,
Henry

> 
> On 05/10/2023 10:21, Andrii Chepurnyi wrote:
>> For read operations, there's a potential issue when the data field
>> of the ioreq struct is partially updated in the response. To address
>> this, zero data field during read operations. This modification
>> serves as a safeguard against implementations that may inadvertently
>> partially update the data field in response to read requests.
>> For instance, consider an 8-bit read operation. In such cases, QEMU,
>> returns the same content of the dat field with only 8 bits of
>> updated data. This behavior could potentially result in the
>> propagation of incorrect or unintended data to ioreq clients.
>> There is also a good point to guard interaction data with actual size
>> of the interaction.
> 
> I don't quite understand the last sentence. Is it meant to justify why the 
> two other changes? I.e.:
>  * Masking the value for a write
>  * Masking the value returned by the Device-Model
> 
>> > Signed-off-by: Andrii Chepurnyi <andrii_chepurnyi@xxxxxxxx>
>> ---
>>  xen/arch/arm/ioreq.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>> diff --git a/xen/arch/arm/ioreq.c b/xen/arch/arm/ioreq.c
>> index 3bed0a14c0..26dae8ca28 100644
>> --- a/xen/arch/arm/ioreq.c
>> +++ b/xen/arch/arm/ioreq.c
>> @@ -17,6 +17,8 @@ enum io_state handle_ioserv(struct cpu_user_regs *regs, 
>> struct vcpu *v)
>>  {
>>      const union hsr hsr = { .bits = regs->hsr };
>>      const struct hsr_dabt dabt = hsr.dabt;
>> +    const uint8_t access_size = (1 << dabt.size) * 8;
> 
> Please use 1U.
> 
>> +    const uint64_t access_mask = GENMASK_ULL(access_size - 1, 0);
>>      /* Code is similar to handle_read */
>>      register_t r = v->io.req.data;
>>  @@ -26,6 +28,7 @@ enum io_state handle_ioserv(struct cpu_user_regs *regs, 
>> struct vcpu *v)
>>      if ( dabt.write )
>>          return IO_HANDLED;
>>  +    r &= access_mask;
> 
> I would add a comment on top with:
> 
> "The Arm Arm requires the value to be zero-extended to the size of the 
> register. The Device Model is not meant to touch the bits outside of the 
> access size, but let's not trust that."
> 
>>      r = sign_extend(dabt, r);
>>        set_user_reg(regs, dabt.reg, r);
>> @@ -39,6 +42,8 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
>>      struct vcpu_io *vio = &v->io;
>>      const struct instr_details instr = info->dabt_instr;
>>      struct hsr_dabt dabt = info->dabt;
>> +    const uint8_t access_size = (1 << dabt.size) * 8;
> 
> Please use 1U.
> 
>> +    const uint64_t access_mask = GENMASK_ULL(access_size - 1, 0);
>>      ioreq_t p = {
>>          .type = IOREQ_TYPE_COPY,
>>          .addr = info->gpa,
>> @@ -79,8 +84,7 @@ enum io_state try_fwd_ioserv(struct cpu_user_regs *regs,
>>          return IO_HANDLED;
>>        ASSERT(dabt.valid);
>> -
> 
> This change seems to be spurious?
> 
>> -    p.data = get_user_reg(regs, info->dabt.reg);
>> +    p.data = p.dir ? 0 : get_user_reg(regs, info->dabt.reg) & access_mask;
> 
> For this case, I would add:
> 
> "During a write access, the Device Model only need to know the content of the 
> bits associated with the access size (e.g. for 8-bit, the lower 8-bits). 
> During a read access, the Device Model don't need to know any value. So 
> restrict the value it can access."
> 
> Cheers,
> 
> -- 
> Julien Grall




 


Rackspace

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