2022-11-18 10:57:04

by Maxim Korotkov

[permalink] [raw]
Subject: [PATCH] pinctrl: single: fix potential NULL dereference

Added checking of pointer "function" in pcs_set_mux().
pinmux_generic_get_function() can return NULL and the pointer
"function" was dereferenced without checking against NULL.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 571aec4df5b7 ("pinctrl: single: Use generic pinmux helpers for managing functions")
Signed-off-by: Maxim Korotkov <[email protected]>
---
drivers/pinctrl/pinctrl-single.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 67bec7ea0f8b..5655a2da5413 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -372,6 +372,8 @@ static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector,
if (!pcs->fmask)
return 0;
function = pinmux_generic_get_function(pctldev, fselector);
+ if (!function)
+ return -EINVAL;
func = function->data;
if (!func)
return -EINVAL;
--
2.17.1



2022-11-18 13:27:03

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: single: fix potential NULL dereference

* Maxim Korotkov <[email protected]> [221118 10:33]:
> Added checking of pointer "function" in pcs_set_mux().
> pinmux_generic_get_function() can return NULL and the pointer
> "function" was dereferenced without checking against NULL.

Reviewed-by: Tony Lindgren <[email protected]>

2023-01-25 09:03:29

by Maxim Korotkov

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: single: fix potential NULL dereference

Dear Linus,
Will this patch be applied or rejected?
best regards, Max

On 18.11.2022 15:52, Tony Lindgren wrote:
> * Maxim Korotkov <[email protected]> [221118 10:33]:
>> Added checking of pointer "function" in pcs_set_mux().
>> pinmux_generic_get_function() can return NULL and the pointer
>> "function" was dereferenced without checking against NULL.
>
> Reviewed-by: Tony Lindgren <[email protected]>

2023-01-27 12:44:37

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: single: fix potential NULL dereference

On Fri, Nov 18, 2022 at 11:43 AM Maxim Korotkov
<[email protected]> wrote:

> Added checking of pointer "function" in pcs_set_mux().
> pinmux_generic_get_function() can return NULL and the pointer
> "function" was dereferenced without checking against NULL.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 571aec4df5b7 ("pinctrl: single: Use generic pinmux helpers for managing functions")
> Signed-off-by: Maxim Korotkov <[email protected]>

Patch applied for fixes.

Yours,
Linus Walleij