All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Mauro Matteo Cascella <mcascell@redhat.com>,
	Frederic Konrad <konrad.frederic@yahoo.fr>,
	Andrew Jeffery <andrew@aj.id.au>,
	QEMU Developers <qemu-devel@nongnu.org>,
	qemu-arm <qemu-arm@nongnu.org>, Joel Stanley <joel@jms.id.au>,
	Ziming Zhang <ezrakiez@gmail.com>
Subject: Re: [PATCH for-5.2 14/19] ftgmac100: Fix integer overflow in ftgmac100_do_tx()
Date: Tue, 18 Aug 2020 16:54:02 +0200	[thread overview]
Message-ID: <7a6f7515-9a5f-3160-6187-675032ce8c75@kaod.org> (raw)
In-Reply-To: <CAFEAcA_rAre03ATda5rxgear4wsoef2-qD5SyAjunH8QW65W2A@mail.gmail.com>

On 8/11/20 2:39 PM, Peter Maydell wrote:
> On Thu, 6 Aug 2020 at 14:21, Cédric Le Goater <clg@kaod.org> wrote:
>>
>> When inserting the VLAN tag in packets, memmove() can generate an
>> integer overflow for packets whose length is less than 12 bytes.
>>
>> Check length against the size of the ethernet header (14 bytes) to
>> avoid the crash and return FTGMAC100_INT_XPKT_LOST status. This seems
>> like a good modeling choice even if Aspeed does not specify anything
>> in that case.
>>
>> Cc: Frederic Konrad <konrad.frederic@yahoo.fr>
>> Cc: Mauro Matteo Cascella <mcascell@redhat.com>
>> Reported-by: Ziming Zhang <ezrakiez@gmail.com>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>  hw/net/ftgmac100.c | 19 +++++++++++++++----
>>  1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
>> index 280aa3d3a1e2..987b843fabc4 100644
>> --- a/hw/net/ftgmac100.c
>> +++ b/hw/net/ftgmac100.c
>> @@ -540,10 +540,21 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
>>                  s->isr |= FTGMAC100_INT_XPKT_LOST;
>>                  len =  sizeof(s->frame) - frame_size - 4;
>>              }
>> -            memmove(ptr + 16, ptr + 12, len - 12);
>> -            stw_be_p(ptr + 12, ETH_P_VLAN);
>> -            stw_be_p(ptr + 14, bd.des1);
>> -            len += 4;
>> +
>> +            if (len < sizeof(struct eth_header)) {
>> +                qemu_log_mask(LOG_GUEST_ERROR,
>> +                         "%s: frame too small for VLAN insertion : %d bytes\n",
>> +                         __func__, len);
>> +                s->isr |= FTGMAC100_INT_XPKT_LOST;
>> +            } else {
>> +                uint8_t *vlan_hdr = ptr + (ETH_ALEN * 2);
>> +                uint8_t *payload = vlan_hdr + sizeof(struct vlan_header);
>> +
>> +                memmove(payload, vlan_hdr, len - (ETH_ALEN * 2));
>> +                stw_be_p(vlan_hdr, ETH_P_VLAN);
>> +                stw_be_p(vlan_hdr + 2, FTGMAC100_TXDES1_VLANTAG_CI(bd.des1));
>> +                len += sizeof(struct vlan_header);
>> +            }
>>          }
> 
> If you want to be picky, this will unnecessarily fail for the case of
> a packet that is big enough for the vlan header but which has been
> split up into multiple tx descriptors such that the first one is
> smaller than the size of the eth_header. You could fix that by
> doing the insertion of the vlan tag when you process the TXDES0_LTS
> descriptor rather than when you process the TXDES0_FTS one. (We
> already save the des1 info where the INS_VLANTAG flag is in the
> 'flags' variable, so we have that available for the LTS descriptor code.)

yes. Good idea. The code is cleaner and the driver can even survive 
a bogus frame.

I will send a new version, without the Tested and Reviewed tags.

To reproduce, I have created a little kernel module tester based 
on the POC proposed by Ziming, which was for another MAC.

	https://github.com/legoater/ftgmac100-test

Thanks,

