Skip to content

Commit ce7663d

Browse files
Yasuyuki KozakaiDavid S. Miller
authored andcommitted
[NETFILTER]: nfnetlink_queue: don't unregister handler of other subsystem
The queue handlers registered by ip[6]_queue.ko at initialization should not be unregistered according to requests from userland program using nfnetlink_queue. If we allow that, there is no way to register the handlers of built-in ip[6]_queue again. Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0d53778 commit ce7663d

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎include/linux/netfilter.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ struct nf_queue_handler {
275275
};
276276
extern int nf_register_queue_handler(int pf,
277277
struct nf_queue_handler *qh);
278-
extern int nf_unregister_queue_handler(int pf);
278+
extern int nf_unregister_queue_handler(int pf,
279+
struct nf_queue_handler *qh);
279280
extern void nf_unregister_queue_handlers(struct nf_queue_handler *qh);
280281
extern void nf_reinject(struct sk_buff *skb,
281282
struct nf_info *info,

‎net/netfilter/nf_queue.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ int nf_register_queue_handler(int pf, struct nf_queue_handler *qh)
4444
EXPORT_SYMBOL(nf_register_queue_handler);
4545

4646
/* The caller must flush their queue before this */
47-
int nf_unregister_queue_handler(int pf)
47+
int nf_unregister_queue_handler(int pf, struct nf_queue_handler *qh)
4848
{
4949
if (pf >= NPROTO)
5050
return -EINVAL;
5151

5252
write_lock_bh(&queue_handler_lock);
53+
if (queue_handler[pf] != qh) {
54+
write_unlock_bh(&queue_handler_lock);
55+
return -EINVAL;
56+
}
57+
5358
queue_handler[pf] = NULL;
5459
write_unlock_bh(&queue_handler_lock);
5560

‎net/netfilter/nfnetlink_queue.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,7 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
913913
case NFQNL_CFG_CMD_PF_UNBIND:
914914
QDEBUG("unregistering queue handler for pf=%u\n",
915915
ntohs(cmd->pf));
916-
/* This is a bug and a feature. We can unregister
917-
* other handlers(!) */
918-
ret = nf_unregister_queue_handler(ntohs(cmd->pf));
916+
ret = nf_unregister_queue_handler(ntohs(cmd->pf), &nfqh);
919917
break;
920918
default:
921919
ret = -EINVAL;

0 commit comments

Comments
 (0)