Skip to content

Commit

Permalink
native_network_stack: Fix use after free/missing wait in dhcp
Browse files Browse the repository at this point in the history
Fixes #184

DHCP code could cause incoming packets to filter with freed dhcp object
if smp calls to unregister did not complete immediately.
In fact, neither register nor de-reg waited for the smp invokes, which
could also make us miss packets -> fail dhcp.

Message-Id: <[email protected]>
  • Loading branch information
Calle Wilund authored and avikivity committed Aug 29, 2016
1 parent 0303e0c commit d92551d
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions net/native-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,20 @@ seastar::socket native_network_stack::socket() {
using namespace std::chrono_literals;

future<> native_network_stack::run_dhcp(bool is_renew, const dhcp::lease& res) {
lw_shared_ptr<dhcp> d = make_lw_shared<dhcp>(_inet);

dhcp d(_inet);
// Hijack the ip-stack.
for (unsigned i = 0; i < smp::count; i++) {
smp::submit_to(i, [d] {
auto & ns = static_cast<native_network_stack&>(engine().net());
ns.set_ipv4_packet_filter(d->get_ipv4_filter());
});
}

net::dhcp::result_type fut = is_renew ? d->renew(res) : d->discover();

return fut.then([this, d, is_renew](bool success, const dhcp::lease & res) {
for (unsigned i = 0; i < smp::count; i++) {
smp::submit_to(i, [] {
auto f = d.get_ipv4_filter();
return smp::invoke_on_all([f] {
auto & ns = static_cast<native_network_stack&>(engine().net());
ns.set_ipv4_packet_filter(f);
}).then([this, d = std::move(d), is_renew, res]() mutable {
net::dhcp::result_type fut = is_renew ? d.renew(res) : d.discover();
return fut.then([this, is_renew](bool success, const dhcp::lease & res) {
return smp::invoke_on_all([] {
auto & ns = static_cast<native_network_stack&>(engine().net());
ns.set_ipv4_packet_filter(nullptr);
});
}
on_dhcp(success, res, is_renew);
}).then(std::bind(&net::native_network_stack::on_dhcp, this, success, res, is_renew));
}).finally([d = std::move(d)] {});
});
}

Expand Down

0 comments on commit d92551d

Please sign in to comment.