From: Jason Wang <jasowang@redhat.com>
To: P J P <ppandit@redhat.com>, Sven Schnelle <svens@stackframe.org>
Cc: Li Qiang <pangpei.lq@antfin.com>,
Qemu Developers <qemu-devel@nongnu.org>,
Ziming Zhang <ezrakiez@gmail.com>,
Prasad J Pandit <pjp@fedoraproject.org>
Subject: Re: [PATCH v2] net: tulip: check frame size and r/w data length
Date: Mon, 24 Feb 2020 13:58:08 +0800 [thread overview]
Message-ID: <e63fe1bb-e77f-1813-6cc7-9763c82c1046@redhat.com> (raw)
In-Reply-To: <20200217113804.341836-1-ppandit@redhat.com>
On 2020/2/17 下午7:38, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> Tulip network driver while copying tx/rx buffers does not check
> frame size against r/w data length. This may lead to OOB buffer
> access. Add check to avoid it.
>
> Reported-by: Li Qiang <pangpei.lq@antfin.com>
> Reported-by: Ziming Zhang <ezrakiez@gmail.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> hw/net/tulip.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> Update v2: retain earlier len[12] & s->rx_frame_len checks
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg04160.html
>
> diff --git a/hw/net/tulip.c b/hw/net/tulip.c
> index cfac2719d3..ea4fd371e3 100644
> --- a/hw/net/tulip.c
> +++ b/hw/net/tulip.c
> @@ -170,6 +170,10 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)
> } else {
> len = s->rx_frame_len;
> }
> +
> + if (s->rx_frame_len + len >= sizeof(s->rx_frame)) {
> + return;
> + }
What's the goal of this checking?
> pci_dma_write(&s->dev, desc->buf_addr1, s->rx_frame +
> (s->rx_frame_size - s->rx_frame_len), len);
> s->rx_frame_len -= len;
> @@ -181,6 +185,10 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)
> } else {
> len = s->rx_frame_len;
> }
> +
> + if (s->rx_frame_len + len >= sizeof(s->rx_frame)) {
> + return;
> + }
> pci_dma_write(&s->dev, desc->buf_addr2, s->rx_frame +
> (s->rx_frame_size - s->rx_frame_len), len);
> s->rx_frame_len -= len;
> @@ -227,7 +235,8 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size)
>
> trace_tulip_receive(buf, size);
>
> - if (size < 14 || size > 2048 || s->rx_frame_len || tulip_rx_stopped(s)) {
> + if (size < 14 || size > sizeof(s->rx_frame) - 4
> + || s->rx_frame_len || tulip_rx_stopped(s)) {
> return 0;
It's better to move those checks in .can_receive().
> }
>
> @@ -558,7 +567,7 @@ static void tulip_tx(TULIPState *s, struct tulip_descriptor *desc)
> if ((s->csr[6] >> CSR6_OM_SHIFT) & CSR6_OM_MASK) {
> /* Internal or external Loopback */
> tulip_receive(s, s->tx_frame, s->tx_frame_len);
> - } else {
> + } else if (s->tx_frame_len < sizeof(s->tx_frame)) {
Should we use <= here?
> qemu_send_packet(qemu_get_queue(s->nic),
> s->tx_frame, s->tx_frame_len);
> }
> @@ -575,12 +584,18 @@ static void tulip_copy_tx_buffers(TULIPState *s, struct tulip_descriptor *desc)
> int len1 = (desc->control >> TDES1_BUF1_SIZE_SHIFT) & TDES1_BUF1_SIZE_MASK;
> int len2 = (desc->control >> TDES1_BUF2_SIZE_SHIFT) & TDES1_BUF2_SIZE_MASK;
>
> + if (s->tx_frame_len + len1 >= sizeof(s->tx_frame)) {
> + return;
> + }
I think it's better to add a return value here to make sure caller
tulip_xmit_list_update() can exit the loop early
> if (len1) {
> pci_dma_read(&s->dev, desc->buf_addr1,
> s->tx_frame + s->tx_frame_len, len1);
> s->tx_frame_len += len1;
> }
>
> + if (s->tx_frame_len + len2 >= sizeof(s->tx_frame)) {
> + return;
> + }
> if (len2) {
> pci_dma_read(&s->dev, desc->buf_addr2,
> s->tx_frame + s->tx_frame_len, len2);
One more thing.
It looks to me there could be a user trigger-able infinite loop in
tun_list_update() through always set TDES0_OWN in its descriptors?
Thanks
next prev parent reply other threads:[~2020-02-24 5:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 11:38 [PATCH v2] net: tulip: check frame size and r/w data length P J P
2020-02-24 5:58 ` Jason Wang [this message]
2020-03-03 10:57 ` P J P
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=e63fe1bb-e77f-1813-6cc7-9763c82c1046@redhat.com \
--to=jasowang@redhat.com \
--cc=ezrakiez@gmail.com \
--cc=pangpei.lq@antfin.com \
--cc=pjp@fedoraproject.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=svens@stackframe.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).