* [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated
@ 2026-11-17 7:39 Sai Krishna Potthuri
2026-11-17 7:46 ` sashiko-bot
2026-11-17 13:16 ` David Laight
0 siblings, 2 replies; 3+ messages in thread
From: Sai Krishna Potthuri @ 2026-11-17 7:39 UTC (permalink / raw)
To: Linus Walleij, Michal Simek
Cc: linux-gpio, linux-arm-kernel, linux-kernel, saikrishna12468, git,
Sai Krishna Potthuri
PM_QID_PINCTRL_GET_FUNCTION_NAME returns the function name in a fixed
16-byte field and does not guarantee NUL termination. A 16-character
name fills the entire field.
The driver copies this field into a 16-byte buffer and subsequently
uses it as a C string. For a non-NUL-terminated name, string operations
can read past the end of the buffer into the adjacent groups pointer.
Reserve an extra byte for the NUL terminator and explicitly terminate
the copied function name.
Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
---
drivers/pinctrl/pinctrl-zynqmp.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
index aba129ead04c..c778133fadc2 100644
--- a/drivers/pinctrl/pinctrl-zynqmp.c
+++ b/drivers/pinctrl/pinctrl-zynqmp.c
@@ -29,7 +29,11 @@
#define ZYNQMP_PIN_PREFIX "MIO"
#define PINCTRL_GET_FUNC_NAME_RESP_LEN 16
-#define MAX_FUNC_NAME_LEN 16
+/*
+ * Firmware returns the name in a fixed-size field and does not guarantee a
+ * NUL terminator. Keep one extra byte for the NUL terminator.
+ */
+#define MAX_FUNC_NAME_LEN (PINCTRL_GET_FUNC_NAME_RESP_LEN + 1)
#define MAX_GROUP_PIN 50
#define MAX_PIN_GROUPS 50
#define END_OF_FUNCTIONS "END_OF_FUNCTIONS"
@@ -650,6 +654,7 @@ static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
*/
zynqmp_pm_query_data(qdata, payload);
memcpy(name, payload, PINCTRL_GET_FUNC_NAME_RESP_LEN);
+ name[PINCTRL_GET_FUNC_NAME_RESP_LEN] = '\0';
}
static int zynqmp_pinctrl_get_num_functions(unsigned int *nfuncs)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated
2026-11-17 7:39 [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated Sai Krishna Potthuri
@ 2026-11-17 7:46 ` sashiko-bot
2026-11-17 13:16 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-17 7:46 UTC (permalink / raw)
To: Sai Krishna Potthuri; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] pinctrl: zynqmp: missing Fixes trailer for NUL termination fix
--
commit 6d64e921f0e4b7c5ff34668587fdab85ea6a7491
Author: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> pinctrl: zynqmp: Ensure function names are NUL terminated
>
> PM_QID_PINCTRL_GET_FUNCTION_NAME returns the function name in a fixed
> 16-byte field and does not guarantee NUL termination. A 16-character
> name fills the entire field.
> The driver copies this field into a 16-byte buffer and subsequently
> uses it as a C string. For a non-NUL-terminated name, string operations
> can read past the end of the buffer into the adjacent groups pointer.
>
> Reserve an extra byte for the NUL terminator and explicitly terminate
> the copied function name.
>
> Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
[Severity: Low]
Since this fixes an out-of-bounds string read in
zynqmp_pinctrl_get_function_name(), should it include a Fixes tag?
Fixes: 8b242ca700f8 ("pinctrl: Add Xilinx ZynqMP pinctrl driver support")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117073947.1100444-1-sai.krishna.potthuri@amd.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated
2026-11-17 7:39 [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated Sai Krishna Potthuri
2026-11-17 7:46 ` sashiko-bot
@ 2026-11-17 13:16 ` David Laight
1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2026-11-17 13:16 UTC (permalink / raw)
To: Sai Krishna Potthuri
Cc: Linus Walleij, Michal Simek, linux-gpio, linux-arm-kernel,
linux-kernel, saikrishna12468, git
On Tue, 17 Nov 2026 13:09:47 +0530
Sai Krishna Potthuri <sai.krishna.potthuri@amd.com> wrote:
> PM_QID_PINCTRL_GET_FUNCTION_NAME returns the function name in a fixed
> 16-byte field and does not guarantee NUL termination. A 16-character
> name fills the entire field.
> The driver copies this field into a 16-byte buffer and subsequently
> uses it as a C string. For a non-NUL-terminated name, string operations
> can read past the end of the buffer into the adjacent groups pointer.
>
> Reserve an extra byte for the NUL terminator and explicitly terminate
> the copied function name.
>
> Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
> ---
> drivers/pinctrl/pinctrl-zynqmp.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
> index aba129ead04c..c778133fadc2 100644
> --- a/drivers/pinctrl/pinctrl-zynqmp.c
> +++ b/drivers/pinctrl/pinctrl-zynqmp.c
> @@ -29,7 +29,11 @@
>
> #define ZYNQMP_PIN_PREFIX "MIO"
> #define PINCTRL_GET_FUNC_NAME_RESP_LEN 16
> -#define MAX_FUNC_NAME_LEN 16
> +/*
> + * Firmware returns the name in a fixed-size field and does not guarantee a
> + * NUL terminator. Keep one extra byte for the NUL terminator.
> + */
> +#define MAX_FUNC_NAME_LEN (PINCTRL_GET_FUNC_NAME_RESP_LEN + 1)
> #define MAX_GROUP_PIN 50
> #define MAX_PIN_GROUPS 50
> #define END_OF_FUNCTIONS "END_OF_FUNCTIONS"
> @@ -650,6 +654,7 @@ static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
> */
> zynqmp_pm_query_data(qdata, payload);
> memcpy(name, payload, PINCTRL_GET_FUNC_NAME_RESP_LEN);
> + name[PINCTRL_GET_FUNC_NAME_RESP_LEN] = '\0';
Too many constants....
You might want to try embedding 'name' in a structure.
Then, at least, you can use sizeof().
David
> }
>
> static int zynqmp_pinctrl_get_num_functions(unsigned int *nfuncs)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-17 13:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 7:39 [PATCH] pinctrl: zynqmp: Ensure function names are NUL terminated Sai Krishna Potthuri
2026-11-17 7:46 ` sashiko-bot
2026-11-17 13:16 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox