From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 01/10] shared/att: Use util_iov helpers to build and parse PDUs
Date: Mon, 9 Nov 2026 10:44:52 -0500 [thread overview]
Message-ID: <20261109154501.1362649-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261109154501.1362649-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Build the PDU in encode_pdu and read the signature counter in
handle_signed with util_iov_push/pull so the length checks are done as
part of the access.
Assisted-by: OpenCode:claude-sonnet-5.5
---
src/shared/att.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/shared/att.c b/src/shared/att.c
index 3055f291f8f1..4fa69e597556 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -338,7 +338,9 @@ static bool encode_pdu(struct bt_att *att, struct att_send_op *op,
{
uint16_t pdu_len = 1;
struct sign_info *sign = att->local_sign;
+ struct iovec iov;
uint32_t sign_cnt;
+ void *sig;
if (sign && (op->opcode & ATT_OP_SIGNED_MASK))
pdu_len += BT_ATT_SIGNATURE_LEN;
@@ -354,9 +356,12 @@ static bool encode_pdu(struct bt_att *att, struct att_send_op *op,
if (!op->pdu)
return false;
- ((uint8_t *) op->pdu)[0] = op->opcode;
- if (pdu_len > 1)
- memcpy(op->pdu + 1, pdu, length);
+ iov.iov_base = op->pdu;
+ iov.iov_len = 0;
+
+ util_iov_push_u8(&iov, op->opcode);
+ if (length && pdu)
+ util_iov_push_mem(&iov, length, pdu);
if (!sign || !(op->opcode & ATT_OP_SIGNED_MASK) || !att->crypto)
return true;
@@ -364,8 +369,13 @@ static bool encode_pdu(struct bt_att *att, struct att_send_op *op,
if (!sign->counter(&sign_cnt, sign->user_data))
goto fail;
- if ((bt_crypto_sign_att(att->crypto, sign->key, op->pdu, 1 + length,
- sign_cnt, &((uint8_t *) op->pdu)[1 + length])))
+ sig = util_iov_push(&iov, BT_ATT_SIGNATURE_LEN);
+ if (!sig)
+ goto fail;
+
+ if ((bt_crypto_sign_att(att->crypto, sign->key, op->pdu,
+ iov.iov_len - BT_ATT_SIGNATURE_LEN,
+ sign_cnt, sig)))
return true;
DBG(att, "ATT unable to generate signature");
@@ -978,7 +988,7 @@ static void respond_not_supported(struct bt_att *att, uint8_t opcode)
static bool handle_signed(struct bt_att *att, uint8_t *pdu, ssize_t pdu_len)
{
- uint8_t *signature;
+ struct iovec iov = { pdu, pdu_len };
uint32_t sign_cnt;
struct sign_info *sign;
uint8_t opcode = pdu[0];
@@ -991,8 +1001,10 @@ static bool handle_signed(struct bt_att *att, uint8_t *pdu, ssize_t pdu_len)
if (!sign)
goto fail;
- signature = pdu + (pdu_len - BT_ATT_SIGNATURE_LEN);
- sign_cnt = get_le32(signature);
+ /* Skip to the signature trailer, the counter is its first field */
+ if (!util_iov_pull(&iov, pdu_len - BT_ATT_SIGNATURE_LEN) ||
+ !util_iov_pull_le32(&iov, &sign_cnt))
+ goto fail;
/* Validate counter */
if (!sign->counter(&sign_cnt, sign->user_data))
--
2.56.0
next prev parent reply other threads:[~2026-11-09 15:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 15:44 [PATCH BlueZ v1 00/10] shared/gatt: Use util_iov helpers for PDU handling Luiz Augusto von Dentz
2026-11-09 15:44 ` Luiz Augusto von Dentz [this message]
2026-11-10 6:49 ` bluez.test.bot
2026-11-09 15:44 ` [PATCH BlueZ v1 02/10] shared/gatt-server: Use util_iov helpers to build and parse PDUs Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 03/10] shared/gatt-helpers: " Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 04/10] shared/gatt-client: " Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 05/10] unit/test-gatt: Add malformed PDU tests Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 06/10] shared/gatt-server: Fix authorize callback getting handle 0 on write Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 07/10] shared/gatt-server: Fix double response on prepare write failure Luiz Augusto von Dentz
2026-11-09 15:44 ` [PATCH BlueZ v1 08/10] shared/gatt-server: Fix return value of handler registration Luiz Augusto von Dentz
2026-11-09 15:45 ` [PATCH BlueZ v1 09/10] shared/att: Fix reference leak on signature verification failure Luiz Augusto von Dentz
2026-11-09 15:45 ` [PATCH BlueZ v1 10/10] shared/att: Fix signature length subtracted once per handler Luiz Augusto von Dentz
2026-11-10 16:40 ` [PATCH BlueZ v1 00/10] shared/gatt: Use util_iov helpers for PDU handling patchwork-bot+bluetooth
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=20261109154501.1362649-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.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