2023-07-27 16:47:14

by Alexandra Diupina

[permalink] [raw]
Subject: [PATCH] 53c700: add 'slot' check to NULL

The 'slot' variable allows a NULL value.
It is necessary to add a check for a null
value to avoid dereferencing the null pointer.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Co-developed-by: Vladimir Telezhnikov <[email protected]>
Signed-off-by: Vladimir Telezhnikov <[email protected]>
Signed-off-by: Alexandra Diupina <[email protected]>
---
drivers/scsi/53c700.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index e1e4f9d10887..8e5468d1733d 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -1598,6 +1598,8 @@ NCR_700_intr(int irq, void *dev_id)
printk("scsi%d (%d:%d) PHASE MISMATCH IN SEND MESSAGE %d remain, return %p[%04x], phase %s\n", host->host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript, sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
#endif
resume_offset = hostdata->pScript + Ent_SendMessagePhaseMismatch;
+ } else if (!slot) {
+ printk(KERN_ERR "53c700: SCSI DONE HAS NULL SCp\n");
} else if(dsp >= to32bit(&slot->pSG[0].ins) &&
dsp <= to32bit(&slot->pSG[NCR_700_SG_SEGMENTS].ins)) {
int data_transfer = NCR_700_readl(host, DBC_REG) & 0xffffff;
--
2.30.2



2023-07-27 18:05:06

by James Bottomley

[permalink] [raw]
Subject: Re: [PATCH] 53c700: add 'slot' check to NULL

On Thu, 2023-07-27 at 18:39 +0300, Alexandra Diupina wrote:
> The 'slot' variable allows a NULL value.
> It is necessary to add a check for a null
> value to avoid dereferencing the null pointer.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Co-developed-by: Vladimir Telezhnikov <[email protected]>
> Signed-off-by: Vladimir Telezhnikov <[email protected]>
> Signed-off-by: Alexandra Diupina <[email protected]>
> ---
>  drivers/scsi/53c700.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
> index e1e4f9d10887..8e5468d1733d 100644
> --- a/drivers/scsi/53c700.c
> +++ b/drivers/scsi/53c700.c
> @@ -1598,6 +1598,8 @@ NCR_700_intr(int irq, void *dev_id)
>                                 printk("scsi%d (%d:%d) PHASE MISMATCH
> IN SEND MESSAGE %d remain, return %p[%04x], phase %s\n", host-
> >host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript,
> sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
>  #endif
>                                 resume_offset = hostdata->pScript +
> Ent_SendMessagePhaseMismatch;
> +                       } else if (!slot) {
> +                               printk(KERN_ERR "53c700: SCSI DONE
> HAS NULL SCp\n");
>                         } else if(dsp >= to32bit(&slot->pSG[0].ins)
> &&

I don't believe anyone has ever hit this, but if slot were null, it
would have to drop through to the else clause to get a bus reset to
kick the device. If we do what you propose above, the driver would
hang instead of crashing, which isn't a better outcome. Something like
this.

James

---

diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index e1e4f9d10887..5296a13404cf 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -1598,7 +1598,7 @@ NCR_700_intr(int irq, void *dev_id)
printk("scsi%d (%d:%d) PHASE MISMATCH IN SEND MESSAGE %d remain, return %p[%04x], phase %s\n", host->host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript, sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
#endif
resume_offset = hostdata->pScript + Ent_SendMessagePhaseMismatch;
- } else if(dsp >= to32bit(&slot->pSG[0].ins) &&
+ } else if(slot && dsp >= to32bit(&slot->pSG[0].ins) &&
dsp <= to32bit(&slot->pSG[NCR_700_SG_SEGMENTS].ins)) {
int data_transfer = NCR_700_readl(host, DBC_REG) & 0xffffff;
int SGcount = (dsp - to32bit(&slot->pSG[0].ins))/sizeof(struct NCR_700_SG_List);


2023-07-28 13:02:16

by Alexandra Diupina

[permalink] [raw]
Subject: [PATCH v2] 53c700: add 'slot' check to NULL

Add a 'slot' check for a null value to avoid
dereferencing the null pointer

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Co-developed-by: Vladimir Telezhnikov <[email protected]>
Signed-off-by: Vladimir Telezhnikov <[email protected]>
Signed-off-by: Alexandra Diupina <[email protected]>
---
v2: Move the 'slot' variable check to an existing if-else expression
as James E.J. Bottomley <[email protected]> suggested
drivers/scsi/53c700.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index e1e4f9d10887..857be0f3ae5b 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -1598,7 +1598,7 @@ NCR_700_intr(int irq, void *dev_id)
printk("scsi%d (%d:%d) PHASE MISMATCH IN SEND MESSAGE %d remain, return %p[%04x], phase %s\n", host->host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript, sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
#endif
resume_offset = hostdata->pScript + Ent_SendMessagePhaseMismatch;
- } else if(dsp >= to32bit(&slot->pSG[0].ins) &&
+ } else if (slot && dsp >= to32bit(&slot->pSG[0].ins) &&
dsp <= to32bit(&slot->pSG[NCR_700_SG_SEGMENTS].ins)) {
int data_transfer = NCR_700_readl(host, DBC_REG) & 0xffffff;
int SGcount = (dsp - to32bit(&slot->pSG[0].ins))/sizeof(struct NCR_700_SG_List);
--
2.30.2


2023-07-31 21:31:15

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] 53c700: add 'slot' check to NULL

On Fri, 28 Jul 2023 15:35:21 +0300, Alexandra Diupina wrote:

> Add a 'slot' check for a null value to avoid
> dereferencing the null pointer
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
>

Applied to 6.5/scsi-fixes, thanks!

[1/1] 53c700: add 'slot' check to NULL
https://git.kernel.org/mkp/scsi/c/8366d1f1249a

--
Martin K. Petersen Oracle Linux Engineering