Skip to content

Commit 52e01b8

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following patchset contains Netfilter updates for your net-next tree, they are: 1) Stash ctinfo 3-bit field into pointer to nf_conntrack object from sk_buff so we only access one single cacheline in the conntrack hotpath. Patchset from Florian Westphal. 2) Don't leak pointer to internal structures when exporting x_tables ruleset back to userspace, from Willem DeBruijn. This includes new helper functions to copy data to userspace such as xt_data_to_user() as well as conversions of our ip_tables, ip6_tables and arp_tables clients to use it. Not surprinsingly, ebtables requires an ad-hoc update. There is also a new field in x_tables extensions to indicate the amount of bytes that we copy to userspace. 3) Add nf_log_all_netns sysctl: This new knob allows you to enable logging via nf_log infrastructure for all existing netnamespaces. Given the effort to provide pernet syslog has been discontinued, let's provide a way to restore logging using netfilter kernel logging facilities in trusted environments. Patch from Michal Kubecek. 4) Validate SCTP checksum from conntrack helper, from Davide Caratti. 5) Merge UDPlite conntrack and NAT helpers into UDP, this was mostly a copy&paste from the original helper, from Florian Westphal. 6) Reset netfilter state when duplicating packets, also from Florian. 7) Remove unnecessary check for broadcast in IPv6 in pkttype match and nft_meta, from Liping Zhang. 8) Add missing code to deal with loopback packets from nft_meta when used by the netdev family, also from Liping. 9) Several cleanups on nf_tables, one to remove unnecessary check from the netlink control plane path to add table, set and stateful objects and code consolidation when unregister chain hooks, from Gao Feng. 10) Fix harmless reference counter underflow in IPVS that, however, results in problems with the introduction of the new refcount_t type, from David Windsor. 11) Enable LIBCRC32C from nf_ct_sctp instead of nf_nat_sctp, from Davide Caratti. 12) Missing documentation on nf_tables uapi header, from Liping Zhang. 13) Use rb_entry() helper in xt_connlimit, from Geliang Tang. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents e60df62 + 2851940 commit 52e01b8

65 files changed

