* [PATCH V2] st: fix potential null pointer dereference.
@ 2015-11-18 14:32 Maurizio Lombardi
2015-11-19 15:10 ` Tomas Henzl
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Maurizio Lombardi @ 2015-11-18 14:32 UTC (permalink / raw)
To: Kai.Makisara; +Cc: James.Bottomley, linux-scsi
If cdev_add() returns an error, the code calls
cdev_del() passing the STm->cdevs[rew] pointer as parameter;
the problem is that the pointer has not been initialized yet.
This patch fixes the problem by moving the STm->cdevs[rew] pointer
initialization before the call to cdev_add().
It also sets STm->devs[rew] and STm->cdevs[rew] to NULL in
case of failure.
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
drivers/scsi/st.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index e0a1e52..2e52295 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4083,6 +4083,7 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
}
cdev->owner = THIS_MODULE;
cdev->ops = &st_fops;
+ STm->cdevs[rew] = cdev;
error = cdev_add(cdev, cdev_devno, 1);
if (error) {
@@ -4091,7 +4092,6 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
pr_err("st%d: Device not attached.\n", dev_num);
goto out_free;
}
- STm->cdevs[rew] = cdev;
i = mode << (4 - ST_NBR_MODE_BITS);
snprintf(name, 10, "%s%s%s", rew ? "n" : "",
@@ -4110,8 +4110,9 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
return 0;
out_free:
cdev_del(STm->cdevs[rew]);
- STm->cdevs[rew] = NULL;
out:
+ STm->cdevs[rew] = NULL;
+ STm->devs[rew] = NULL;
return error;
}
--
Maurizio Lombardi
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH V2] st: fix potential null pointer dereference.
2015-11-18 14:32 [PATCH V2] st: fix potential null pointer dereference Maurizio Lombardi
@ 2015-11-19 15:10 ` Tomas Henzl
2015-11-19 15:13 ` Johannes Thumshirn
2015-11-24 19:59 ` "Kai Mäkisara (Kolumbus)"
2 siblings, 0 replies; 4+ messages in thread
From: Tomas Henzl @ 2015-11-19 15:10 UTC (permalink / raw)
To: Maurizio Lombardi, Kai.Makisara; +Cc: James.Bottomley, linux-scsi
On 18.11.2015 15:32, Maurizio Lombardi wrote:
> If cdev_add() returns an error, the code calls
> cdev_del() passing the STm->cdevs[rew] pointer as parameter;
> the problem is that the pointer has not been initialized yet.
>
> This patch fixes the problem by moving the STm->cdevs[rew] pointer
> initialization before the call to cdev_add().
> It also sets STm->devs[rew] and STm->cdevs[rew] to NULL in
> case of failure.
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
> drivers/scsi/st.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index e0a1e52..2e52295 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -4083,6 +4083,7 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
> }
> cdev->owner = THIS_MODULE;
> cdev->ops = &st_fops;
> + STm->cdevs[rew] = cdev;
>
> error = cdev_add(cdev, cdev_devno, 1);
> if (error) {
> @@ -4091,7 +4092,6 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
> pr_err("st%d: Device not attached.\n", dev_num);
> goto out_free;
> }
> - STm->cdevs[rew] = cdev;
>
> i = mode << (4 - ST_NBR_MODE_BITS);
> snprintf(name, 10, "%s%s%s", rew ? "n" : "",
> @@ -4110,8 +4110,9 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
> return 0;
> out_free:
> cdev_del(STm->cdevs[rew]);
> - STm->cdevs[rew] = NULL;
> out:
> + STm->cdevs[rew] = NULL;
> + STm->devs[rew] = NULL;
Reviewed-by: Tomas Henzl <thenzl@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] st: fix potential null pointer dereference.
2015-11-18 14:32 [PATCH V2] st: fix potential null pointer dereference Maurizio Lombardi
2015-11-19 15:10 ` Tomas Henzl
@ 2015-11-19 15:13 ` Johannes Thumshirn
2015-11-24 19:59 ` "Kai Mäkisara (Kolumbus)"
2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2015-11-19 15:13 UTC (permalink / raw)
To: Maurizio Lombardi, Kai.Makisara; +Cc: James.Bottomley, linux-scsi
On Wed, 2015-11-18 at 15:32 +0100, Maurizio Lombardi wrote:
> If cdev_add() returns an error, the code calls
> cdev_del() passing the STm->cdevs[rew] pointer as parameter;
> the problem is that the pointer has not been initialized yet.
>
> This patch fixes the problem by moving the STm->cdevs[rew] pointer
> initialization before the call to cdev_add().
> It also sets STm->devs[rew] and STm->cdevs[rew] to NULL in
> case of failure.
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
> drivers/scsi/st.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index e0a1e52..2e52295 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -4083,6 +4083,7 @@ static int create_one_cdev(struct scsi_tape
> *tape, int mode, int rew)
> }
> cdev->owner = THIS_MODULE;
> cdev->ops = &st_fops;
> + STm->cdevs[rew] = cdev;
>
> error = cdev_add(cdev, cdev_devno, 1);
> if (error) {
> @@ -4091,7 +4092,6 @@ static int create_one_cdev(struct scsi_tape
> *tape, int mode, int rew)
> pr_err("st%d: Device not attached.\n", dev_num);
> goto out_free;
> }
> - STm->cdevs[rew] = cdev;
>
> i = mode << (4 - ST_NBR_MODE_BITS);
> snprintf(name, 10, "%s%s%s", rew ? "n" : "",
> @@ -4110,8 +4110,9 @@ static int create_one_cdev(struct scsi_tape
> *tape, int mode, int rew)
> return 0;
> out_free:
> cdev_del(STm->cdevs[rew]);
> - STm->cdevs[rew] = NULL;
> out:
> + STm->cdevs[rew] = NULL;
> + STm->devs[rew] = NULL;
> return error;
> }
>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH V2] st: fix potential null pointer dereference.
2015-11-18 14:32 [PATCH V2] st: fix potential null pointer dereference Maurizio Lombardi
2015-11-19 15:10 ` Tomas Henzl
2015-11-19 15:13 ` Johannes Thumshirn
@ 2015-11-24 19:59 ` "Kai Mäkisara (Kolumbus)"
2 siblings, 0 replies; 4+ messages in thread
From: "Kai Mäkisara (Kolumbus)" @ 2015-11-24 19:59 UTC (permalink / raw)
To: Maurizio Lombardi; +Cc: James.Bottomley, linux-scsi
> On 18.11.2015, at 16.32, Maurizio Lombardi <mlombard@redhat.com> wrote:
>
> If cdev_add() returns an error, the code calls
> cdev_del() passing the STm->cdevs[rew] pointer as parameter;
> the problem is that the pointer has not been initialized yet.
>
> This patch fixes the problem by moving the STm->cdevs[rew] pointer
> initialization before the call to cdev_add().
> It also sets STm->devs[rew] and STm->cdevs[rew] to NULL in
> case of failure.
>
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Acked-by: Kai Mäkisara <kai.makisara@kolumbus.fi>
Thanks,
Kai
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-24 19:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 14:32 [PATCH V2] st: fix potential null pointer dereference Maurizio Lombardi
2015-11-19 15:10 ` Tomas Henzl
2015-11-19 15:13 ` Johannes Thumshirn
2015-11-24 19:59 ` "Kai Mäkisara (Kolumbus)"
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.