Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func
@ 2024-10-16 15:56 Colin Ian King
  2024-10-16 18:15 ` Drew Fustini
  2024-10-16 19:31 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Colin Ian King @ 2024-10-16 15:56 UTC (permalink / raw)
  To: Drew Fustini, Guo Ren, Fu Wei, Linus Walleij,
	Emil Renner Berthing, linux-riscv, linux-gpio
  Cc: kernel-janitors, linux-kernel

The initialization of muxtype deferences pointer func before func
is sanity checked with a null pointer check, hence we have a null
pointer deference issue. Fix this by only deferencing func with
the assignment to muxtype after func has been null pointer checked.

Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/pinctrl/pinctrl-th1520.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
index 7474d8da32f9..e641bad6728c 100644
--- a/drivers/pinctrl/pinctrl-th1520.c
+++ b/drivers/pinctrl/pinctrl-th1520.c
@@ -803,11 +803,12 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
 {
 	struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
 	const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
-	enum th1520_muxtype muxtype = (uintptr_t)func->data;
+	enum th1520_muxtype muxtype;
 
 	if (!func)
 		return -EINVAL;
 
+	muxtype = (uintptr_t)func->data;
 	return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
 				 th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
 				 muxtype);
-- 
2.39.5


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

* Re: [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func
  2024-10-16 15:56 [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func Colin Ian King
@ 2024-10-16 18:15 ` Drew Fustini
  2024-10-16 19:31 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Fustini @ 2024-10-16 18:15 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Drew Fustini, Guo Ren, Fu Wei, Linus Walleij,
	Emil Renner Berthing, linux-riscv, linux-gpio, kernel-janitors,
	linux-kernel

On Wed, Oct 16, 2024 at 04:56:55PM +0100, Colin Ian King wrote:
> The initialization of muxtype deferences pointer func before func
> is sanity checked with a null pointer check, hence we have a null
> pointer deference issue. Fix this by only deferencing func with
> the assignment to muxtype after func has been null pointer checked.
> 
> Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
>  drivers/pinctrl/pinctrl-th1520.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c
> index 7474d8da32f9..e641bad6728c 100644
> --- a/drivers/pinctrl/pinctrl-th1520.c
> +++ b/drivers/pinctrl/pinctrl-th1520.c
> @@ -803,11 +803,12 @@ static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev,
>  {
>  	struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev);
>  	const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel);
> -	enum th1520_muxtype muxtype = (uintptr_t)func->data;
> +	enum th1520_muxtype muxtype;
>  
>  	if (!func)
>  		return -EINVAL;
>  
> +	muxtype = (uintptr_t)func->data;
>  	return th1520_pinmux_set(thp, thp->desc.pins[gsel].number,
>  				 th1520_pad_muxdata(thp->desc.pins[gsel].drv_data),
>  				 muxtype);
> -- 
> 2.39.5
> 

Acked-by: Drew Fustini <dfustini@tenstorrent.com>

I've tested this on top of next-20241016 on the BeagleV Ahead and
LicheePi 4A.

thanks,
drew

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

* Re: [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func
  2024-10-16 15:56 [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func Colin Ian King
  2024-10-16 18:15 ` Drew Fustini
@ 2024-10-16 19:31 ` Linus Walleij
  2024-10-16 19:32   ` Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2024-10-16 19:31 UTC (permalink / raw)
  To: Colin Ian King, Kees Cook
  Cc: Drew Fustini, Guo Ren, Fu Wei, Emil Renner Berthing, linux-riscv,
	linux-gpio, kernel-janitors, linux-kernel

On Wed, Oct 16, 2024 at 5:56 PM Colin Ian King <colin.i.king@gmail.com> wrote:

> The initialization of muxtype deferences pointer func before func
> is sanity checked with a null pointer check, hence we have a null
> pointer deference issue. Fix this by only deferencing func with
> the assignment to muxtype after func has been null pointer checked.
>
> Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

Patch applied, added Reported-by Kees since he mailed about this too.

Yours,
Linus Walleij

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

* Re: [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func
  2024-10-16 19:31 ` Linus Walleij
@ 2024-10-16 19:32   ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-10-16 19:32 UTC (permalink / raw)
  To: Colin Ian King, Kees Cook, Kees Bakker
  Cc: Drew Fustini, Guo Ren, Fu Wei, Emil Renner Berthing, linux-riscv,
	linux-gpio, kernel-janitors, linux-kernel

On Wed, Oct 16, 2024 at 9:31 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> On Wed, Oct 16, 2024 at 5:56 PM Colin Ian King <colin.i.king@gmail.com> wrote:
>
> > The initialization of muxtype deferences pointer func before func
> > is sanity checked with a null pointer check, hence we have a null
> > pointer deference issue. Fix this by only deferencing func with
> > the assignment to muxtype after func has been null pointer checked.
> >
> > Fixes: 1fc30cd92770 ("pinctrl: th1520: Factor out casts")
> > Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
>
> Patch applied, added Reported-by Kees since he mailed about this too.

...which was actually the "other Kees" (Bakker), not the one the mailer
suggested.

Yours,
Linus Walleij

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

end of thread, other threads:[~2024-10-16 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-16 15:56 [PATCH][next] pinctrl: th1520: Fix potential null pointer dereference on func Colin Ian King
2024-10-16 18:15 ` Drew Fustini
2024-10-16 19:31 ` Linus Walleij
2024-10-16 19:32   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox