scsi: aic79xx: Fix NULL pointer dereference in device reset
Subsystems (2)
PATCH v3 1/1 scsi: aic79xx: Fix NULL pointer dereference in device reset
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.
---
Notes:
v3:
- Complete an SCB that ahd_perform_autosense() declines with ahd_done().
v2 left it on the pending list until a bus reset, which does not come
with SG_SCSI_RESET_NO_ESCALATE (Sashiko AI review of v2). Such a reset
now returns SUCCESS, as one answered with any other status does; in v2
it timed out and returned FAILED. This is the only code change, so I
kept Hannes's Reviewed-by.
- Much shorter commit message (Hannes). Sorry for the overlong
descriptions in v1 and v2.
v2: https://patchwork.kernel.org/project/linux-scsi/patch/[email protected]/
- Put the NULL checks into the ahd_cmd_*() helpers where one exists, and
keep the now safe ahd_set_residual() call in ahd_linux_dev_reset()
(Hannes).
- Skip autosense for an SCB without a command (Sashiko AI review of v1).
v1: https://patchwork.kernel.org/project/linux-scsi/patch/[email protected]/
Tested on an AIC-7902 (SE7501WV2S, i686, v7.2.11, not packetized) with the v2 code: device resets idle and under I/O, a device reset of the failing disk, and a bus reset. The new ahd_done() call is reached only by a reset answered with CHECK CONDITION, which these disks do not do. Build-tested with W=1 for x86_64 and i386, no new warnings.
Prepared with LLM assistance (Claude Opus 5.5; v3 also reviewed by Grok); I reviewed it and ran the tests.
drivers/scsi/aic7xxx/aic79xx_core.c | 4 +++- drivers/scsi/aic7xxx/aic79xx_osm.h | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +3 -1
@@ -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),
drivers/scsi/aic7xxx/aic79xx_osm.h +21 -5
@@ -501,6 +501,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 ; }
@@ -514,6 +516,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; }
@@ -527,6 +531,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 ); }
@@ -539,6 +545,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 ); }
@@ -566,13 +574,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
@@ -584,6 +595,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); }
@@ -597,11 +610,12 @@ static inlineint 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
@@ -631,6 +645,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++;
base-commit: db8b4d2bf2d3e02b4ff78bbf69d00e11795840de
Signature · 1 line
2.47.3
Andrew,
Quoted 6 lines
Since commit
c67e63800446("scsi: aic79xx: Do not reference SCSI command when resetting device") the device reset SCB has no SCSI command, butahd_linux_dev_reset()still sets its residual, andahd_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:
Applied to 7.4/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen
Quoted 10 lines · Andrew Luebke
Since commit
c67e63800446("scsi: aic79xx: Do not reference SCSI command when resetting device") the device reset SCB has no SCSI command, butahd_linux_dev_reset()still sets its residual, andahd_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[...]
Applied to 7.4/scsi-queue, thanks!
[1/1] scsi: aic79xx: Fix NULL pointer dereference in device reset
https://git.kernel.org/mkp/scsi/c/f057a8bfeb6f
Signature · 1 line
Martin K. Petersen