mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Rondreis <linhaoguo86@gmail.com>,
	Tony Battersby <tonyb@cybernetics.com>,
	jejb@linux.ibm.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: KASAN: use-after-free Read in sg_release
Date: Wed, 28 Sep 2022 23:45:18 +0200	[thread overview]
Message-ID: <af3d2628-bf00-d897-d140-415985c29bfd@interlog.com> (raw)
In-Reply-To: <404508f8-37bb-a3bd-4319-6b6d7a7e076e@cybernetics.com>

On 2022-09-22 17:29, Tony Battersby wrote:
> On 9/20/22 10:46, Rondreis wrote:
>> Hello,
>>
>> When fuzzing the Linux kernel driver v6.0-rc6, the following crash was
>> triggered.
>>
>> HEAD commit: 521a547ced6477c54b4b0cc206000406c221b4d6
>> git tree: upstream
>>
>> kernel config: https://pastebin.com/raw/hekxU61F
>> console output: https://pastebin.com/raw/73a8RzBY
>>
>> Sorry for failing to extract the reproducer. But on other versions of
>> Linux, I also triggered this crash.
>>
>> I would appreciate it if you have any idea how to solve this bug.
>>
> sg_release() calls "kref_put(&sfp->f_ref, sg_remove_sfp)" which
> eventually does "kref_put(&sdp->d_ref, sg_device_destroy)" which does
> "kfree(sdp)", but sg_release() continues to access sdp afterward.  Try
> the following patch.
> 
>>From 82ca6785c40eded6229183a53752fc5e43db4a94 Mon Sep 17 00:00:00 2001
> From: Tony Battersby <tonyb@cybernetics.com>
> Date: Thu, 22 Sep 2022 11:05:30 -0400
> Subject: [PATCH] scsi: sg: fix memory-use-after-free on device removal
> 
> Fix memory-use-after-free race when closing a sg fd to a removed device.
> 
> Link: https://lore.kernel.org/linux-scsi/CAB7eexK_jr1LWOO9RWrBF9as7gAS9kpHjrZFRuRrRJF=1H4W6A@mail.gmail.com/
> Reported-by: Rondreis <linhaoguo86@gmail.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
> ---
>   drivers/scsi/sg.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 340b050ad28d..f44cbe42dba9 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -388,6 +388,7 @@ sg_release(struct inode *inode, struct file *filp)
>   		return -ENXIO;
>   	SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_release\n"));
>   
> +	kref_get(&sdp->d_ref);
>   	mutex_lock(&sdp->open_rel_lock);
>   	scsi_autopm_put_device(sdp->device);
>   	kref_put(&sfp->f_ref, sg_remove_sfp);
> @@ -402,6 +403,7 @@ sg_release(struct inode *inode, struct file *filp)
>   		wake_up_interruptible(&sdp->open_wait);
>   	}
>   	mutex_unlock(&sdp->open_rel_lock);
> +	kref_put(&sdp->d_ref, sg_device_destroy);
>   	return 0;
>   }
>  


Hi Rondreis,
Have you been able to test the above patch from Tony?

Doug Gilbert


  reply	other threads:[~2022-09-28 21:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 14:46 Rondreis
2022-09-22  6:10 ` Douglas Gilbert
2022-09-22 15:29 ` Tony Battersby
2022-09-28 21:45   ` Douglas Gilbert [this message]
2022-09-29  3:01     ` Rondreis

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=af3d2628-bf00-d897-d140-415985c29bfd@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=jejb@linux.ibm.com \
    --cc=linhaoguo86@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=tonyb@cybernetics.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

all inboxes | Powered by JetHome®