* [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated
@ 2026-11-18 11:18 Sai Krishna Potthuri
0 siblings, 0 replies; only message 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 [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 11:18 UTC | newest]
Thread overview: (only message) (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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®