Lines changed: 646 additions & 680 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/proc/sys/net/netfilter/* Variables:
2+
3+
nf_log_all_netns - BOOLEAN
4+
0 - disabled (default)
5+
not 0 - enabled
6+
7+
By default, only init_net namespace can log packets into kernel log
8+
with LOG target; this aims to prevent containers from flooding host
9+
kernel log. If enabled, this target also works in other network
10+
namespaces. This variable is only accessible from init_net.

‎include/linux/netfilter/x_tables.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ struct xt_match {
167167

168168
const char *table;
169169
unsigned int matchsize;
170+
unsigned int usersize;
170171
#ifdef CONFIG_COMPAT
171172
unsigned int compatsize;
172173
#endif
@@ -207,6 +208,7 @@ struct xt_target {
207208

208209
const char *table;
209210
unsigned int targetsize;
211+
unsigned int usersize;
210212
#ifdef CONFIG_COMPAT
211213
unsigned int compatsize;
212214
#endif
@@ -287,6 +289,13 @@ int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto,
287289
int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto,
288290
bool inv_proto);
289291

292+
int xt_match_to_user(const struct xt_entry_match *m,
293+
struct xt_entry_match __user *u);
294+
int xt_target_to_user(const struct xt_entry_target *t,
295+
struct xt_entry_target __user *u);
296+
int xt_data_to_user(void __user *dst, const void *src,
297+
int usersize, int size);
298+
290299
void *xt_copy_counters_from_user(const void __user *user, unsigned int len,
291300
struct xt_counters_info *info, bool compat);
292301

‎include/linux/skbuff.h‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
585585
* @cloned: Head may be cloned (check refcnt to be sure)
586586
* @ip_summed: Driver fed us an IP checksum
587587
* @nohdr: Payload reference only, must not modify header
588-
* @nfctinfo: Relationship of this skb to the connection
589588
* @pkt_type: Packet class
590589
* @fclone: skbuff clone status
591590
* @ipvs_property: skbuff is owned by ipvs
@@ -598,7 +597,7 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
598597
* @nf_trace: netfilter packet trace flag
599598
* @protocol: Packet protocol from driver
600599
* @destructor: Destruct function
601-
* @nfct: Associated connection, if any
600+
* @_nfct: Associated connection, if any (with nfctinfo bits)
602601
* @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
603602
* @skb_iif: ifindex of device we arrived on
604603
* @tc_index: Traffic control index
@@ -671,7 +670,7 @@ struct sk_buff {
671670
struct sec_path *sp;
672671
#endif
673672
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
674-
struct nf_conntrack *nfct;
673+
unsigned long _nfct;
675674
#endif
676675
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
677676
struct nf_bridge_info *nf_bridge;
@@ -724,7 +723,6 @@ struct sk_buff {
724723
__u8 pkt_type:3;
725724
__u8 pfmemalloc:1;
726725
__u8 ignore_df:1;
727-
__u8 nfctinfo:3;
728726

729727
__u8 nf_trace:1;
730728
__u8 ip_summed:2;
@@ -841,6 +839,7 @@ static inline bool skb_pfmemalloc(const struct sk_buff *skb)
841839
#define SKB_DST_NOREF 1UL
842840
#define SKB_DST_PTRMASK ~(SKB_DST_NOREF)
843841

842+
#define SKB_NFCT_PTRMASK ~(7UL)
844843
/**
845844
* skb_dst - returns skb dst_entry
846845
* @skb: buffer
@@ -3558,6 +3557,15 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr,
35583557
skb->csum = csum_add(skb->csum, delta);
35593558
}
35603559

3560+
static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb)
3561+
{
3562+
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
3563+
return (void *)(skb->_nfct & SKB_NFCT_PTRMASK);
3564+
#else
3565+
return NULL;
3566+
#endif
3567+
}
3568+
35613569
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
35623570
void nf_conntrack_destroy(struct nf_conntrack *nfct);
35633571
static inline void nf_conntrack_put(struct nf_conntrack *nfct)
@@ -3586,8 +3594,8 @@ static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
35863594
static inline void nf_reset(struct sk_buff *skb)
35873595
{
35883596
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
3589-
nf_conntrack_put(skb->nfct);
3590-
skb->nfct = NULL;
3597+
nf_conntrack_put(skb_nfct(skb));
3598+
skb->_nfct = 0;
35913599
#endif
35923600
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
35933601
nf_bridge_put(skb->nf_bridge);
@@ -3607,10 +3615,8 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src,
36073615
bool copy)
36083616
{
36093617
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
3610-
dst->nfct = src->nfct;
3611-
nf_conntrack_get(src->nfct);
3612-
if (copy)
3613-
dst->nfctinfo = src->nfctinfo;
3618+
dst->_nfct = src->_nfct;
3619+
nf_conntrack_get(skb_nfct(src));
36143620
#endif
36153621
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
36163622
dst->nf_bridge = src->nf_bridge;
@@ -3625,7 +3631,7 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src,
36253631
static inline void nf_copy(struct sk_buff *dst, const struct sk_buff *src)
36263632
{
36273633
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
3628-
nf_conntrack_put(dst->nfct);
3634+
nf_conntrack_put(skb_nfct(dst));
36293635
#endif
36303636
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
36313637
nf_bridge_put(dst->nf_bridge);
@@ -3657,9 +3663,7 @@ static inline bool skb_irq_freeable(const struct sk_buff *skb)
36573663
#if IS_ENABLED(CONFIG_XFRM)
36583664
!skb->sp &&
36593665
#endif
3660-
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
3661-
!skb->nfct &&
3662-
#endif
3666+
!skb_nfct(skb) &&
36633667
!skb->_skb_refdst &&
36643668
!skb_has_frag_list(skb);
36653669
}

‎include/net/ip_vs.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
14211421

14221422
static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
14231423
{
1424-
if (atomic_dec_return(&dest->refcnt) < 0)
1424+
if (atomic_dec_and_test(&dest->refcnt))
14251425
kfree(dest);
14261426
}
14271427

@@ -1554,10 +1554,12 @@ static inline void ip_vs_notrack(struct sk_buff *skb)
15541554
struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
15551555

15561556
if (!ct || !nf_ct_is_untracked(ct)) {
1557-
nf_conntrack_put(skb->nfct);
1558-
skb->nfct = &nf_ct_untracked_get()->ct_general;
1559-
skb->nfctinfo = IP_CT_NEW;
1560-
nf_conntrack_get(skb->nfct);
1557+
struct nf_conn *untracked;
1558+
1559+
nf_conntrack_put(&ct->ct_general);
1560+
untracked = nf_ct_untracked_get();
1561+
nf_conntrack_get(&untracked->ct_general);
1562+
nf_ct_set(skb, untracked, IP_CT_NEW);
15611563
}
15621564
#endif
15631565
}

‎include/net/netfilter/ipv4/nf_conntrack_ipv4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4;
1414

1515
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4;
1616
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
17+
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4;
1718
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp;
1819
#ifdef CONFIG_NF_CT_PROTO_DCCP
1920
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp4;

‎include/net/netfilter/ipv6/nf_conntrack_ipv6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6;
55

66
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6;
77
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6;
8+
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6;
89
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6;
910
#ifdef CONFIG_NF_CT_PROTO_DCCP
1011
extern struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp6;

‎include/net/netfilter/nf_conntrack.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ union nf_conntrack_proto {
3434
struct ip_ct_sctp sctp;
3535
struct ip_ct_tcp tcp;
3636
struct nf_ct_gre gre;
37+
unsigned int tmpl_padto;
3738
};
3839

3940
union nf_conntrack_expect_proto {
@@ -75,7 +76,7 @@ struct nf_conn {
7576
/* Usage count in here is 1 for hash table, 1 per skb,
7677
* plus 1 for any connection(s) we are `master' for
7778
*
78-
* Hint, SKB address this struct and refcnt via skb->nfct and
79+
* Hint, SKB address this struct and refcnt via skb->_nfct and
7980
* helpers nf_conntrack_get() and nf_conntrack_put().
8081
* Helper nf_ct_put() equals nf_conntrack_put() by dec refcnt,
8182
* beware nf_ct_get() is different and don't inc refcnt.
@@ -162,12 +163,16 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
162163
int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
163164
const struct nf_conn *ignored_conntrack);
164165

166+
#define NFCT_INFOMASK 7UL
167+
#define NFCT_PTRMASK ~(NFCT_INFOMASK)
168+
165169
/* Return conntrack_info and tuple hash for given skb. */
166170
static inline struct nf_conn *
167171
nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
168172
{
169-
*ctinfo = skb->nfctinfo;
170-
return (struct nf_conn *)skb->nfct;
173+
*ctinfo = skb->_nfct & NFCT_INFOMASK;
174+
175+
return (struct nf_conn *)(skb->_nfct & NFCT_PTRMASK);
171176
}
172177

