* [PATCH BlueZ v3] mesh: Fix segmentation fault after adding second netkey via NET_KEY_ADD opcode
@ 2019-06-10 8:46 Jakub Witowski
2019-06-11 22:33 ` Gix, Brian
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Witowski @ 2019-06-10 8:46 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Brian Gix, Inga Stotland
Segmentation fault was caused by passing subnet pointer to the
start_network_beacon() which was NULL
---
mesh/net.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/mesh/net.c b/mesh/net.c
index c7aff9ab4..fdd38e7ce 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -977,27 +977,28 @@ int mesh_net_del_key(struct mesh_net *net, uint16_t idx)
return MESH_STATUS_SUCCESS;
}
-static int add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
+static struct mesh_subnet *add_key(struct mesh_net *net, uint16_t idx,
+ const uint8_t *value)
{
struct mesh_subnet *subnet;
subnet = subnet_new(net, idx);
if (!subnet)
- return MESH_STATUS_INSUFF_RESOURCES;
+ return NULL;
subnet->net_key_tx = subnet->net_key_cur = net_key_add(value);
if (!subnet->net_key_cur) {
l_free(subnet);
- return MESH_STATUS_INSUFF_RESOURCES;
+ return NULL;
}
if (!create_secure_beacon(net, subnet, subnet->snb.beacon + 1) ||
!l_queue_push_tail(net->subnets, subnet)) {
subnet_free(subnet);
- return MESH_STATUS_INSUFF_RESOURCES;
+ return NULL;
}
- return MESH_STATUS_SUCCESS;
+ return subnet;
}
/*
@@ -1007,7 +1008,6 @@ static int add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
{
struct mesh_subnet *subnet;
- int status;
subnet = l_queue_find(net->subnets, match_key_index,
L_UINT_TO_PTR(idx));
@@ -1019,9 +1019,9 @@ int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
return MESH_STATUS_IDX_ALREADY_STORED;
}
- status = add_key(net, idx, value);
- if (status != MESH_STATUS_SUCCESS)
- return status;
+ subnet = add_key(net, idx, value);
+ if (!subnet)
+ return MESH_STATUS_INSUFF_RESOURCES;
if (!storage_net_key_add(net, idx, value, false)) {
l_queue_remove(net->subnets, subnet);
@@ -2490,7 +2490,7 @@ static void net_rx(void *net_ptr, void *user_data)
int8_t rssi = 0;
key_id = net_key_decrypt(net->iv_index, data->data, data->len,
- &out, &out_size);
+ &out, &out_size);
if (!key_id)
return;
@@ -3017,7 +3017,6 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
const uint8_t *new_key, uint8_t phase)
{
struct mesh_subnet *subnet;
- int status;
subnet = l_queue_find(net->subnets, match_key_index,
L_UINT_TO_PTR(idx));
@@ -3032,8 +3031,8 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
if (phase != KEY_REFRESH_PHASE_NONE && !new_key)
return false;
- status = add_key(net, idx, key);
- if (status != MESH_STATUS_SUCCESS)
+ subnet = add_key(net, idx, key);
+ if (!subnet)
return false;
subnet = l_queue_find(net->subnets, match_key_index,
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH BlueZ v3] mesh: Fix segmentation fault after adding second netkey via NET_KEY_ADD opcode
2019-06-10 8:46 [PATCH BlueZ v3] mesh: Fix segmentation fault after adding second netkey via NET_KEY_ADD opcode Jakub Witowski
@ 2019-06-11 22:33 ` Gix, Brian
0 siblings, 0 replies; 2+ messages in thread
From: Gix, Brian @ 2019-06-11 22:33 UTC (permalink / raw)
To: jakub.witowski, linux-bluetooth; +Cc: Stotland, Inga
Patch Applied, Thanks.
On Mon, 2019-06-10 at 10:46 +0200, Jakub Witowski wrote:
> Segmentation fault was caused by passing subnet pointer to the
> start_network_beacon() which was NULL
> ---
> mesh/net.c | 25 ++++++++++++-------------
> 1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/mesh/net.c b/mesh/net.c
> index c7aff9ab4..fdd38e7ce 100644
> --- a/mesh/net.c
> +++ b/mesh/net.c
> @@ -977,27 +977,28 @@ int mesh_net_del_key(struct mesh_net *net, uint16_t idx)
> return MESH_STATUS_SUCCESS;
> }
>
> -static int add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
> +static struct mesh_subnet *add_key(struct mesh_net *net, uint16_t idx,
> + const uint8_t *value)
> {
> struct mesh_subnet *subnet;
>
> subnet = subnet_new(net, idx);
> if (!subnet)
> - return MESH_STATUS_INSUFF_RESOURCES;
> + return NULL;
>
> subnet->net_key_tx = subnet->net_key_cur = net_key_add(value);
> if (!subnet->net_key_cur) {
> l_free(subnet);
> - return MESH_STATUS_INSUFF_RESOURCES;
> + return NULL;
> }
>
> if (!create_secure_beacon(net, subnet, subnet->snb.beacon + 1) ||
> !l_queue_push_tail(net->subnets, subnet)) {
> subnet_free(subnet);
> - return MESH_STATUS_INSUFF_RESOURCES;
> + return NULL;
> }
>
> - return MESH_STATUS_SUCCESS;
> + return subnet;
> }
>
> /*
> @@ -1007,7 +1008,6 @@ static int add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
> int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
> {
> struct mesh_subnet *subnet;
> - int status;
>
> subnet = l_queue_find(net->subnets, match_key_index,
> L_UINT_TO_PTR(idx));
> @@ -1019,9 +1019,9 @@ int mesh_net_add_key(struct mesh_net *net, uint16_t idx, const uint8_t *value)
> return MESH_STATUS_IDX_ALREADY_STORED;
> }
>
> - status = add_key(net, idx, value);
> - if (status != MESH_STATUS_SUCCESS)
> - return status;
> + subnet = add_key(net, idx, value);
> + if (!subnet)
> + return MESH_STATUS_INSUFF_RESOURCES;
>
> if (!storage_net_key_add(net, idx, value, false)) {
> l_queue_remove(net->subnets, subnet);
> @@ -2490,7 +2490,7 @@ static void net_rx(void *net_ptr, void *user_data)
> int8_t rssi = 0;
>
> key_id = net_key_decrypt(net->iv_index, data->data, data->len,
> - &out, &out_size);
> + &out, &out_size);
>
> if (!key_id)
> return;
> @@ -3017,7 +3017,6 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
> const uint8_t *new_key, uint8_t phase)
> {
> struct mesh_subnet *subnet;
> - int status;
>
> subnet = l_queue_find(net->subnets, match_key_index,
> L_UINT_TO_PTR(idx));
> @@ -3032,8 +3031,8 @@ bool mesh_net_set_key(struct mesh_net *net, uint16_t idx, const uint8_t *key,
> if (phase != KEY_REFRESH_PHASE_NONE && !new_key)
> return false;
>
> - status = add_key(net, idx, key);
> - if (status != MESH_STATUS_SUCCESS)
> + subnet = add_key(net, idx, key);
> + if (!subnet)
> return false;
>
> subnet = l_queue_find(net->subnets, match_key_index,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-11 22:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 8:46 [PATCH BlueZ v3] mesh: Fix segmentation fault after adding second netkey via NET_KEY_ADD opcode Jakub Witowski
2019-06-11 22:33 ` Gix, Brian
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).