-
Notifications
You must be signed in to change notification settings - Fork 23
address: fix use after free #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include <gr_module.h> | ||
| #include <gr_net_types.h> | ||
| #include <gr_queue.h> | ||
| #include <gr_rcu.h> | ||
| #include <gr_vec.h> | ||
|
|
||
| #include <event2/event.h> | ||
|
|
@@ -138,7 +139,20 @@ static int mcast6_addr_add(const struct iface *iface, const struct rte_ipv6_addr | |
| } | ||
|
|
||
| nexthop_incref(nh); | ||
| gr_vec_add(maddrs->nh, nh); | ||
|
|
||
| // gr_vec_add may realloc() and free the old vector | ||
| // Duplicate the whole vector and append to the clone. | ||
| gr_vec struct nexthop **nhs_copy = NULL; | ||
| gr_vec struct nexthop **nhs_old = maddrs->nh; | ||
| gr_vec_cap_set(nhs_copy, gr_vec_len(nhs_old) + 1); // avoid malloc+realloc | ||
| gr_vec_extend(nhs_copy, nhs_old); | ||
| gr_vec_add(nhs_copy, nh); | ||
| maddrs->nh = nhs_copy; | ||
| if (nhs_old != NULL) { | ||
| // Once all datapath workers have seen the new clone, free the old one. | ||
| rte_rcu_qsbr_synchronize(gr_datapath_rcu(), RTE_QSBR_THRID_INVALID); | ||
| gr_vec_free(nhs_old); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a real gc, not doing synchronize barrier every where seems more and more needed for grout...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. We will soon need to implement such a thing. |
||
| } | ||
|
|
||
| // add ethernet filter | ||
| return iface_add_eth_addr(iface->id, &mac); | ||
|
|
@@ -228,7 +242,20 @@ iface6_addr_add(const struct iface *iface, const struct rte_ipv6_addr *ip, uint8 | |
| if (ret < 0) | ||
| return errno_set(-ret); | ||
|
|
||
| gr_vec_add(addrs->nh, nh); | ||
| // gr_vec_add may realloc() and free the old vector | ||
| // Duplicate the whole vector and append to the clone. | ||
| gr_vec struct nexthop **nhs_copy = NULL; | ||
| gr_vec struct nexthop **nhs_old = addrs->nh; | ||
| gr_vec_cap_set(nhs_copy, gr_vec_len(nhs_old) + 1); // avoid malloc+realloc | ||
| gr_vec_extend(nhs_copy, nhs_old); | ||
| gr_vec_add(nhs_copy, nh); | ||
| addrs->nh = nhs_copy; | ||
| if (nhs_old != NULL) { | ||
| // Once all datapath workers have seen the new clone, free the old one. | ||
| rte_rcu_qsbr_synchronize(gr_datapath_rcu(), RTE_QSBR_THRID_INVALID); | ||
| gr_vec_free(nhs_old); | ||
| } | ||
|
|
||
| gr_event_push( | ||
| GR_EVENT_IP6_ADDR_ADD, | ||
| &(struct gr_ip6_ifaddr) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gr_vec_clone will to do a malloc, gr_vec_add will do a realloc, it could be optimized:
gr_vec_grow(nhs_copy, gr_vec_len(nhs_old) +1) ;
gr_vec_extend(nhs_copy, nh_old);
gr_vec_add(nhs_copy, nh);
no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could change this to:
But it is less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind. Let me know what you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this one, it is still readable, more efficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done