Skip to contentSkip to conversation

net/e1000e_core: adjust count if RDH exceeds RDT in e1000e_ring_advance()

PATCH In review Mauro Matteo Cascella 2 participants 10 messages Nov 13, 2020 – Dec 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/e1000e_core: adjust count if RDH exceeds RDT in e1000e_ring_advance()

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

This issue was independently reported by Gaoning Pan (Zhejiang University) and Cheolwoo Myung.

---
Changes since previous version:
Take the initial values of RDH/RDT into account. Address the case where RDH is less than RDT and (RDH + count) would exceed RDT.

Patch v1:
https://lists.nongnu.org/archive/html/qemu-devel/2020-11/msg01492.html

References:
https://git.qemu.org/?p=qemu.git;a=commit;h=dd793a74882477ca38d49e191110c17dfe
https://git.qemu.org/?p=qemu.git;a=commit;h=4154c7e03fa55b4cf52509a83d50d6c09d743b7
http://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf

 hw/net/e1000e_core.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/net/e1000e_core.c +5 -0
index bcfd46696f..324cc14ffb 100644
@@ -829,6 +829,11 @@ e1000e_ring_head_descr(E1000ECore *core, const E1000E_RingInfo *r)
 static inline void
 e1000e_ring_advance(E1000ECore *core, const E1000E_RingInfo *r, uint32_t count)
 {
+    if (count > 1 && core->mac[r->dh] < core->mac[r->dt] &&
+        core->mac[r->dh] + count > core->mac[r->dt]) {
+        count = core->mac[r->dt] - core->mac[r->dh];
+    }
+
     core->mac[r->dh] += count;
 
     if (core->mac[r->dh] * E1000_RING_DESC_LEN >= core->mac[r->dlen]) {
Signature · 1 line
2.28.0
#1 lore raw
Quoted 10 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

Quoted 8 lines

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

#2 lore raw
Quoted 23 lines · Jason Wang
Quoted 10 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

Quoted 8 lines

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

Thank you,

Signature · 3 lines
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
#3 lore raw
Quoted 22 lines · Mauro Matteo Cascella
Quoted 21 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

        base = e1000e_ring_head_descr(core, rxi);

        pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Quoted 2 lines

Thank you,

#4 lore raw
Quoted 39 lines · Jason Wang
Quoted 22 lines · Mauro Matteo Cascella
Quoted 21 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

Quoted 5 lines
         base = e1000e_ring_head_descr(core, rxi);

         pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 2 lines

Thanks

Quoted 51 lines · Jason Wang
Quoted 22 lines · Mauro Matteo Cascella
Quoted 21 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

         base = e1000e_ring_head_descr(core, rxi);

         pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Quoted 2 lines

Thank you,

Signature · 3 lines
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
#5 lore raw
Quoted 40 lines · Mauro Matteo Cascella
Quoted 39 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

          base = e1000e_ring_head_descr(core, rxi);

          pci_dma_read(d, base, &desc, core->rx_desc_len);
Quoted 50 lines
Quoted 1 line

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 1 line

Thanks

Quoted 42 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

          base = e1000e_ring_head_descr(core, rxi);

          pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Sorry, I meant RDH actually, when packet split descriptor is used, it doesn't check whether DH exceeds DLEN?

Thanks

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

Thank you,

#6 lore raw
Quoted 90 lines · Jason Wang
Quoted 87 lines · Mauro Matteo Cascella
Quoted 35 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

Quoted 5 lines
          base = e1000e_ring_head_descr(core, rxi);

          pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 1 line

Thanks

Quoted 39 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

          base = e1000e_ring_head_descr(core, rxi);

          pci_dma_read(d, base, &desc, core->rx_desc_len);
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Sorry, I meant RDH actually, when packet split descriptor is used, it doesn't check whether DH exceeds DLEN?

When the packet split feature is used (i.e., count > 1) this patch basically sets RDH=RDT in case the increment would exceed RDT. The next iteration should detect that RDH equals RDT in e1000e_ring_empty(), and exit the loop right before pci_dma_read(). On the other hand RDH is set to zero if it exceeds DLEN in e1000e_ring_advance() so we should be fine in either case, unless I'm missing something?

Thank you for your time,
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0

#7 lore raw
Quoted 87 lines · Mauro Matteo Cascella
Quoted 86 lines · Jason Wang
Quoted 84 lines · Mauro Matteo Cascella
Quoted 33 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

Quoted 5 lines
           base = e1000e_ring_head_descr(core, rxi);

           pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 1 line

Thanks

Quoted 39 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

           base = e1000e_ring_head_descr(core, rxi);

           pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

Thanks

Sorry, I meant RDH actually, when packet split descriptor is used, it doesn't check whether DH exceeds DLEN?

When the packet split feature is used (i.e., count > 1) this patch basically sets RDH=RDT in case the increment would exceed RDT.

Can software set RDH to an odd value? If not, I think we are probably fine.

Thanks

Quoted 14 lines

The
next iteration should detect that RDH equals RDT in e1000e_ring_empty(), and exit the loop right before pci_dma_read(). On the other hand RDH is set to zero if it exceeds DLEN in e1000e_ring_advance() so we should be fine in either case, unless I'm missing something?

Thank you for your time,
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0

#8 lore raw
Quoted 95 lines · Jason Wang
Quoted 92 lines · Mauro Matteo Cascella
Quoted 91 lines · Jason Wang
Quoted 38 lines · Mauro Matteo Cascella
Quoted 37 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

           base = e1000e_ring_head_descr(core, rxi);

           pci_dma_read(d, base, &desc, core->rx_desc_len);
Quoted 47 lines
Quoted 1 line

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 1 line

Thanks

Quoted 40 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

           base = e1000e_ring_head_descr(core, rxi);

           pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Sorry, I meant RDH actually, when packet split descriptor is used, it doesn't check whether DH exceeds DLEN?

Quoted 8 lines
Quoted 2 lines

When the packet split feature is used (i.e., count > 1) this patch basically sets RDH=RDT in case the increment would exceed RDT.

Can software set RDH to an odd value? If not, I think we are probably fine.

Thanks

Honestly I don't know the answer to your question, my guess is that it may be possible for a malicious/bogus guest to set RDH the same way as RDT.

Thank you,
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0

#9 lore raw
Quoted 104 lines · Mauro Matteo Cascella
Quoted 92 lines · Jason Wang
Quoted 90 lines · Mauro Matteo Cascella
Quoted 89 lines · Jason Wang
Quoted 38 lines · Mauro Matteo Cascella
Quoted 37 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

            base = e1000e_ring_head_descr(core, rxi);

            pci_dma_read(d, base, &desc, core->rx_desc_len);
Quoted 47 lines
Quoted 1 line

Otherwise e1000e may try to read out of descriptor ring.

Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd?

Quoted 1 line

Thanks

Quoted 40 lines · Jason Wang
Quoted 20 lines · Mauro Matteo Cascella
Quoted 19 lines · Jason Wang
Quoted 18 lines · Mauro Matteo Cascella

The e1000e_write_packet_to_guest() function iterates over a set of receive descriptors by advancing rx descriptor head register (RDH) from its initial value to rx descriptor tail register (RDT). The check in e1000e_ring_empty() is responsible for detecting whether RDH has reached RDT, terminating the loop if that's the case. Additional checks have been added in the past to deal with bogus values submitted by the guest to prevent possible infinite loop. This is done by "wrapping around" RDH at some point and detecting whether it assumes the original value during the loop.

However, when e1000e is configured to use the packet split feature, RDH is incremented by two instead of one, as the packet split descriptors are 32 bytes while regular descriptors are 16 bytes. A malicious or buggy guest may set RDT to an odd value and transmit only null RX descriptors. This corner case would prevent RDH from ever matching RDT, leading to an infinite loop. This patch adds a check in e1000e_ring_advance() to make sure RDH does not exceed RDT in a single incremental step, adjusting the count value accordingly.

Quoted 8 lines
Quoted 6 lines

Can this patch solve this issue in another way?

https://patchew.org/QEMU/[email protected]/

Thanks

Yes, it does work nicely. Still, I think this patch is useful to avoid possible inconsistent state in e1000e_ring_advance() when count > 1.

So if RDT is odd, it looks to me the following codes in e1000e_write_packet_to_guest() needs to be fixed as well.

            base = e1000e_ring_head_descr(core, rxi);

            pci_dma_read(d, base, &desc, core->rx_desc_len);

Otherwise e1000e may try to read out of descriptor ring.

Thanks

Sorry, I meant RDH actually, when packet split descriptor is used, it doesn't check whether DH exceeds DLEN?

Quoted 7 lines
Quoted 2 lines

When the packet split feature is used (i.e., count > 1) this patch basically sets RDH=RDT in case the increment would exceed RDT.

Can software set RDH to an odd value? If not, I think we are probably fine.

Thanks

Honestly I don't know the answer to your question, my guess is that it may be possible for a malicious/bogus guest to set RDH the same way as RDT.

Quoted 7 lines

Thank you,
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0

Then I think we should fix that.

Thanks