Re: [Qemu-devel] [PATCH v2] bt: use size_t type for length parameters instead of int

2019-01-29 Thread Hugo Lefeuvre
Hi Philippe,

> I have been assigned to fix this issue, but rather fixing locally this
> BT device, fix the pattern on all devices.
> I'll post the series during the week and Cc you (and eventually the
> Debian LTS list when it gets merged). The series obsoletes this patch,
> so the plan is to not apply it.

Thanks ! I will wait for your patch then.

> > Any reason why assert() calls are used here ?
> > 
> > These checks should always be executed, but they won't if user compiles
> > without asserts. Also, AFAIK any assert failure will stop the qemu host
> > process which is not what we want in this case.
> 
> There was a discussion about this, and the outcome is QEMU does not
> support building without assertions. See this commit:
> 
> https://git.qemu.org/?p=qemu.git;a=blobdiff;f=include/qemu/osdep.h;h=9966638;hp=6855b94;hb=262a69f42;hpb=825bfa005

Makes sense. But I'm still sceptical about assert() being used here.

For example:

@@ -113,6 +113,7 @@ static void vhci_host_send(void *opaque,
 static uint8_t buf[4096];
 
 buf[0] = type;
+assert(len < sizeof(buf));
 memcpy(buf + 1, data, len);
 
 while (write(s->fd, buf, len + 1) < 0)

From my understanding assert() calls are supposed to be a way to verify
code assumptions at runtime. assert failures are always bugs, so they
terminate the process.

If len is passed by guest systems, an excessive value should not be
considered a bug but invalid user passed input, that is normal behaviour,
right? In this case I expect qemu to simply reject the input instead of
triggering an assert failure and terminating.

regards,
 Hugo

-- 
Hugo Lefeuvre (hle)|www.owl.eu.com
RSA4096_ 360B 03B3 BF27 4F4D 7A3F D5E8 14AA 1EB8 A247 3DFD
ed25519_ 37B2 6D38 0B25 B8A2 6B9F 3A65 A36F 5357 5F2D DC4C


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v2] bt: use size_t type for length parameters instead of int

2019-01-28 Thread Philippe Mathieu-Daudé
Hi Hugo,

On 1/28/19 10:31 AM, Hugo Lefeuvre wrote:
> Hi,
> 
>> The length parameter values are not negative, thus use an unsigned
>> type 'size_t' for them. Many routines pass 'len' values to memcpy(3)
>> calls. If it was negative, it could lead to memory corruption issues.
>> Add check to avoid it.
> 
> I'm working on a Debian LTS security update for qemu and am currently
> thinking about addressing this issue as well.
> 
> I see this patch has not been applied yet and the bluetooth subsystem
> is pending deprecation. Are you still considering to apply it?

I have been assigned to fix this issue, but rather fixing locally this
BT device, fix the pattern on all devices.
I'll post the series during the week and Cc you (and eventually the
Debian LTS list when it gets merged). The series obsoletes this patch,
so the plan is to not apply it.

> 
>> @@ -113,6 +113,7 @@ static void vhci_host_send(void *opaque,
>>  static uint8_t buf[4096];
>>  
>>  buf[0] = type;
>> +assert(len < sizeof(buf));
>>  memcpy(buf + 1, data, len);
>>  
>>  while (write(s->fd, buf, len + 1) < 0)
> 
> Any reason why assert() calls are used here ?
> 
> These checks should always be executed, but they won't if user compiles
> without asserts. Also, AFAIK any assert failure will stop the qemu host
> process which is not what we want in this case.

There was a discussion about this, and the outcome is QEMU does not
support building without assertions. See this commit:

https://git.qemu.org/?p=qemu.git;a=blobdiff;f=include/qemu/osdep.h;h=9966638;hp=6855b94;hb=262a69f42;hpb=825bfa005

Regards,

Phil.



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2] bt: use size_t type for length parameters instead of int

2019-01-28 Thread Hugo Lefeuvre
Hi,

> The length parameter values are not negative, thus use an unsigned
> type 'size_t' for them. Many routines pass 'len' values to memcpy(3)
> calls. If it was negative, it could lead to memory corruption issues.
> Add check to avoid it.

I'm working on a Debian LTS security update for qemu and am currently
thinking about addressing this issue as well.

I see this patch has not been applied yet and the bluetooth subsystem
is pending deprecation. Are you still considering to apply it?

> @@ -113,6 +113,7 @@ static void vhci_host_send(void *opaque,
>  static uint8_t buf[4096];
>  
>  buf[0] = type;
> +assert(len < sizeof(buf));
>  memcpy(buf + 1, data, len);
>  
>  while (write(s->fd, buf, len + 1) < 0)

Any reason why assert() calls are used here ?

These checks should always be executed, but they won't if user compiles
without asserts. Also, AFAIK any assert failure will stop the qemu host
process which is not what we want in this case.

regards,
 Hugo

-- 
Hugo Lefeuvre (hle)|www.owl.eu.com
RSA4096_ 360B 03B3 BF27 4F4D 7A3F D5E8 14AA 1EB8 A247 3DFD
ed25519_ 37B2 6D38 0B25 B8A2 6B9F 3A65 A36F 5357 5F2D DC4C


signature.asc
Description: PGP signature