diff mbox series

[05/13] qla2xxx: Fix crash during module load unload test

Message ID 20220308082048.9774-6-njavali@marvell.com (mailing list archive)
State Superseded
Headers show
Series qla2xxx driver fixes | expand

Commit Message

Nilesh Javali March 8, 2022, 8:20 a.m. UTC
From: Arun Easi <aeasi@marvell.com>

During purex packet handling driver was incorrectly
freeing a pre-allocated structure. Fix this by
skipping that entry.

System crashed with the following stack during a
module unload test.

Call Trace:
          sbitmap_init_node+0x7f/0x1e0
          sbitmap_queue_init_node+0x24/0x150
          blk_mq_init_bitmaps+0x3d/0xa0
          blk_mq_init_tags+0x68/0x90
          blk_mq_alloc_map_and_rqs+0x44/0x120
          blk_mq_alloc_set_map_and_rqs+0x63/0x150
          blk_mq_alloc_tag_set+0x11b/0x230
          scsi_add_host_with_dma.cold+0x3f/0x245
          qla2x00_probe_one+0xd5a/0x1b80 [qla2xxx]

Call Trace with slub_debug and debug kernel:
        kasan_report_invalid_free+0x50/0x80
        __kasan_slab_free+0x137/0x150
        slab_free_freelist_hook+0xc6/0x190
        kfree+0xe8/0x2e0
        qla2x00_free_device+0x3bb/0x5d0 [qla2xxx]
        qla2x00_remove_one+0x668/0xcf0 [qla2xxx]

Reported-by: Marco Patalano <mpatalan@redhat.com>
Tested-by: Marco Patalano <mpatalan@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 62e9dd177732 ("scsi: qla2xxx: Change in PUREX to handle FPIN ELS requests")
Signed-off-by: Arun Easi <aeasi@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
---
 drivers/scsi/qla2xxx/qla_os.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Himanshu Madhani March 9, 2022, 6:42 p.m. UTC | #1
> On Mar 8, 2022, at 12:20 AM, Nilesh Javali <njavali@marvell.com> wrote:
> 
> From: Arun Easi <aeasi@marvell.com>
> 
> During purex packet handling driver was incorrectly
> freeing a pre-allocated structure. Fix this by
> skipping that entry.
> 
> System crashed with the following stack during a
> module unload test.
> 
> Call Trace:
>          sbitmap_init_node+0x7f/0x1e0
>          sbitmap_queue_init_node+0x24/0x150
>          blk_mq_init_bitmaps+0x3d/0xa0
>          blk_mq_init_tags+0x68/0x90
>          blk_mq_alloc_map_and_rqs+0x44/0x120
>          blk_mq_alloc_set_map_and_rqs+0x63/0x150
>          blk_mq_alloc_tag_set+0x11b/0x230
>          scsi_add_host_with_dma.cold+0x3f/0x245
>          qla2x00_probe_one+0xd5a/0x1b80 [qla2xxx]
> 
> Call Trace with slub_debug and debug kernel:
>        kasan_report_invalid_free+0x50/0x80
>        __kasan_slab_free+0x137/0x150
>        slab_free_freelist_hook+0xc6/0x190
>        kfree+0xe8/0x2e0
>        qla2x00_free_device+0x3bb/0x5d0 [qla2xxx]
>        qla2x00_remove_one+0x668/0xcf0 [qla2xxx]
> 
> Reported-by: Marco Patalano <mpatalan@redhat.com>
> Tested-by: Marco Patalano <mpatalan@redhat.com>
> Cc: stable@vger.kernel.org
> Fixes: 62e9dd177732 ("scsi: qla2xxx: Change in PUREX to handle FPIN ELS requests")
> Signed-off-by: Arun Easi <aeasi@marvell.com>
> Signed-off-by: Nilesh Javali <njavali@marvell.com>
> ---
> drivers/scsi/qla2xxx/qla_os.c | 2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
> index a4546346c18b..d572a76d0fa0 100644
> --- a/drivers/scsi/qla2xxx/qla_os.c
> +++ b/drivers/scsi/qla2xxx/qla_os.c
> @@ -3904,6 +3904,8 @@ qla24xx_free_purex_list(struct purex_list *list)
> 	spin_lock_irqsave(&list->lock, flags);
> 	list_for_each_entry_safe(item, next, &list->head, list) {
> 		list_del(&item->list);
> +		if (item == &item->vha->default_item)
> +			continue;
> 		kfree(item);
> 	}
> 	spin_unlock_irqrestore(&list->lock, flags);
> -- 
> 2.19.0.rc0
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>

--
Himanshu Madhani	 Oracle Linux Engineering
diff mbox series

Patch

diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index a4546346c18b..d572a76d0fa0 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -3904,6 +3904,8 @@  qla24xx_free_purex_list(struct purex_list *list)
 	spin_lock_irqsave(&list->lock, flags);
 	list_for_each_entry_safe(item, next, &list->head, list) {
 		list_del(&item->list);
+		if (item == &item->vha->default_item)
+			continue;
 		kfree(item);
 	}
 	spin_unlock_irqrestore(&list->lock, flags);