* Re: [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access
2018-10-26 12:33 [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access P J P
@ 2018-10-26 16:40 ` Cédric Le Goater
2018-11-03 13:28 ` David Gibson
2018-11-08 9:10 ` Laurent Vivier
2 siblings, 0 replies; 5+ messages in thread
From: Cédric Le Goater @ 2018-10-26 16:40 UTC (permalink / raw)
To: P J P, Qemu Developers
Cc: Moguofang, David Gibson, Alexander Graf, Benjamin Herrenschmidt,
Prasad J Pandit
On 10/26/18 2:33 PM, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While performing PowerNV memory r/w operations, the access length
> 'sz' could exceed the data[4] buffer size. Add check to avoid OOB
> access.
>
> Reported-by: Moguofang <moguofang@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Thanks,
C.
> ---
> hw/ppc/pnv_lpc.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> Update v2: add error log message
> -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05750.html
>
> diff --git a/hw/ppc/pnv_lpc.c b/hw/ppc/pnv_lpc.c
> index d7721320a2..172a915cfc 100644
> --- a/hw/ppc/pnv_lpc.c
> +++ b/hw/ppc/pnv_lpc.c
> @@ -155,9 +155,15 @@ static void pnv_lpc_do_eccb(PnvLpcController *lpc, uint64_t cmd)
> /* XXX Check for magic bits at the top, addr size etc... */
> unsigned int sz = (cmd & ECCB_CTL_SZ_MASK) >> ECCB_CTL_SZ_LSH;
> uint32_t opb_addr = cmd & ECCB_CTL_ADDR_MASK;
> - uint8_t data[4];
> + uint8_t data[8];
> bool success;
>
> + if (sz > sizeof(data)) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "ECCB: invalid operation at @0x%08x size %d\n", opb_addr, sz);
> + return;
> + }
> +
> if (cmd & ECCB_CTL_READ) {
> success = opb_read(lpc, opb_addr, data, sz);
> if (success) {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access
2018-10-26 12:33 [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access P J P
2018-10-26 16:40 ` Cédric Le Goater
@ 2018-11-03 13:28 ` David Gibson
2018-11-08 9:10 ` Laurent Vivier
2 siblings, 0 replies; 5+ messages in thread
From: David Gibson @ 2018-11-03 13:28 UTC (permalink / raw)
To: P J P
Cc: Qemu Developers, Cédric Le Goater, Moguofang, Alexander Graf,
Benjamin Herrenschmidt, Prasad J Pandit
[-- Attachment #1: Type: text/plain, Size: 1625 bytes --]
On Fri, Oct 26, 2018 at 06:03:58PM +0530, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While performing PowerNV memory r/w operations, the access length
> 'sz' could exceed the data[4] buffer size. Add check to avoid OOB
> access.
>
> Reported-by: Moguofang <moguofang@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Applied to ppc-for-3.1, thanks.
> ---
> hw/ppc/pnv_lpc.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> Update v2: add error log message
> -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05750.html
>
> diff --git a/hw/ppc/pnv_lpc.c b/hw/ppc/pnv_lpc.c
> index d7721320a2..172a915cfc 100644
> --- a/hw/ppc/pnv_lpc.c
> +++ b/hw/ppc/pnv_lpc.c
> @@ -155,9 +155,15 @@ static void pnv_lpc_do_eccb(PnvLpcController *lpc, uint64_t cmd)
> /* XXX Check for magic bits at the top, addr size etc... */
> unsigned int sz = (cmd & ECCB_CTL_SZ_MASK) >> ECCB_CTL_SZ_LSH;
> uint32_t opb_addr = cmd & ECCB_CTL_ADDR_MASK;
> - uint8_t data[4];
> + uint8_t data[8];
> bool success;
>
> + if (sz > sizeof(data)) {
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "ECCB: invalid operation at @0x%08x size %d\n", opb_addr, sz);
> + return;
> + }
> +
> if (cmd & ECCB_CTL_READ) {
> success = opb_read(lpc, opb_addr, data, sz);
> if (success) {
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access
2018-10-26 12:33 [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access P J P
2018-10-26 16:40 ` Cédric Le Goater
2018-11-03 13:28 ` David Gibson
@ 2018-11-08 9:10 ` Laurent Vivier
2018-11-08 16:51 ` Cédric Le Goater
2 siblings, 1 reply; 5+ messages in thread
From: Laurent Vivier @ 2018-11-08 9:10 UTC (permalink / raw)
To: P J P, Qemu Developers
Cc: Prasad J Pandit, Alexander Graf, Cédric Le Goater, Moguofang,
David Gibson
On 26/10/2018 14:33, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> While performing PowerNV memory r/w operations, the access length
> 'sz' could exceed the data[4] buffer size. Add check to avoid OOB
> access.
>
> Reported-by: Moguofang <moguofang@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> hw/ppc/pnv_lpc.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> Update v2: add error log message
> -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05750.html
>
> diff --git a/hw/ppc/pnv_lpc.c b/hw/ppc/pnv_lpc.c
> index d7721320a2..172a915cfc 100644
> --- a/hw/ppc/pnv_lpc.c
> +++ b/hw/ppc/pnv_lpc.c
> @@ -155,9 +155,15 @@ static void pnv_lpc_do_eccb(PnvLpcController *lpc, uint64_t cmd)
> /* XXX Check for magic bits at the top, addr size etc... */
> unsigned int sz = (cmd & ECCB_CTL_SZ_MASK) >> ECCB_CTL_SZ_LSH;
> uint32_t opb_addr = cmd & ECCB_CTL_ADDR_MASK;
> - uint8_t data[4];
> + uint8_t data[8];
> bool success;
I'm not sure 8 is enough.
ECCB_CTL_SZ_MASK is PPC_BITMASK(4, 7), and ECCB_CTL_SZ_LSH is (63 - 7).
So the bitmask is 4 bits wide, and thus sz can be 0 to 15.
I think data[] size should be 16.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v2] ppc/pnv: check size before data buffer access
2018-11-08 9:10 ` Laurent Vivier
@ 2018-11-08 16:51 ` Cédric Le Goater
0 siblings, 0 replies; 5+ messages in thread
From: Cédric Le Goater @ 2018-11-08 16:51 UTC (permalink / raw)
To: Laurent Vivier, P J P, Qemu Developers
Cc: Prasad J Pandit, Alexander Graf, Moguofang, David Gibson
Hello Laurent,
On 11/8/18 10:10 AM, Laurent Vivier wrote:
> On 26/10/2018 14:33, P J P wrote:
>> From: Prasad J Pandit <pjp@fedoraproject.org>
>>
>> While performing PowerNV memory r/w operations, the access length
>> 'sz' could exceed the data[4] buffer size. Add check to avoid OOB
>> access.
>>
>> Reported-by: Moguofang <moguofang@huawei.com>
>> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
>> ---
>> hw/ppc/pnv_lpc.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> Update v2: add error log message
>> -> https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05750.html
>>
>> diff --git a/hw/ppc/pnv_lpc.c b/hw/ppc/pnv_lpc.c
>> index d7721320a2..172a915cfc 100644
>> --- a/hw/ppc/pnv_lpc.c
>> +++ b/hw/ppc/pnv_lpc.c
>> @@ -155,9 +155,15 @@ static void pnv_lpc_do_eccb(PnvLpcController *lpc, uint64_t cmd)
>> /* XXX Check for magic bits at the top, addr size etc... */
>> unsigned int sz = (cmd & ECCB_CTL_SZ_MASK) >> ECCB_CTL_SZ_LSH;
>> uint32_t opb_addr = cmd & ECCB_CTL_ADDR_MASK;
>> - uint8_t data[4];
>> + uint8_t data[8];
>> bool success;
>
> I'm not sure 8 is enough.
>
> ECCB_CTL_SZ_MASK is PPC_BITMASK(4, 7), and ECCB_CTL_SZ_LSH is (63 - 7).
> So the bitmask is 4 bits wide, and thus sz can be 0 to 15.
> I think data[] size should be 16.
The bitmask allows more that 8 but the specs says that 1, 2, 4, 8 are the
possible value size. So We should be fine.
C.
>
> Thanks,
> Laurent
>
^ permalink raw reply [flat|nested] 5+ messages in thread