From: Maritu Hone <marehone12@gmail.com>
To: vireshk@kernel.org
Cc: johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org,
greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, outreachy@lists.linux.dev,
Maritu Hone <marehone12@gmail.com>
Subject: [PATCH] staging: greybus: fw-management: validate firmware_tag is NUL-terminated
Date: Mon, 2 Nov 2026 17:12:21 +0300 [thread overview]
Message-ID: <20261102141221.87646-1-marehone12@gmail.com> (raw)
fw_mgmt_ioctl() copies struct fw_mgmt_ioc_get_backend_version,
struct fw_mgmt_ioc_intf_load_and_validate and
struct fw_mgmt_ioc_backend_fw_update directly from userspace via
copy_from_user(). Each of these contains a fixed-size
firmware_tag[GB_FIRMWARE_U_TAG_MAX_SIZE] array that is never checked
for NUL-termination before being used.
While the array is eventually copied into a Greybus request via
strscpy_pad(), which safely bounds its read and always NUL-terminates
its destination, three error paths print the original, unterminated
userspace buffer directly with "%s":
fw_mgmt_backend_fw_version_operation():
dev_err(..., "failed to get version of %s backend firmware (%d)\n",
fw_info->firmware_tag, ret);
dev_err(..., "Firmware with tag %s is not supported by Interface\n",
fw_info->firmware_tag);
fw_mgmt_backend_fw_update_operation():
dev_err(..., "backend %s firmware update request failed (%d)\n",
tag, ret);
If a caller supplies exactly GB_FIRMWARE_U_TAG_MAX_SIZE non-NUL bytes,
"%s" has no terminator inside the array and reads past it into
adjacent kernel stack memory until it happens to find a zero byte,
leaking that memory into dmesg.
Reject the ioctl up front when firmware_tag is not NUL-terminated,
mirroring the existing check already used for the equivalent
Greybus-module-supplied field in fw_download_find_firmware().
Fixes: 013e66537273 ("greybus: fw-management: Add firmware-management protocol driver")
Signed-off-by: Maritu Hone <marehone12@gmail.com>
---
drivers/staging/greybus/fw-management.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c
index 5d01da6b6eb9..2ee609dd67fb 100644
--- a/drivers/staging/greybus/fw-management.c
+++ b/drivers/staging/greybus/fw-management.c
@@ -419,6 +419,11 @@ static int fw_mgmt_ioctl(struct fw_mgmt *fw_mgmt, unsigned int cmd,
sizeof(backend_fw_info)))
return -EFAULT;
+ if (strnlen(backend_fw_info.firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE) ==
+ GB_FIRMWARE_U_TAG_MAX_SIZE)
+ return -EINVAL;
+
ret = fw_mgmt_backend_fw_version_operation(fw_mgmt,
&backend_fw_info);
if (ret)
@@ -433,6 +438,11 @@ static int fw_mgmt_ioctl(struct fw_mgmt *fw_mgmt, unsigned int cmd,
if (copy_from_user(&intf_load, buf, sizeof(intf_load)))
return -EFAULT;
+ if (strnlen(intf_load.firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE) ==
+ GB_FIRMWARE_U_TAG_MAX_SIZE)
+ return -EINVAL;
+
ret = fw_mgmt_load_and_validate_operation(fw_mgmt,
intf_load.load_method, intf_load.firmware_tag);
if (ret)
@@ -457,6 +467,11 @@ static int fw_mgmt_ioctl(struct fw_mgmt *fw_mgmt, unsigned int cmd,
sizeof(backend_update)))
return -EFAULT;
+ if (strnlen(backend_update.firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE) ==
+ GB_FIRMWARE_U_TAG_MAX_SIZE)
+ return -EINVAL;
+
ret = fw_mgmt_backend_fw_update_operation(fw_mgmt,
backend_update.firmware_tag);
if (ret)
--
2.43.0
next reply other threads:[~2026-11-02 14:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 14:12 Maritu Hone [this message]
2026-11-02 14:54 ` Dan Carpenter
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=20261102141221.87646-1-marehone12@gmail.com \
--to=marehone12@gmail.com \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
--cc=vireshk@kernel.org \
/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®