src: make nfq_open_nfnl thread-safe
Florian Westphal
maintainerPATCH 1/1 src: make nfq_open_nfnl thread-safe
nfq_open_nfnl uses an intermediate static object, so when
it is invoked by distinct threads at the same time there is a small chance that some threads end up with another threads nfq_handle pointer stored in ->data.
--- src/libnetfilter_queue.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
src/libnetfilter_queue.c +4 -5
@@ -216,11 +216,6 @@ static int __nfq_rcv_pkt(struct nlmsghdr *nlh, struct nfattr *nfa[],return qh->cb (qh, nfmsg, &nfqa, qh->data); } -static struct nfnl_callback pkt_cb = { - .call = &__nfq_rcv_pkt, - .attr_count =NFQA_MAX , -}; -/* public interface */ struct nfnl_handle *nfq_nfnlh (struct nfq_handle *h)
@@ -389,6 +384,10 @@ EXPORT_SYMBOL(nfq_open);*/ struct nfq_handle *nfq_open_nfnl (struct nfnl_handle *nfnlh) { +struct nfnl_callback pkt_cb = { + .call = __nfq_rcv_pkt, + .attr_count =NFQA_MAX , + };struct nfq_handle *h;int err;
Signature · 1 line
2.7.3
Quoted 7 lines · Florian Westphal
nfq_open_nfnluses an intermediate static object, so when
it is invoked by distinct threads at the same time there is a small chance that some threads end up with another threadsnfq_handlepointer stored in ->data.Tested-by Michal Tesar <[email protected]>Signed-off-by Florian Westphal <[email protected]>
Pablo Neira Ayuso
maintainerQuoted 10 lines · Pablo Neira Ayuso
Quoted 7 lines · Florian Westphal
nfq_open_nfnluses an intermediate static object, so when
it is invoked by distinct threads at the same time there is a small chance that some threads end up with another threadsnfq_handlepointer stored in ->data.Tested-by Michal Tesar <[email protected]>Signed-off-by Florian Westphal <[email protected]>
Wait wait...
This is allocated in this stack?
struct nfq_handle *nfq_open_nfnl(struct nfnl_handle *nfnlh) {
+ struct nfnl_callback pkt_cb = {
+ .call = __nfq_rcv_pkt, + .attr_count = NFQA_MAX,
+ };
Then accessed out of it?
I mean, this is passed by reference to the callback registration.
Florian Westphal
maintainerQuoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
nfq_open_nfnluses an intermediate static object, so when
it is invoked by distinct threads at the same time there is a small chance that some threads end up with another threadsnfq_handlepointer stored in ->data.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Tested-by Michal Tesar <[email protected]>Signed-off-by Florian Westphal <[email protected]>Wait wait...
Sorry, already pushed it after seeing the Ack...
Quoted 9 lines
This is allocated in this stack?
struct
nfq_handle*nfq_open_nfnl(structnfnl_handle*nfnlh) {src/libnetfilter_queue.c +4
-0+struct nfnl_callback pkt_cb = { + .call = __nfq_rcv_pkt, + .attr_count =NFQA_MAX , + };
Quoted 3 lines
Then accessed out of it?
I mean, this is passed by reference to the callback registration.
AFAICS nfnl_callback_register() memcpy's the thing into nfnl_handle, which is malloc'd in nfq_open_nfnl.
Pablo Neira Ayuso
maintainerQuoted 26 lines · Florian Westphal
Quoted 7 lines · Pablo Neira Ayuso
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
nfq_open_nfnluses an intermediate static object, so when
it is invoked by distinct threads at the same time there is a small chance that some threads end up with another threadsnfq_handlepointer stored in ->data.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Tested-by Michal Tesar <[email protected]>Signed-off-by Florian Westphal <[email protected]>Wait wait...
Sorry, already pushed it after seeing the Ack...
Quoted 9 lines
This is allocated in this stack?
struct
nfq_handle*nfq_open_nfnl(structnfnl_handle*nfnlh) {src/libnetfilter_queue.c +4
-0+struct nfnl_callback pkt_cb = { + .call = __nfq_rcv_pkt, + .attr_count =NFQA_MAX , + };
Quoted 6 lines
Quoted 3 lines
Then accessed out of it?
I mean, this is passed by reference to the callback registration.
AFAICS
nfnl_callback_register()memcpy's the thing intonfnl_handle, which is malloc'd innfq_open_nfnl.
Right, sorry for the noise.