[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220328143853.GU3293@kadam>
Date: Mon, 28 Mar 2022 17:38:53 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: "Fabio M. De Francesco" <fmdefrancesco@...il.com>
Cc: axboe@...nel.dk, linux-block@...r.kernel.org,
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
linux-scsi@...r.kernel.org,
syzbot+f08c77040fa163a75a46@...kaller.appspotmail.com
Subject: Re: [PATCH] scsi: sd: Jump to out_free_index if device_add{,_disk}()
fail
On Mon, Mar 28, 2022 at 10:44:52AM +0200, Fabio M. De Francesco wrote:
> Currently, if device_add() or device_add_disk() fail, the code jumps to
> the "out" label. Doing so we get a memory leak as Syzbot reports.[1]
>
> Fix this bug by jumping to the "out_free_index" label.
>
> [1] https://groups.google.com/g/syzkaller-bugs/c/BvuqG6YGb6I
>
> Reported-and-tested-by: syzbot+f08c77040fa163a75a46@...kaller.appspotmail.com
> Fixes: 2a7a891f4c40 ("scsi: sd: Add error handling support for add_disk()")
> Fixes: 265dfe8ebbab ("scsi: sd: Free scsi_disk device via put_device()")
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@...il.com>
> ---
> drivers/scsi/sd.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index a390679cf458..61fcf653ef5a 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -3434,7 +3434,7 @@ static int sd_probe(struct device *dev)
> error = device_add(&sdkp->disk_dev);
> if (error) {
> put_device(&sdkp->disk_dev);
> - goto out;
> + goto out_free_index;
The put_device calls scsi_disk_release() so this change will introduce
use after frees and double frees.
There is a larger process issue here. We need to figure out why syzbot
did not detect that this patch introduces bugs.
regards,
dan carpenter
Powered by blists - more mailing lists