The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: John Garry <john.garry@linux.dev>
To: Yang Zi <2959243019@qq.com>,
	aacraid@microsemi.com, James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, linux-scsi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: ips: Fix NULL pointer dereference in ips_release()
Date: Tue, 25 Aug 2026 11:44:54 +0100	[thread overview]
Message-ID: <1586c3fc-eeb2-4601-b8f3-3096a1c30671@linux.dev> (raw)
In-Reply-To: <tencent_F38F19C2D497EC19AF3331BC5030EFEF3307@qq.com>

On 8/25/26 10:25, Yang Zi wrote:
> When ips_insert_device() fails before calling pci_set_drvdata(), the
> PCI device's drvdata is NULL.  The .remove callback ips_remove_device()
> then calls ips_release(NULL), which immediately calls
> scsi_remove_host(NULL).  That dereferences shost->scan_mutex at a fixed
> offset of the NULL pointer, triggering a NULL pointer dereference.
> 
> KASAN report:
> 
>      BUG: KASAN: null-ptr-deref in __mutex_lock_common kernel/locking/mutex.c:625 [inline]
>      BUG: KASAN: null-ptr-deref in __mutex_lock+0x8b/0x1010 kernel/locking/mutex.c:820
>      Read of size 8 at addr 00000000000000d0 by task syz.0.671/5574
> 
>      __mutex_lock+0x8b/0x1010  kernel/locking/mutex.c:820
>      scsi_remove_host+0x24/0x300  drivers/scsi/hosts.c:169
>      ips_release  drivers/scsi/ips.c:654 [inline] [ips]
>      ips_remove_device+0x155/0x2840  drivers/scsi/ips.c:6701 [ips]

You have sent many fixes for similar crashes in other drivers today. How 
did you recreate this? You have this ips HW, right?

> 
> Make ips_release() handle a NULL Scsi_Host by returning early, so the
> remove path is safe when probe never established drvdata.

ips_release() is only called from ips_remove_device(), and this is in 
the driver removal path. This would not be called if the probe fails 
(and pci_set_drvdata() was not called). So there seems to be something 
wrong in ips_insert_device().

> 
> Signed-off-by: Yang Zi <2959243019@qq.com>
> ---
>   drivers/scsi/ips.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
> index 41ed73966a48..39568a7effb3 100644
> --- a/drivers/scsi/ips.c
> +++ b/drivers/scsi/ips.c
> @@ -649,6 +649,9 @@ static void ips_release(struct Scsi_Host *sh)
>       ips_ha_t *ha;
>       int i;
>   
> +    if (!sh)
> +        return;
> +
>       METHOD_TRACE("ips_release", 1);
>   
>       scsi_remove_host(sh);


      reply	other threads:[~2026-08-25 10:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:25 [PATCH] scsi: ips: Fix NULL pointer dereference in ips_release() Yang Zi
2026-08-25 10:44 ` John Garry [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1586c3fc-eeb2-4601-b8f3-3096a1c30671@linux.dev \
    --to=john.garry@linux.dev \
    --cc=2959243019@qq.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=aacraid@microsemi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox