From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794585406; b=MxJelbO5tq036hATbWODUzx3BIhwUc23EuMqWRen/DKTJAMiJz6srkjY+d6zckeMsitL pT6DptKfunMkCBFSyZ9ex+OHKSv5t12imlLfGogMzQHYNKII5j8I3ZQvGUbU402ykCsIm t+uVY7SKnJ6N0A0hdVoo2uL8Bt3huA1TSoM0P1VmRmR3eLT8ze+/YxLd5cj+zBqHdZ1xl Ix2yOuUd1sbK6BnMRS9XOsmGLGnwSP09W8NuBJVOYDKjpV8fSAe+QGG9Vwfhe3of6tDAD j+0WDdqK9pix4+qGK2kgylu0e1eDET/jPDJyJPqCaFNqWNmfFk7zBPLr7haCDyfxEmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794585406; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=caIJMSvulmfXQGVQM97ELyQR4K7glPnR+o8mlM/zuKg=; b=a1yhoKnGwbbNhdCuXlg7nxpPG/ik7y2+NiuF9s16y6cKGlZ+Q0k+rI4YznqtjhaoirkG oy8Sxpwj+3gnFDjrF0WD6bgQt26z1lUM0fLAdYvsp9my/r7Z4CEs8gg7tpMh5XHQT+/s6 xgVjbpgkR5d20Vc2hUeaKDWez+Y+B4q8N5f2/+FK7SoEgd2DJtzGHB9ZMu/FUTGGCDrA7 xlpsT184op4fuXm5Nhn9kxYMT/YT2S6h+0zuT1O1jMhRUlMioD6Px98DQaebH30zy3peD jqhDx9BJODDQvQ4FZuXkAKNhE8hLn7RMQ1CCdxrvFDQqbfMJaHelilYgQZt5DeB2XEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UEzLMksM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07CF76070FFD; Fri, 13 Nov 2026 15:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UEzLMksM Received: by smtp.kernel.org (Postfix) with ESMTPSA id A77331F000C7; Fri, 13 Nov 2026 15:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794585405; bh=caIJMSvulmfXQGVQM97ELyQR4K7glPnR+o8mlM/zuKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UEzLMksM8yIuyM/yXtKKQlb+pIg5HiJawJIoFX+Pi704qgSMzUs5W+esm4JMVRmUQ KofXn1faZxaHWGgXRZOChjqAJif/swG+eNLoba42ZTTHU/+VCbltRCBQAZsVRdykNI yGLo2/ucloT5oDhtnoCLqTWwGQs8n5BOkynfC1D8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hannes Reinecke , Andrew Luebke , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 7.3 074/507] scsi: aic79xx: Fix NULL pointer dereference in device reset Date: Fri, 13 Nov 2026 10:46:18 -0500 Message-ID: <20261113153756.103100121@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153753.358973689@linuxfoundation.org> References: <20261113153753.358973689@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrew Luebke [ Upstream commit f057a8bfeb6ff89c65e95540b8700a53c66d4a31 ] Since commit c67e63800446 ("scsi: aic79xx: Do not reference SCSI command when resetting device") the device reset SCB has no SCSI command, but ahd_linux_dev_reset() still sets its residual, and ahd_abort_scbs(), which completes it, sets its status. Seen on an AIC-7902 when a failing disk triggered a device reset, which killed the SCSI error handler: BUG: kernel NULL pointer dereference, address: 0000009c EIP: ahd_linux_dev_reset.cold+0xee/0x26e Add NULL command checks to the accessors in aic79xx_osm.h. Also skip autosense for an SCB without a command and complete it with ahd_done() right away: the REQUEST SENSE path can clear SCB_DEVICE_RESET, after which ahd_done() would dereference the missing command. Fixes: c67e63800446 ("scsi: aic79xx: Do not reference SCSI command when resetting device") Cc: stable@vger.kernel.org Reviewed-by: Hannes Reinecke Signed-off-by: Andrew Luebke Assisted-by: LLM Link: https://patch.msgid.link/20261026172032.749756-1-andrew.luebke@gmail.com Signed-off-by: Martin K. Petersen (Oracle) Signed-off-by: Sasha Levin --- drivers/scsi/aic7xxx/aic79xx_core.c | 4 +++- drivers/scsi/aic7xxx/aic79xx_osm.h | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c index 3602a1fc40e4e..4abc7948187f8 100644 --- a/drivers/scsi/aic7xxx/aic79xx_core.c +++ b/drivers/scsi/aic7xxx/aic79xx_core.c @@ -8942,8 +8942,10 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb) } #endif - if (ahd_perform_autosense(scb) == 0) + if (ahd_perform_autosense(scb) == 0) { + ahd_done(ahd, scb); break; + } ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb), SCB_GET_TARGET(ahd, scb), diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h index 793fe19993a90..3bcfcfe18f08b 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.h +++ b/drivers/scsi/aic7xxx/aic79xx_osm.h @@ -499,6 +499,8 @@ int ahd_linux_show_info(struct seq_file *,struct Scsi_Host *); static inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status) { + if (!cmd) + return; cmd->result &= ~(CAM_STATUS_MASK << 16); cmd->result |= status << 16; } @@ -512,6 +514,8 @@ void ahd_set_transaction_status(struct scb *scb, uint32_t status) static inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status) { + if (!cmd) + return; cmd->result &= ~0xFFFF; cmd->result |= status; } @@ -525,6 +529,8 @@ void ahd_set_scsi_status(struct scb *scb, uint32_t status) static inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd) { + if (!cmd) + return CAM_REQ_INPROG; return ((cmd->result >> 16) & CAM_STATUS_MASK); } @@ -537,6 +543,8 @@ uint32_t ahd_get_transaction_status(struct scb *scb) static inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd) { + if (!cmd) + return SAM_STAT_GOOD; return (cmd->result & 0xFFFF); } @@ -564,13 +572,16 @@ u_long ahd_get_transfer_length(struct scb *scb) static inline int ahd_get_transfer_dir(struct scb *scb) { + if (!scb->io_ctx) + return DMA_NONE; return (scb->io_ctx->sc_data_direction); } static inline void ahd_set_residual(struct scb *scb, u_long resid) { - scsi_set_resid(scb->io_ctx, resid); + if (scb->io_ctx) + scsi_set_resid(scb->io_ctx, resid); } static inline @@ -582,6 +593,8 @@ void ahd_set_sense_residual(struct scb *scb, u_long resid) static inline u_long ahd_get_residual(struct scb *scb) { + if (!scb->io_ctx) + return 0; return scsi_get_resid(scb->io_ctx); } @@ -595,11 +608,12 @@ static inline int ahd_perform_autosense(struct scb *scb) { /* - * We always perform autosense in Linux. - * On other platforms this is set on a - * per-transaction basis. + * We always perform autosense in Linux, except for the device + * reset SCB, which has no command to return sense data to. */ - return (1); + if (!scb->io_ctx) + return 0; + return 1; } static inline uint32_t @@ -629,6 +643,8 @@ void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb); static inline void ahd_freeze_scb(struct scb *scb) { + if (!scb->io_ctx) + return; if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) { scb->io_ctx->result |= CAM_DEV_QFRZN << 16; scb->platform_data->dev->qfrozen++; -- 2.53.0