From: Suraj Theekshana <surajtheekshana1111@gmail.com>
To: vireshk@kernel.org, johan@kernel.org, elder@kernel.org,
gregkh@linuxfoundation.org
Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH] greybus: cap: bound IMS/auth memcpy to ioctl size
Date: Fri, 4 Sep 2026 03:46:28 +0000 [thread overview]
Message-ID: <20260904034628.12376-1-surajtheekshana1111@gmail.com> (raw)
cap_get_ims_certificate() and cap_authenticate() derive copy
lengths from response payload sizes without checking the response
header size or destination capacity.
Reject responses smaller than their headers with -EMSGSIZE. Reject
certificate and signature data larger than their fixed ioctl buffers
with -E2BIG.
Signed-off-by: Suraj Theekshana <surajtheekshana1111@gmail.com>
---
drivers/staging/greybus/authentication.c | 27 ++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index d8f2cd4..cbd28a3 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -128,9 +128,22 @@ static int cap_get_ims_certificate(struct gb_cap *cap, u32 class, u32 id,
goto done;
}
+ if (op->response->payload_size < sizeof(*response)) {
+ dev_err(cap->parent,
+ "invalid IMS certificate response size (%zu)\n",
+ op->response->payload_size);
+ ret = -EMSGSIZE;
+ goto done;
+ }
+
response = op->response->payload;
*result = response->result_code;
*size = op->response->payload_size - sizeof(*response);
+ if (*size > CAP_CERTIFICATE_MAX_SIZE) {
+ dev_err(cap->parent, "IMS certificate too large (%u)\n", *size);
+ ret = -E2BIG;
+ goto done;
+ }
memcpy(certificate, response->certificate, *size);
done:
@@ -167,9 +180,23 @@ static int cap_authenticate(struct gb_cap *cap, u32 auth_type, u8 *uid,
goto done;
}
+ if (op->response->payload_size < sizeof(*response)) {
+ dev_err(cap->parent,
+ "invalid authenticate response size (%zu)\n",
+ op->response->payload_size);
+ ret = -EMSGSIZE;
+ goto done;
+ }
+
response = op->response->payload;
*result = response->result_code;
*signature_size = op->response->payload_size - sizeof(*response);
+ if (*signature_size > CAP_SIGNATURE_MAX_SIZE) {
+ dev_err(cap->parent, "authenticate signature too large (%u)\n",
+ *signature_size);
+ ret = -E2BIG;
+ goto done;
+ }
memcpy(auth_response, response->response, sizeof(response->response));
memcpy(signature, response->signature, *signature_size);
--
2.43.0
next reply other threads:[~2026-09-04 3:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 3:46 Suraj Theekshana [this message]
2026-09-04 4:19 ` Greg KH
[not found] ` <CA+_JcNRPo1dojU4EmegM5Fv-YpZqiyd_K7SRz8km1VzzPv2nMw@mail.gmail.com>
2026-09-04 5:46 ` Greg KH
2026-09-04 5:56 ` Suraj Theekshana
2026-09-04 6:28 ` Greg KH
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=20260904034628.12376-1-surajtheekshana1111@gmail.com \
--to=surajtheekshana1111@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=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®