Skip to contentSkip to conversation

netfilter: nf_tables: don't call nfnetlink_set_err() if nfnetlink_send() fails

PATCH In review Pablo Neira Ayuso 2 participants 2 messages Mar 2, 2017

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 netfilter: nf_tables: don't call nfnetlink_set_err() if nfnetlink_send() fails

The underlying nlmsg_multicast() already sets sk->sk_err for us to notify socket overruns, so we should not do anything with this return value. So we just call nfnetlink_set_err() if:

1) We fail to allocate the netlink message.

or

2) We don't have enough space in the netlink message to place the attribute, which means that we likely need to allocate a larger message.

Before this patch, the internal ESRCH netlink error code which is very misleading. Netlink semantics mandate that listeners hit ENOBUFS if the socket buffer overruns.

---
v2: Previous patch was still calling nfnetlink_set_err() when nfnetlink_send()
fails, this is not correct. Fix it in this new round.

 include/net/netfilter/nf_tables.h |   6 +-
 net/netfilter/nf_tables_api.c     | 133 ++++++++++++++++----------------------
 2 files changed, 58 insertions(+), 81 deletions(-)
include/net/netfilter/nf_tables.h +3 -3
index ac84686aaafb..2aa8a9d80fbe 100644
@@ -988,9 +988,9 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
 					const struct nlattr *nla, u32 objtype,
 					u8 genmask);
 
-int nft_obj_notify(struct net *net, struct nft_table *table,
-		   struct nft_object *obj, u32 portid, u32 seq,
-		   int event, int family, int report, gfp_t gfp);
+void nft_obj_notify(struct net *net, struct nft_table *table,
+		    struct nft_object *obj, u32 portid, u32 seq,
+		    int event, int family, int report, gfp_t gfp);
 
 /**
  *	struct nft_object_type - stateful object type
net/netfilter/nf_tables_api.c +55 -78

277 lines not on this page · raw message

Signature · 1 line
2.1.4
Tested-by on v2 1/1
#1 lore raw
Quoted 11 lines · Pablo Neira Ayuso

The underlying nlmsg_multicast() already sets sk->sk_err for us to notify socket overruns, so we should not do anything with this return value. So we just call nfnetlink_set_err() if:

1) We fail to allocate the netlink message.

or

2) We don't have enough space in the netlink message to place the attribute, which means that we likely need to allocate a larger message.

Quoted 6 lines

Before this patch, the internal ESRCH netlink error code which is very misleading. Netlink semantics mandate that listeners hit ENOBUFS if the socket buffer overruns.

Signature · 3 lines
Mit freundlichen Grüßen

Alexander Alemayhu