From: Inga Stotland <inga.stotland@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: brian.gix@intel.com, Inga Stotland <inga.stotland@intel.com>
Subject: [PATCH BlueZ 2/3] mesh: Add size checks for every opcode in config server
Date: Mon, 13 Jul 2020 16:05:27 -0700 [thread overview]
Message-ID: <20200713230528.107948-3-inga.stotland@intel.com> (raw)
In-Reply-To: <20200713230528.107948-1-inga.stotland@intel.com>
This adds missing size checks for the incoming config server messages.
---
mesh/cfgmod-server.c | 46 +++++++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c
index 08a74d014..9046a1ad9 100644
--- a/mesh/cfgmod-server.c
+++ b/mesh/cfgmod-server.c
@@ -754,7 +754,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
case OP_DEV_COMP_GET:
if (size != 1)
- return false;
+ return true;
n = mesh_model_opcode_set(OP_DEV_COMP_STATUS, msg);
n += get_composition(node, pkt[0], msg + n);
@@ -770,6 +770,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_DEFAULT_TTL_GET:
+ if (opcode == OP_CONFIG_DEFAULT_TTL_GET && size != 0)
+ return true;
+
l_debug("Get/Set Default TTL");
n = mesh_model_opcode_set(OP_CONFIG_DEFAULT_TTL_STATUS, msg);
@@ -792,6 +795,8 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_CONFIG_MODEL_PUB_GET:
+ if (size != 4 && size != 6)
+ return true;
config_pub_get(node, net_idx, src, dst, pkt, size);
break;
@@ -832,6 +837,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_RELAY_GET:
+ if (opcode == OP_CONFIG_RELAY_GET && size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_CONFIG_RELAY_STATUS, msg);
msg[n++] = node_relay_mode_get(node, &count, &interval);
@@ -853,6 +861,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_NETWORK_TRANSMIT_GET:
+ if (opcode == OP_CONFIG_NETWORK_TRANSMIT_GET && size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_CONFIG_NETWORK_TRANSMIT_STATUS,
msg);
mesh_net_transmit_params_get(net, &count, &interval);
@@ -869,6 +880,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_PROXY_GET:
+ if (opcode == OP_CONFIG_PROXY_GET && size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_CONFIG_PROXY_STATUS, msg);
msg[n++] = node_proxy_mode_get(node);
@@ -883,9 +897,7 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
if (n_idx > 0xfff)
return true;
- /*
- * Currently no support for proxy: node identity not supported
- */
+ /* Currently setting node identity not supported */
/* Fall Through */
@@ -918,6 +930,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_BEACON_GET:
+ if (opcode == OP_CONFIG_BEACON_GET && size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_CONFIG_BEACON_STATUS, msg);
msg[n++] = node_beacon_mode_get(node);
@@ -932,6 +947,8 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall Through */
case OP_CONFIG_FRIEND_GET:
+ if (opcode == OP_CONFIG_FRIEND_GET && size != 0)
+ return true;
n = mesh_model_opcode_set(OP_CONFIG_FRIEND_STATUS, msg);
@@ -1071,13 +1088,14 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_NETKEY_GET:
+ if (size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_NETKEY_LIST, msg);
size = MAX_MSG_LEN - n;
if (mesh_net_key_list_get(net, msg + n, &size))
n += size;
- else
- n = 0;
break;
case OP_MODEL_APP_BIND:
@@ -1089,21 +1107,22 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
case OP_VEND_MODEL_APP_GET:
if (size != 6)
return true;
+
model_app_list(node, net_idx, src, dst, pkt, size);
break;
case OP_MODEL_APP_GET:
if (size != 4)
return true;
+
model_app_list(node, net_idx, src, dst, pkt, size);
break;
case OP_CONFIG_HEARTBEAT_PUB_SET:
l_debug("OP_CONFIG_HEARTBEAT_PUB_SET");
- if (size != 9) {
- l_debug("bad size %d", size);
+ if (size != 9)
return true;
- }
+
if (pkt[2] > 0x11 || pkt[3] > 0x10 || pkt[4] > 0x7f)
return true;
else if (IS_VIRTUAL(l_get_le16(pkt)))
@@ -1150,6 +1169,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_CONFIG_HEARTBEAT_PUB_GET:
+ if (size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_CONFIG_HEARTBEAT_PUB_STATUS, msg);
msg[n++] = b_res;
l_put_le16(hb->pub_dst, msg + n);
@@ -1179,6 +1201,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
/* Fall through */
case OP_CONFIG_HEARTBEAT_SUB_GET:
+ if (opcode == OP_CONFIG_HEARTBEAT_SUB_GET && size != 0)
+ return true;
+
gettimeofday(&time_now, NULL);
time_now.tv_sec -= hb->sub_start;
@@ -1218,6 +1243,9 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,
break;
case OP_NODE_RESET:
+ if (size != 0)
+ return true;
+
n = mesh_model_opcode_set(OP_NODE_RESET_STATUS, msg);
/* Delay node removal to give it a chance to send the status */
--
2.26.2
next prev parent reply other threads:[~2020-07-13 23:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-13 23:05 [PATCH BlueZ 0/3] Code re-org and clean up Inga Stotland
2020-07-13 23:05 ` [PATCH BlueZ 1/3] mesh: Use static array to hold config server response Inga Stotland
2020-07-13 23:05 ` Inga Stotland [this message]
2020-07-13 23:05 ` [PATCH BlueZ 3/3] mesh: move model functionality out of node.c to model.c Inga Stotland
2020-07-16 17:20 ` [PATCH BlueZ 0/3] Code re-org and clean up Gix, Brian
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=20200713230528.107948-3-inga.stotland@intel.com \
--to=inga.stotland@intel.com \
--cc=brian.gix@intel.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;
as well as URLs for NNTP newsgroup(s).