Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated
@ 2026-11-18 11:18 Sai Krishna Potthuri
  2026-11-18 11:25 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sai Krishna Potthuri @ 2026-11-18 11:18 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>
---
changes in v2:
- Replace macro/constants with sizeof()(comment from David Laight)

 drivers/pinctrl/pinctrl-zynqmp.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
index aba129ead04c..a0b48193ad98 100644
--- a/drivers/pinctrl/pinctrl-zynqmp.c
+++ b/drivers/pinctrl/pinctrl-zynqmp.c
@@ -29,7 +29,6 @@
 
 #define ZYNQMP_PIN_PREFIX			"MIO"
 #define PINCTRL_GET_FUNC_NAME_RESP_LEN		16
-#define MAX_FUNC_NAME_LEN			16
 #define MAX_GROUP_PIN				50
 #define MAX_PIN_GROUPS				50
 #define END_OF_FUNCTIONS			"END_OF_FUNCTIONS"
@@ -61,7 +60,7 @@
  * and function group names supporting that function.
  */
 struct zynqmp_pmux_function {
-	char name[MAX_FUNC_NAME_LEN];
+	char name[PINCTRL_GET_FUNC_NAME_RESP_LEN + 1];
 	const char * const *groups;
 	unsigned int ngroups;
 };
@@ -635,7 +634,7 @@ static int zynqmp_pinctrl_prepare_func_groups(struct device *dev, u32 fid,
 	return 0;
 }
 
-static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
+static void zynqmp_pinctrl_get_function_name(u32 fid, struct zynqmp_pmux_function *func)
 {
 	struct zynqmp_pm_query_data qdata = {0};
 	u32 payload[PAYLOAD_ARG_CNT];
@@ -649,7 +648,8 @@ static void zynqmp_pinctrl_get_function_name(u32 fid, char *name)
 	 * the return value for this specific qid.
 	 */
 	zynqmp_pm_query_data(qdata, payload);
-	memcpy(name, payload, PINCTRL_GET_FUNC_NAME_RESP_LEN);
+	memcpy(func->name, payload, sizeof(func->name) - 1);
+	func->name[sizeof(func->name) - 1] = '\0';
 }
 
 static int zynqmp_pinctrl_get_num_functions(unsigned int *nfuncs)
@@ -795,7 +795,7 @@ static int zynqmp_pinctrl_prepare_function_info(struct device *dev,
 		return -ENOMEM;
 
 	for (i = 0; i < pctrl->nfuncs; i++) {
-		zynqmp_pinctrl_get_function_name(i, funcs[i].name);
+		zynqmp_pinctrl_get_function_name(i, &funcs[i]);
 
 		ret = zynqmp_pinctrl_get_func_num_groups(i, &funcs[i].ngroups);
 		if (ret)
-- 
2.25.1


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

* Re: [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated
  2026-11-18 11:18 [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated Sai Krishna Potthuri
@ 2026-11-18 11:25 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18 11:25 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 9edfc24329d75f5063aa1d16738b9cc9a5a2b745
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 when a 16-character function
name is returned without a NUL terminator, should it include a Fixes: tag?

  Fixes: 8b242ca700f8 ("pinctrl: Add Xilinx ZynqMP pinctrl driver support")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118111816.2483052-1-sai.krishna.potthuri@amd.com?part=1

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

end of thread, other threads:[~2026-11-18 11:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 11:18 [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated Sai Krishna Potthuri
2026-11-18 11:25 ` sashiko-bot

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