diff options
| author | xoviat <[email protected]> | 2023-11-07 21:42:55 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-07 21:42:55 +0000 |
| commit | 3bccb672316415d54baf306a1084003b8796e94a (patch) | |
| tree | b4d83742bc0c8b048d3e4599d48f4d7c27baa1ba | |
| parent | b44a5fcaf6cbd7bb91f575dffbe5a4ea16723172 (diff) | |
| parent | 553f0158c0a8abaa293ada3b3f214194418a767e (diff) | |
Merge pull request #2155 from xoviat/eth
stm32: resolve eth/v2 security bug
| -rw-r--r-- | embassy-stm32/src/eth/v2/descriptors.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs index e9799adf1..01ea8e574 100644 --- a/embassy-stm32/src/eth/v2/descriptors.rs +++ b/embassy-stm32/src/eth/v2/descriptors.rs | |||
| @@ -119,13 +119,11 @@ impl<'a> TDesRing<'a> { | |||
| 119 | // "Preceding reads and writes cannot be moved past subsequent writes." | 119 | // "Preceding reads and writes cannot be moved past subsequent writes." |
| 120 | fence(Ordering::Release); | 120 | fence(Ordering::Release); |
| 121 | 121 | ||
| 122 | self.index = self.index + 1; | ||
| 123 | if self.index == self.descriptors.len() { | ||
| 124 | self.index = 0; | ||
| 125 | } | ||
| 126 | |||
| 127 | // signal DMA it can try again. | 122 | // signal DMA it can try again. |
| 128 | ETH.ethernet_dma().dmactx_dtpr().write(|w| w.0 = 0) | 123 | // See issue #2129 |
| 124 | ETH.ethernet_dma().dmactx_dtpr().write(|w| w.0 = &td as *const _ as u32); | ||
| 125 | |||
| 126 | self.index = (self.index + 1) % self.descriptors.len(); | ||
| 129 | } | 127 | } |
| 130 | } | 128 | } |
| 131 | 129 | ||
| @@ -237,21 +235,19 @@ impl<'a> RDesRing<'a> { | |||
| 237 | 235 | ||
| 238 | /// Pop the packet previously returned by `available`. | 236 | /// Pop the packet previously returned by `available`. |
| 239 | pub(crate) fn pop_packet(&mut self) { | 237 | pub(crate) fn pop_packet(&mut self) { |
| 240 | let descriptor = &mut self.descriptors[self.index]; | 238 | let rd = &mut self.descriptors[self.index]; |
| 241 | assert!(descriptor.available()); | 239 | assert!(rd.available()); |
| 242 | 240 | ||
| 243 | self.descriptors[self.index].set_ready(self.buffers[self.index].0.as_mut_ptr()); | 241 | rd.set_ready(self.buffers[self.index].0.as_mut_ptr()); |
| 244 | 242 | ||
| 245 | // "Preceding reads and writes cannot be moved past subsequent writes." | 243 | // "Preceding reads and writes cannot be moved past subsequent writes." |
| 246 | fence(Ordering::Release); | 244 | fence(Ordering::Release); |
| 247 | 245 | ||
| 248 | // signal DMA it can try again. | 246 | // signal DMA it can try again. |
| 249 | ETH.ethernet_dma().dmacrx_dtpr().write(|w| w.0 = 0); | 247 | // See issue #2129 |
| 248 | ETH.ethernet_dma().dmacrx_dtpr().write(|w| w.0 = &rd as *const _ as u32); | ||
| 250 | 249 | ||
| 251 | // Increment index. | 250 | // Increment index. |
| 252 | self.index += 1; | 251 | self.index = (self.index + 1) % self.descriptors.len(); |
| 253 | if self.index == self.descriptors.len() { | ||
| 254 | self.index = 0 | ||
| 255 | } | ||
| 256 | } | 252 | } |
| 257 | } | 253 | } |
