Skip to content

Commit

Permalink
net: ppp: ip{,v6}cp: drop possible double free of nack_buf
Browse files Browse the repository at this point in the history
When iterating though configuration options it is possible that we will
fail to add data to nack_buf and hence unref it in error handling
path. Just after that we will unref buf, which has nack_buf in its
buffer chain.

Drop code unrefing nack_buf and just go directly to unrefing buf.

Signed-off-by: Marcin Niestroj <[email protected]>
  • Loading branch information
mniestroj authored and jukkar committed Jan 7, 2020
1 parent e0cf06f commit b3a8e7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
17 changes: 4 additions & 13 deletions subsys/net/l2/ppp/ipcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int ipcp_config_info_req(struct ppp_fsm *fsm,

nack_buf = ppp_get_net_buf(buf, nack_options[i].len);
if (!nack_buf) {
goto out_of_mem;
goto bail_out;
}

if (!buf) {
Expand All @@ -170,13 +170,13 @@ static int ipcp_config_info_req(struct ppp_fsm *fsm,
added = append_to_buf(nack_buf,
&nack_options[i].type.ipcp, 1);
if (!added) {
goto out_of_mem;
goto bail_out;
}

added = append_to_buf(nack_buf, &nack_options[i].len,
1);
if (!added) {
goto out_of_mem;
goto bail_out;
}

/* If there is some data, copy it to result buf */
Expand All @@ -185,18 +185,9 @@ static int ipcp_config_info_req(struct ppp_fsm *fsm,
nack_options[i].value.pos,
nack_options[i].len - 1 - 1);
if (!added) {
goto out_of_mem;
goto bail_out;
}
}

continue;

out_of_mem:
if (nack_buf) {
net_buf_unref(nack_buf);
}

goto bail_out;
}
} else {
struct ppp_context *ctx;
Expand Down
17 changes: 4 additions & 13 deletions subsys/net/l2/ppp/ipv6cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int ipv6cp_config_info_req(struct ppp_fsm *fsm,

nack_buf = ppp_get_net_buf(buf, nack_options[i].len);
if (!nack_buf) {
goto out_of_mem;
goto bail_out;
}

if (!buf) {
Expand All @@ -166,13 +166,13 @@ static int ipv6cp_config_info_req(struct ppp_fsm *fsm,
added = append_to_buf(nack_buf,
&nack_options[i].type.ipv6cp, 1);
if (!added) {
goto out_of_mem;
goto bail_out;
}

added = append_to_buf(nack_buf, &nack_options[i].len,
1);
if (!added) {
goto out_of_mem;
goto bail_out;
}

/* If there is some data, copy it to result buf */
Expand All @@ -181,18 +181,9 @@ static int ipv6cp_config_info_req(struct ppp_fsm *fsm,
nack_options[i].value.pos,
nack_options[i].len - 1 - 1);
if (!added) {
goto out_of_mem;
goto bail_out;
}
}

continue;

out_of_mem:
if (nack_buf) {
net_buf_unref(nack_buf);
}

goto bail_out;
}
} else {
u8_t iface_id[PPP_INTERFACE_IDENTIFIER_LEN];
Expand Down

0 comments on commit b3a8e7d

Please sign in to comment.