Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp148449pxf; Wed, 10 Mar 2021 02:53:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxu1bvGC7SW9CsUQjOD6Xq4u01ymmCHZz/Tz5yTXN0gHQjbzIpUGzYWie74g7uiHFV03e+V X-Received: by 2002:aa7:d588:: with SMTP id r8mr2533854edq.88.1615373582995; Wed, 10 Mar 2021 02:53:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615373582; cv=none; d=google.com; s=arc-20160816; b=gBvJsSR7duvVfkLJkyv381HlN0tefui822+AGT3jwjnx9a1g0e2L9em4r8EArBepoH t3bTMJ/cPFFiDWdVdZ/kq3s8FC/DIPd8aDKM8Euklrdv5PviTKA1UY7p7HpDli2KWCod SHOxl0W0oZQHD7kgo2H79jofotCMMvKQy+ncvpUuytiggGZvSJsV9CVqLwgLQeLPTz+h XBit6TBuZPdRYmXD37ftJB+OROAuExgvB8atRBwYuM/TLmyWPp99g+COxKovVA/62IzH cPtYrE4tj0AzIngB7MZ3aKytNv5PNUP5BirV5Nv6MDa/uDAOTcovu6BZeAfW0ewARKcS LUBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=VlQxHT9m2YrWTH+j0Yq/I7hn8Ar2/FbVPAn6L7N9n6E=; b=S1WfF3wCt37I0F/JR7UKGoxdRkCHIyyNPFe8s0zxq0m0AfaaiKtFKqQ3MdC3kO3w08 JDoZC+5zZ7WFMxMzkXm1EtA6yyIsQ/0BbJ02q3Bs5Y7VYqA3Q/2+Xt2Nv5Mqvhcd7RJ8 Fv35Jp/GbbAxZRJ8pYNAIQujm0MDVVAkGasyhE2e8t1M5+/FelJ3Vb4oOoJlLKMIMe6w U5hsx8YDzkfuoU/vPNiIsn60V5hh+ixIO70WRZdddXa9D/wLobbYezSQXOHWBIvWSOWP 6GWKXfdUktBnjK9mRAV5HunPBXEmOIIX1P7zMncMa4JaMG7BGRDRKx84FzJy8s8jf+f4 LsLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si12062249edv.312.2021.03.10.02.52.40; Wed, 10 Mar 2021 02:53:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbhCJKv2 (ORCPT + 99 others); Wed, 10 Mar 2021 05:51:28 -0500 Received: from mail.zju.edu.cn ([61.164.42.155]:36260 "EHLO zju.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229706AbhCJKvR (ORCPT ); Wed, 10 Mar 2021 05:51:17 -0500 Received: from localhost.localdomain (unknown [10.192.85.18]) by mail-app2 (Coremail) with SMTP id by_KCgB3XomDpEhgYxkiAg--.43318S4; Wed, 10 Mar 2021 18:50:48 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn, kjlu@umn.edu Cc: Hannes Reinecke , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: aic7xxx: aic79xx: Add missing check in ahc_handle_seqint Date: Wed, 10 Mar 2021 18:50:42 +0800 Message-Id: <20210310105042.31660-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgB3XomDpEhgYxkiAg--.43318S4 X-Coremail-Antispam: 1UD129KBjvJXoWxWrWrCFW3GrykGr43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-kernel@vger.kernel.org ahc_lookup_scb() may return a null pointer and further lead to null-pointer-dereference in case DATA_OVERRUN. Fix this by adding a null check. Signed-off-by: Dinghao Liu --- drivers/scsi/aic7xxx/aic7xxx_core.c | 72 +++++++++++++++-------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c index 4b04ab8908f8..3a1cd6a0334e 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_core.c +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c @@ -1382,43 +1382,45 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) u_int i; scb = ahc_lookup_scb(ahc, scbindex); - for (i = 0; i < num_phases; i++) { - if (lastphase == ahc_phase_table[i].phase) - break; - } - ahc_print_path(ahc, scb); - printk("data overrun detected %s." - " Tag == 0x%x.\n", - ahc_phase_table[i].phasemsg, - scb->hscb->tag); - ahc_print_path(ahc, scb); - printk("%s seen Data Phase. Length = %ld. NumSGs = %d.\n", - ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't", - ahc_get_transfer_length(scb), scb->sg_count); - if (scb->sg_count > 0) { - for (i = 0; i < scb->sg_count; i++) { - - printk("sg[%d] - Addr 0x%x%x : Length %d\n", - i, - (ahc_le32toh(scb->sg_list[i].len) >> 24 - & SG_HIGH_ADDR_BITS), - ahc_le32toh(scb->sg_list[i].addr), - ahc_le32toh(scb->sg_list[i].len) - & AHC_SG_LEN_MASK); + if (scb != NULL) { + for (i = 0; i < num_phases; i++) { + if (lastphase == ahc_phase_table[i].phase) + break; } + ahc_print_path(ahc, scb); + printk("data overrun detected %s." + " Tag == 0x%x.\n", + ahc_phase_table[i].phasemsg, + scb->hscb->tag); + ahc_print_path(ahc, scb); + printk("%s seen Data Phase. Length = %ld. NumSGs = %d.\n", + ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't", + ahc_get_transfer_length(scb), scb->sg_count); + if (scb->sg_count > 0) { + for (i = 0; i < scb->sg_count; i++) { + + printk("sg[%d] - Addr 0x%x%x : Length %d\n", + i, + (ahc_le32toh(scb->sg_list[i].len) >> 24 + & SG_HIGH_ADDR_BITS), + ahc_le32toh(scb->sg_list[i].addr), + ahc_le32toh(scb->sg_list[i].len) + & AHC_SG_LEN_MASK); + } + } + /* + * Set this and it will take effect when the + * target does a command complete. + */ + ahc_freeze_devq(ahc, scb); + if ((scb->flags & SCB_SENSE) == 0) { + ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR); + } else { + scb->flags &= ~SCB_SENSE; + ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL); + } + ahc_freeze_scb(scb); } - /* - * Set this and it will take effect when the - * target does a command complete. - */ - ahc_freeze_devq(ahc, scb); - if ((scb->flags & SCB_SENSE) == 0) { - ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR); - } else { - scb->flags &= ~SCB_SENSE; - ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL); - } - ahc_freeze_scb(scb); if ((ahc->features & AHC_ULTRA2) != 0) { /* -- 2.17.1