C. 
 



  reply	other threads:[~2020-08-18 15:32 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-06 13:20 [PATCH for-5.2 00/19] aspeed: mostly cleanups and some extensions Cédric Le Goater
2020-08-06 13:20 ` [PATCH for-5.2 01/19] m25p80: Return the JEDEC ID twice for mx25l25635e Cédric Le Goater
2020-08-06 13:20 ` [PATCH for-5.2 02/19] m25p80: Add support for mx25l25635f Cédric Le Goater
2020-08-06 22:55   ` Joel Stanley
2020-08-07  5:59     ` Cédric Le Goater
2020-08-06 13:20 ` [PATCH for-5.2 03/19] m25p80: Add support for n25q512ax3 Cédric Le Goater
2020-08-06 22:56   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 04/19] aspeed/scu: Fix valid access size on AST2400 Cédric Le Goater
2020-08-06 13:32   ` Philippe Mathieu-Daudé
2020-08-06 13:49     ` Cédric Le Goater
2020-08-06 14:08       ` Philippe Mathieu-Daudé
2020-08-06 22:57   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 05/19] hw/arm/aspeed: Add board model for Supermicro X11 BMC Cédric Le Goater
2020-08-06 23:23   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 06/19] aspeed/smc: Fix MemoryRegionOps definition Cédric Le Goater
2020-08-06 23:24   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 07/19] aspeed/smc: Fix max_slaves of the legacy SMC device Cédric Le Goater
2020-08-06 23:24   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 08/19] aspeed/sdhci: Fix reset sequence Cédric Le Goater
2020-08-06 23:42   ` Joel Stanley
2020-08-07  6:04     ` Cédric Le Goater
2020-08-10 17:16     ` Cédric Le Goater
2020-08-10 23:20       ` Joel Stanley
2020-08-11  7:05         ` Cédric Le Goater
2020-08-06 13:20 ` [PATCH for-5.2 09/19] ftgmac100: Fix registers that can be read Cédric Le Goater
2020-08-06 13:33   ` Philippe Mathieu-Daudé
2020-08-06 23:44   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 10/19] ftgmac100: Fix interrupt status "Packet transmitted on ethernet" Cédric Le Goater
2020-08-06 23:47   ` Joel Stanley
2020-08-07  6:06     ` Cédric Le Goater
2020-08-06 13:20 ` [PATCH for-5.2 11/19] ftgmac100: Fix interrupt status "Packet moved to RX FIFO" Cédric Le Goater
2020-08-06 23:48   ` Joel Stanley
2020-08-06 13:20 ` [PATCH for-5.2 12/19] ftgmac100: Change interrupt status when a DMA error occurs Cédric Le Goater
2020-08-06 23:51   ` Joel Stanley
2020-08-07  6:19     ` Cédric Le Goater
2020-08-06 13:21 ` [PATCH for-5.2 13/19] ftgmac100: Check for invalid len and address before doing a DMA transfer Cédric Le Goater
2020-08-06 23:51   ` Joel Stanley
2020-08-06 13:21 ` [PATCH for-5.2 14/19] ftgmac100: Fix integer overflow in ftgmac100_do_tx() Cédric Le Goater
2020-08-06 23:57   ` Joel Stanley
2020-08-10 13:43   ` Mauro Matteo Cascella
2020-08-10 17:14     ` Cédric Le Goater
2020-08-11 12:20       ` Mauro Matteo Cascella
2020-08-11 12:39   ` Peter Maydell
2020-08-18 14:54     ` Cédric Le Goater [this message]
2020-08-06 13:21 ` [PATCH for-5.2 15/19] ftgmac100: Improve software reset Cédric Le Goater
2020-08-06 13:40   ` Philippe Mathieu-Daudé
2020-08-07  0:03   ` Joel Stanley
2020-08-07  6:21     ` Cédric Le Goater
2020-08-06 13:21 ` [PATCH for-5.2 16/19] aspeed/sdmc: Perform memory training Cédric Le Goater
2020-08-06 13:38   ` Philippe Mathieu-Daudé
2020-08-07  0:10     ` Joel Stanley
2020-08-06 13:21 ` [PATCH for-5.2 17/19] aspeed/sdmc: Allow writes to unprotected registers Cédric Le Goater
2020-08-06 13:21 ` [PATCH for-5.2 18/19] aspeed/sdmc: Simplify calculation of RAM bits Cédric Le Goater
2020-08-07  0:11   ` Joel Stanley
2020-08-06 13:21 ` [PATCH for-5.2 19/19] aspeed/smc: Open AHB window of the second chip of the AST2600 FMC controller Cédric Le Goater
2020-08-07  0:12   ` Joel Stanley
2020-08-06 13:24 ` [PATCH for-5.2 00/19] aspeed: mostly cleanups and some extensions Cédric Le Goater
2020-08-07  9:14   ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a6f7515-9a5f-3160-6187-675032ce8c75@kaod.org \
    --to=clg@kaod.org \
    --cc=andrew@aj.id.au \
    --cc=ezrakiez@gmail.com \
    --cc=joel@jms.id.au \
    --cc=konrad.frederic@yahoo.fr \
    --cc=mcascell@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.