173178
/* decrement reference count on a conntrack */
@@ -341,6 +346,12 @@ struct nf_conn *nf_ct_tmpl_alloc(struct net *net,
341346
gfp_t flags);
342347
void nf_ct_tmpl_free(struct nf_conn *tmpl);
343348

349+
static inline void
350+
nf_ct_set(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info info)
351+
{
352+
skb->_nfct = (unsigned long)ct | info;
353+
}
354+
344355
#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count)
345356
#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
346357
#define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v))

‎include/net/netfilter/nf_conntrack_core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int __nf_conntrack_confirm(struct sk_buff *skb);
6262
/* Confirm a connection: returns NF_DROP if packet must be dropped. */
6363
static inline int nf_conntrack_confirm(struct sk_buff *skb)
6464
{
65-
struct nf_conn *ct = (struct nf_conn *)skb->nfct;
65+
struct nf_conn *ct = (struct nf_conn *)skb_nfct(skb);
6666
int ret = NF_ACCEPT;
6767

6868
if (ct && !nf_ct_is_untracked(ct)) {

‎include/net/netfilter/nf_conntrack_l4proto.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct nf_conntrack_l4proto {
5555
void (*destroy)(struct nf_conn *ct);
5656

5757
int (*error)(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
58-
unsigned int dataoff, enum ip_conntrack_info *ctinfo,
58+
unsigned int dataoff,
5959
u_int8_t pf, unsigned int hooknum);
6060

6161
/* Print out the per-protocol part of the tuple. Return like seq_* */

‎include/net/netfilter/nf_log.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct nf_logger {
5151
struct module *me;
5252
};
5353

54+
/* sysctl_nf_log_all_netns - allow LOG target in all network namespaces */
55+
extern int sysctl_nf_log_all_netns;
56+
5457
/* Function to register/unregister log function. */
5558
int nf_log_register(u_int8_t pf, struct nf_logger *logger);
5659
void nf_log_unregister(struct nf_logger *logger);

0 commit comments

Comments
 (0)