2019-03-09 08:00:03

by Kangjie Lu

[permalink] [raw]
Subject: [PATCH] memstick: fix a potential NULL pointer dereference

In case alloc_ordered_workqueue fails, the fix returns ENOMEM to
avoid potential NULL pointer dereference.

Signed-off-by: Kangjie Lu <[email protected]>
---
drivers/memstick/core/ms_block.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index 82daccc9ea62..8e00de414567 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -2149,6 +2149,11 @@ static int msb_init_disk(struct memstick_dev *card)

msb->usage_count = 1;
msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
+ if (!msb->io_queue) {
+ rc = -ENOMEM;
+ goto out_put_disk;
+ }
+
INIT_WORK(&msb->io_work, msb_io_work);
sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);

--
2.17.1



2019-03-23 03:09:57

by Kangjie Lu

[permalink] [raw]
Subject: Re: [PATCH] memstick: fix a potential NULL pointer dereference

Hi Maxim,

Can you review this patch?

Thanks,

> On Mar 9, 2019, at 1:59 AM, Kangjie Lu <[email protected]> wrote:
>
> In case alloc_ordered_workqueue fails, the fix returns ENOMEM to
> avoid potential NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <[email protected]>
> ---
> drivers/memstick/core/ms_block.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> index 82daccc9ea62..8e00de414567 100644
> --- a/drivers/memstick/core/ms_block.c
> +++ b/drivers/memstick/core/ms_block.c
> @@ -2149,6 +2149,11 @@ static int msb_init_disk(struct memstick_dev *card)
>
> msb->usage_count = 1;
> msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
> + if (!msb->io_queue) {
> + rc = -ENOMEM;
> + goto out_put_disk;
> + }
> +
> INIT_WORK(&msb->io_work, msb_io_work);
> sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
>
> --
> 2.17.1
>


2019-03-23 07:58:46

by Maxim Levitsky

[permalink] [raw]
Subject: Re: [PATCH] memstick: fix a potential NULL pointer dereference

On Sat, Mar 23, 2019 at 5:08 AM Kangjie Lu <[email protected]> wrote:
>
> Hi Maxim,
>
> Can you review this patch?
>
> Thanks,
>
> > On Mar 9, 2019, at 1:59 AM, Kangjie Lu <[email protected]> wrote:
> >
> > In case alloc_ordered_workqueue fails, the fix returns ENOMEM to
> > avoid potential NULL pointer dereference.
> >
> > Signed-off-by: Kangjie Lu <[email protected]>
> > ---
> > drivers/memstick/core/ms_block.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
> > index 82daccc9ea62..8e00de414567 100644
> > --- a/drivers/memstick/core/ms_block.c
> > +++ b/drivers/memstick/core/ms_block.c
> > @@ -2149,6 +2149,11 @@ static int msb_init_disk(struct memstick_dev *card)
> >
> > msb->usage_count = 1;
> > msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
> > + if (!msb->io_queue) {
> > + rc = -ENOMEM;
> > + goto out_put_disk;
> > + }
> > +
> > INIT_WORK(&msb->io_work, msb_io_work);
> > sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
> >
> > --
> > 2.17.1
> >

Looks OK to me!

Reviewed-by: Maxim Levitsky <[email protected]>

Best regards,
Maxim Levitsky