linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: touchscreen: wm97xx-core: Fix possible null-pointer dereferences in wm97xx_ts_input_open()
@ 2019-07-26  8:48 Jia-Ju Bai
  2019-07-26  9:06 ` Charles Keepax
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-26  8:48 UTC (permalink / raw)
  To: dmitry.torokhov, gregkh, tglx, allison, rdunlap
  Cc: patches, linux-input, linux-kernel, Jia-Ju Bai

In wm97xx_ts_input_open(), there is an if statement on line 507 to check
whether wm->mach_ops is NULL:
    if (wm->mach_ops && wm->mach_ops->acc_enabled)

When wm->mach_ops is NULL, it is used on line 521:
    wm97xx_init_pen_irq(wm);
        BUG_ON(!wm->mach_ops->irq_enable);
        BUG_ON(!wm->mach_ops->irq_gpio);
        wm97xx_reg_write(..., reg & ~(wm->mach_ops->irq_gpio))

Thus, possible null-pointer dereferences may occur.

To fix these bugs, wm->mach_ops is checked before calling
wm97xx_init_pen_irq().

These bugs found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/input/touchscreen/wm97xx-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index 0a174bd82915..f7bd0726a577 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -517,7 +517,7 @@ static int wm97xx_ts_input_open(struct input_dev *idev)
 	wm->ts_reader_interval = wm->ts_reader_min_interval;
 
 	wm->pen_is_down = 0;
-	if (wm->pen_irq)
+	if (wm->pen_irq && wm->mach_ops)
 		wm97xx_init_pen_irq(wm);
 	else
 		dev_err(wm->dev, "No IRQ specified\n");
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] input: touchscreen: wm97xx-core: Fix possible null-pointer dereferences in wm97xx_ts_input_open()
  2019-07-26  8:48 [PATCH] input: touchscreen: wm97xx-core: Fix possible null-pointer dereferences in wm97xx_ts_input_open() Jia-Ju Bai
@ 2019-07-26  9:06 ` Charles Keepax
  2019-07-26  9:08   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Keepax @ 2019-07-26  9:06 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: dmitry.torokhov, gregkh, tglx, allison, rdunlap, patches,
	linux-input, linux-kernel

On Fri, Jul 26, 2019 at 04:48:16PM +0800, Jia-Ju Bai wrote:
> In wm97xx_ts_input_open(), there is an if statement on line 507 to check
> whether wm->mach_ops is NULL:
>     if (wm->mach_ops && wm->mach_ops->acc_enabled)
> 
> When wm->mach_ops is NULL, it is used on line 521:
>     wm97xx_init_pen_irq(wm);
>         BUG_ON(!wm->mach_ops->irq_enable);
>         BUG_ON(!wm->mach_ops->irq_gpio);
>         wm97xx_reg_write(..., reg & ~(wm->mach_ops->irq_gpio))
> 
> Thus, possible null-pointer dereferences may occur.
> 
> To fix these bugs, wm->mach_ops is checked before calling
> wm97xx_init_pen_irq().
> 
> These bugs found by a static analysis tool STCheck written by us.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/input/touchscreen/wm97xx-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
> index 0a174bd82915..f7bd0726a577 100644
> --- a/drivers/input/touchscreen/wm97xx-core.c
> +++ b/drivers/input/touchscreen/wm97xx-core.c
> @@ -517,7 +517,7 @@ static int wm97xx_ts_input_open(struct input_dev *idev)
>  	wm->ts_reader_interval = wm->ts_reader_min_interval;
>  
>  	wm->pen_is_down = 0;
> -	if (wm->pen_irq)
> +	if (wm->pen_irq && wm->mach_ops)
>  		wm97xx_init_pen_irq(wm);
>  	else
>  		dev_err(wm->dev, "No IRQ specified\n");

This doesn't quite feel like the right fix as it would print an
error message saying "No IRQ specified", in the case the IRQ is
specified but the mach_ops have not been set.

I would suggest either extending the existing BUG_ON or adding a
new check in wm97xx_init_pen_irq.

Thanks,
Charles

> -- 
> 2.17.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] input: touchscreen: wm97xx-core: Fix possible null-pointer dereferences in wm97xx_ts_input_open()
  2019-07-26  9:06 ` Charles Keepax
@ 2019-07-26  9:08   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2019-07-26  9:08 UTC (permalink / raw)
  To: Charles Keepax
  Cc: dmitry.torokhov, gregkh, tglx, allison, rdunlap, patches,
	linux-input, linux-kernel



On 2019/7/26 17:06, Charles Keepax wrote:
> On Fri, Jul 26, 2019 at 04:48:16PM +0800, Jia-Ju Bai wrote:
>> In wm97xx_ts_input_open(), there is an if statement on line 507 to check
>> whether wm->mach_ops is NULL:
>>      if (wm->mach_ops && wm->mach_ops->acc_enabled)
>>
>> When wm->mach_ops is NULL, it is used on line 521:
>>      wm97xx_init_pen_irq(wm);
>>          BUG_ON(!wm->mach_ops->irq_enable);
>>          BUG_ON(!wm->mach_ops->irq_gpio);
>>          wm97xx_reg_write(..., reg & ~(wm->mach_ops->irq_gpio))
>>
>> Thus, possible null-pointer dereferences may occur.
>>
>> To fix these bugs, wm->mach_ops is checked before calling
>> wm97xx_init_pen_irq().
>>
>> These bugs found by a static analysis tool STCheck written by us.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>>   drivers/input/touchscreen/wm97xx-core.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
>> index 0a174bd82915..f7bd0726a577 100644
>> --- a/drivers/input/touchscreen/wm97xx-core.c
>> +++ b/drivers/input/touchscreen/wm97xx-core.c
>> @@ -517,7 +517,7 @@ static int wm97xx_ts_input_open(struct input_dev *idev)
>>   	wm->ts_reader_interval = wm->ts_reader_min_interval;
>>   
>>   	wm->pen_is_down = 0;
>> -	if (wm->pen_irq)
>> +	if (wm->pen_irq && wm->mach_ops)
>>   		wm97xx_init_pen_irq(wm);
>>   	else
>>   		dev_err(wm->dev, "No IRQ specified\n");
> This doesn't quite feel like the right fix as it would print an
> error message saying "No IRQ specified", in the case the IRQ is
> specified but the mach_ops have not been set.
>
> I would suggest either extending the existing BUG_ON or adding a
> new check in wm97xx_init_pen_irq.

Thanks for the advice.
I will send a v2 patch of adding a new check in wm97xx_init_pen_irq().


Best wishes,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-26  9:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-26  8:48 [PATCH] input: touchscreen: wm97xx-core: Fix possible null-pointer dereferences in wm97xx_ts_input_open() Jia-Ju Bai
2019-07-26  9:06 ` Charles Keepax
2019-07-26  9:08   ` Jia-Ju Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).