@@ -889,6 +889,27 @@ int hw_atl_b0_hw_ring_tx_head_update(struct aq_hw_s *self,
err = -ENXIO;
goto err_exit;
}
+
+ /* Validate that the new hw_head_ is reasonable. */
+ if (hw_head_ >= ring->size) {
+ err = -ENXIO;
+ goto err_exit;
+ }
+
+ if (ring->sw_head >= ring->sw_tail) {
+ /* Head index hasn't wrapped around to below tail index. */
+ if (hw_head_ < ring->sw_head && hw_head_ >= ring->sw_tail) {
+ err = -ENXIO;
+ goto err_exit;
+ }
+ } else {
+ /* Head index has wrapped around and is below tail index. */
+ if (hw_head_ < ring->sw_head || hw_head_ >= ring->sw_tail) {
+ err = -ENXIO;
+ goto err_exit;
+ }
+ }
+
ring->hw_head = hw_head_;
err = aq_hw_err_from_flags(self);
Bounds check hw_head index to verify it lies within the TX buffer ring. Unexpected values of hw_head may cause aq_ring_tx_clean to double dev_kfree_skb_any already cleaned parts of the ring. Reported-by: Aashay Shringarpure <aashay@google.com> Reported-by: Yi Chou <yich@google.com> Reported-by: Shervin Oloumi <enlightened@google.com> Signed-off-by: Grant Grundler <grundler@chromium.org> --- .../aquantia/atlantic/hw_atl/hw_atl_b0.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)