mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
To: Linus Walleij <linusw@kernel.org>, Michal Simek <michal.simek@amd.com>
Cc: <linux-gpio@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <saikrishna12468@gmail.com>,
	<git@amd.com>,
	Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Subject: [PATCH v2] pinctrl: zynqmp: Ensure function names are NUL terminated
Date: Wed, 18 Nov 2026 16:48:16 +0530	[thread overview]
Message-ID: <20261118111816.2483052-1-sai.krishna.potthuri@amd.com> (raw)

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


                 reply	other threads:[~2026-11-18 11:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118111816.2483052-1-sai.krishna.potthuri@amd.com \
    --to=sai.krishna.potthuri@amd.com \
    --cc=git@amd.com \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=saikrishna12468@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®