Re: [RFC 1/1] swiotlb: Replace BUG_ON() with graceful error handling
From: Brian Johannesmeyer
Date: Fri Nov 22 2024 - 15:34:42 EST
On Fri, Nov 22, 2024 at 12:13 PM Brian Johannesmeyer
<bjohannesmeyer@xxxxxxxxx> wrote:
>
> Replace the BUG_ON() assertion in swiotlb_release_slots() with a
> conditional check and return. This change prevents a corrupted tlb_addr
> from causing a kernel panic.
>
> Co-developed-by: Raphael Isemann <teemperor@xxxxxxxxx>
> Signed-off-by: Raphael Isemann <teemperor@xxxxxxxxx>
> Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@xxxxxxxxx>
> ---
> kernel/dma/swiotlb.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index aa0a4a220719..54b4f9665772 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -834,7 +834,11 @@ static void swiotlb_release_slots(struct device *dev, phys_addr_t tlb_addr)
> * While returning the entries to the free list, we merge the entries
> * with slots below and above the pool being returned.
> */
> - BUG_ON(aindex >= mem->nareas);
> + if (unlikely(aindex >= mem->nareas)) {
> + dev_err(dev, "%s: invalid area index (%d >= %d)\n", __func__,
> + aindex, mem->nareas);
> + return;
> + }
>
> spin_lock_irqsave(&area->lock, flags);
> if (index + nslots < ALIGN(index + 1, IO_TLB_SEGSIZE))
> --
> 2.34.1
>
Whoops -- didn't send to the hardening mailing list. Adding it now.
-Brian