]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net...
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 17 Oct 2015 12:11:08 +0000 (14:11 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 17 Oct 2015 12:28:03 +0000 (14:28 +0200)
This merge resolves conflicts with 75aec9df3a78 ("bridge: Remove
br_nf_push_frag_xmit_sk") as part of Eric Biederman's effort to improve
netns support in the network stack that reached upstream via David's
net-next tree.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Conflicts:
net/bridge/br_netfilter_hooks.c

1  2 
net/bridge/br_netfilter_hooks.c
net/decnet/dn_route.c
net/ipv4/netfilter/ipt_SYNPROXY.c
net/ipv4/netfilter/nf_defrag_ipv4.c
net/ipv6/netfilter/ip6t_SYNPROXY.c
net/ipv6/netfilter/nf_conntrack_reasm.c
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c
net/ipv6/netfilter/nf_reject_ipv6.c
net/netfilter/ipvs/ip_vs_core.c
net/netfilter/nfnetlink_log.c
security/selinux/hooks.c

index 9d3051916a64b63753c5c02d12b9fc7b44e10fd5,370aa4d4cf4d3866624dbcdec6ad339ae302cd9a..7ddbe7ec81d61d4971b919c5988e7bed93436dec
@@@ -111,6 -111,7 +111,6 @@@ static inline __be16 pppoe_proto(const 
  /* largest possible L2 header, see br_nf_dev_queue_xmit() */
  #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN)
  
 -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
  struct brnf_frag_data {
        char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH];
        u8 encap_size;
  };
  
  static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage);
 -#endif
  
  static void nf_bridge_info_free(struct sk_buff *skb)
  {
@@@ -664,6 -666,7 +664,6 @@@ static unsigned int br_nf_forward_arp(v
        return NF_STOLEN;
  }
  
 -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) || IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
  static int br_nf_push_frag_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
  {
        struct brnf_frag_data *data;
        nf_bridge_info_free(skb);
        return br_dev_queue_push_xmit(net, sk, skb);
  }
- static int br_nf_push_frag_xmit_sk(struct sock *sk, struct sk_buff *skb)
- {
-       struct net *net = dev_net(skb_dst(skb)->dev);
-       return br_nf_push_frag_xmit(net, sk, skb);
- }
 -#endif
  
 -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
  static int
  br_nf_ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
-                 int (*output)(struct sock *, struct sk_buff *))
+                 int (*output)(struct net *, struct sock *, struct sk_buff *))
  {
        unsigned int mtu = ip_skb_dst_mtu(skb);
        struct iphdr *iph = ip_hdr(skb);
                return -EMSGSIZE;
        }
  
-       return ip_do_fragment(sk, skb, output);
+       return ip_do_fragment(net, sk, skb, output);
  }
 -#endif
  
  static unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
  {
@@@ -733,11 -734,11 +728,11 @@@ static int br_nf_dev_queue_xmit(struct 
  
        nf_bridge = nf_bridge_info_get(skb);
  
 -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
        /* This is wrong! We should preserve the original fragment
         * boundaries by preserving frag_list rather than refragmenting.
         */
 -      if (skb->protocol == htons(ETH_P_IP)) {
 +      if (IS_ENABLED(CONFIG_NF_DEFRAG_IPV4) &&
 +          skb->protocol == htons(ETH_P_IP)) {
                struct brnf_frag_data *data;
  
                if (br_validate_ipv4(net, skb))
                skb_copy_from_linear_data_offset(skb, -data->size, data->mac,
                                                 data->size);
  
-               return br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit_sk);
+               return br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit);
        }
 -#endif
 -#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
 -      if (skb->protocol == htons(ETH_P_IPV6)) {
 +      if (IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) &&
 +          skb->protocol == htons(ETH_P_IPV6)) {
                const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
                struct brnf_frag_data *data;
  
                                                 data->size);
  
                if (v6ops)
-                       return v6ops->fragment(sk, skb, br_nf_push_frag_xmit_sk);
+                       return v6ops->fragment(net, sk, skb, br_nf_push_frag_xmit);
  
                kfree_skb(skb);
                return -EMSGSIZE;
        }
 -#endif
        nf_bridge_info_free(skb);
        return br_dev_queue_push_xmit(net, sk, skb);
   drop:
@@@ -901,42 -904,49 +896,42 @@@ EXPORT_SYMBOL_GPL(br_netfilter_enable)
  static struct nf_hook_ops br_nf_ops[] __read_mostly = {
        {
                .hook = br_nf_pre_routing,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_BRIDGE,
                .hooknum = NF_BR_PRE_ROUTING,
                .priority = NF_BR_PRI_BRNF,
        },
        {
                .hook = br_nf_local_in,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_BRIDGE,
                .hooknum = NF_BR_LOCAL_IN,
                .priority = NF_BR_PRI_BRNF,
        },
        {
                .hook = br_nf_forward_ip,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_BRIDGE,
                .hooknum = NF_BR_FORWARD,
                .priority = NF_BR_PRI_BRNF - 1,
        },
        {
                .hook = br_nf_forward_arp,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_BRIDGE,
                .hooknum = NF_BR_FORWARD,
                .priority = NF_BR_PRI_BRNF,
        },
        {
                .hook = br_nf_post_routing,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_BRIDGE,
                .hooknum = NF_BR_POST_ROUTING,
                .priority = NF_BR_PRI_LAST,
        },
        {
                .hook = ip_sabotage_in,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_IPV4,
                .hooknum = NF_INET_PRE_ROUTING,
                .priority = NF_IP_PRI_FIRST,
        },
        {
                .hook = ip_sabotage_in,
 -              .owner = THIS_MODULE,
                .pf = NFPROTO_IPV6,
                .hooknum = NF_INET_PRE_ROUTING,
                .priority = NF_IP6_PRI_FIRST,
diff --combined net/decnet/dn_route.c
index 0c491fc0e254d5be8a0d9655ed44b23aee6e9a43,27fce283117babac70b4be2ca77c82eef5badf0c..607a14f20d88011e6de8540b21a69e6527d49df0
@@@ -744,7 -744,7 +744,7 @@@ out
        return NET_RX_DROP;
  }
  
- static int dn_output(struct sock *sk, struct sk_buff *skb)
+ static int dn_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  {
        struct dst_entry *dst = skb_dst(skb);
        struct dn_route *rt = (struct dn_route *)dst;
@@@ -789,7 -789,9 +789,7 @@@ static int dn_forward(struct sk_buff *s
        struct dn_dev *dn_db = rcu_dereference(dst->dev->dn_ptr);
        struct dn_route *rt;
        int header_len;
 -#ifdef CONFIG_NETFILTER
        struct net_device *dev = skb->dev;
 -#endif
  
        if (skb->pkt_type != PACKET_HOST)
                goto drop;
@@@ -830,7 -832,7 +830,7 @@@ drop
   * Used to catch bugs. This should never normally get
   * called.
   */
- static int dn_rt_bug_sk(struct sock *sk, struct sk_buff *skb)
+ static int dn_rt_bug_out(struct net *net, struct sock *sk, struct sk_buff *skb)
  {
        struct dn_skb_cb *cb = DN_SKB_CB(skb);
  
@@@ -1467,7 -1469,7 +1467,7 @@@ make_route
  
        rt->n = neigh;
        rt->dst.lastuse = jiffies;
-       rt->dst.output = dn_rt_bug_sk;
+       rt->dst.output = dn_rt_bug_out;
        switch (res.type) {
        case RTN_UNICAST:
                rt->dst.input = dn_forward;
index a1058363d2e93d0723c894b13b7ea73c7d61056d,f1a8df8ecc1f344d58aa834fb7230b12e0fa1bc2..5fdc556514bac3335f0c4f78b2c01c54f1c8b68f
@@@ -63,7 -63,7 +63,7 @@@ synproxy_send_tcp(const struct synproxy
                nf_conntrack_get(nfct);
        }
  
-       ip_local_out(nskb);
+       ip_local_out(net, nskb->sk, nskb);
        return;
  
  free_nskb:
@@@ -231,7 -231,7 +231,7 @@@ synproxy_send_client_ack(const struct s
        synproxy_build_options(nth, opts);
  
        synproxy_send_tcp(snet, skb, nskb, skb->nfct, IP_CT_ESTABLISHED_REPLY,
 -                        niph, nth, tcp_hdr_size);
 +                        niph, nth, tcp_hdr_size);
  }
  
  static bool
@@@ -437,12 -437,14 +437,12 @@@ static struct xt_target synproxy_tg4_re
  static struct nf_hook_ops ipv4_synproxy_ops[] __read_mostly = {
        {
                .hook           = ipv4_synproxy_hook,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
        },
        {
                .hook           = ipv4_synproxy_hook,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_POST_ROUTING,
                .priority       = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
index 9df3f93269d3300b01e1d5b77ee891ab52897d5d,bf25f45b23d24305bfa8a22f4bb5946153052221..0e5591c2ee9f6d66acb47ce2cbbf31403dc286f7
  #endif
  #include <net/netfilter/nf_conntrack_zones.h>
  
- static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
+ static int nf_ct_ipv4_gather_frags(struct net *net, struct sk_buff *skb,
+                                  u_int32_t user)
  {
        int err;
  
        skb_orphan(skb);
  
        local_bh_disable();
-       err = ip_defrag(skb, user);
+       err = ip_defrag(net, skb, user);
        local_bh_enable();
  
        if (!err) {
@@@ -85,7 -86,7 +86,7 @@@ static unsigned int ipv4_conntrack_defr
                enum ip_defrag_users user =
                        nf_ct_defrag_user(state->hook, skb);
  
-               if (nf_ct_ipv4_gather_frags(skb, user))
+               if (nf_ct_ipv4_gather_frags(state->net, skb, user))
                        return NF_STOLEN;
        }
        return NF_ACCEPT;
  static struct nf_hook_ops ipv4_defrag_ops[] = {
        {
                .hook           = ipv4_conntrack_defrag,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_PRE_ROUTING,
                .priority       = NF_IP_PRI_CONNTRACK_DEFRAG,
        },
        {
                .hook           = ipv4_conntrack_defrag,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_CONNTRACK_DEFRAG,
index 3426d9df1be7b3d1f09218916c0a209ec37f28d7,a10a2a9e9f94129e2d4a92b0c58012eb346485b3..3deed5860a42510078a2377260819aa269d0bc47
@@@ -76,7 -76,7 +76,7 @@@ synproxy_send_tcp(const struct synproxy
                nf_conntrack_get(nfct);
        }
  
-       ip6_local_out(nskb);
+       ip6_local_out(net, nskb->sk, nskb);
        return;
  
  free_nskb:
@@@ -244,7 -244,7 +244,7 @@@ synproxy_send_client_ack(const struct s
        synproxy_build_options(nth, opts);
  
        synproxy_send_tcp(snet, skb, nskb, skb->nfct, IP_CT_ESTABLISHED_REPLY,
 -                        niph, nth, tcp_hdr_size);
 +                        niph, nth, tcp_hdr_size);
  }
  
  static bool
@@@ -458,12 -458,14 +458,12 @@@ static struct xt_target synproxy_tg6_re
  static struct nf_hook_ops ipv6_synproxy_ops[] __read_mostly = {
        {
                .hook           = ipv6_synproxy_hook,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
        },
        {
                .hook           = ipv6_synproxy_hook,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_POST_ROUTING,
                .priority       = NF_IP_PRI_CONNTRACK_CONFIRM - 1,
index deab0a1608d69e0fb3a0aad65cc2c6bc81543ab5,2fb86a99bf5f1325cb97e1bd75c5870b38f64116..056f5d4a852aa1d8014c439378e2b2281b3622e4
@@@ -59,7 -59,7 +59,7 @@@ struct nf_ct_frag6_skb_c
        struct sk_buff          *orig;
  };
  
 -#define NFCT_FRAG6_CB(skb)    ((struct nf_ct_frag6_skb_cb*)((skb)->cb))
 +#define NFCT_FRAG6_CB(skb)    ((struct nf_ct_frag6_skb_cb *)((skb)->cb))
  
  static struct inet_frags nf_frags;
  
@@@ -445,7 -445,7 +445,7 @@@ nf_ct_frag6_reasm(struct frag_queue *fq
        skb_reset_transport_header(head);
        skb_push(head, head->data - skb_network_header(head));
  
 -      for (fp=head->next; fp; fp = fp->next) {
 +      for (fp = head->next; fp; fp = fp->next) {
                head->data_len += fp->len;
                head->len += fp->len;
                if (head->ip_summed != fp->ip_summed)
@@@ -563,12 -563,10 +563,10 @@@ find_prev_fhdr(struct sk_buff *skb, u8 
        return 0;
  }
  
- struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user)
+ struct sk_buff *nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)
  {
        struct sk_buff *clone;
        struct net_device *dev = skb->dev;
-       struct net *net = skb_dst(skb) ? dev_net(skb_dst(skb)->dev)
-                                      : dev_net(skb->dev);
        struct frag_hdr *fhdr;
        struct frag_queue *fq;
        struct ipv6hdr *hdr;
index b6ddca7461091c172cf9adbbcd3140311725bcea,5173a89a238ef37e2862b7e91abafb84700fc191..4fdbed5ebfb6bbe92136fc545533914a40be7a2a
@@@ -63,7 -63,8 +63,8 @@@ static unsigned int ipv6_defrag(void *p
                return NF_ACCEPT;
  #endif
  
-       reasm = nf_ct_frag6_gather(skb, nf_ct6_defrag_user(state->hook, skb));
+       reasm = nf_ct_frag6_gather(state->net, skb,
+                                  nf_ct6_defrag_user(state->hook, skb));
        /* queued */
        if (reasm == NULL)
                return NF_STOLEN;
  static struct nf_hook_ops ipv6_defrag_ops[] = {
        {
                .hook           = ipv6_defrag,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_PRE_ROUTING,
                .priority       = NF_IP6_PRI_CONNTRACK_DEFRAG,
        },
        {
                .hook           = ipv6_defrag,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_CONNTRACK_DEFRAG,
index 5629db84c047a27fe92c55b10c47c52e3ee6ed73,7309e475f68b405d040e53069b123663914ffd7b..e0f922b777e3d9333ca4723e422182d083c6afba
@@@ -26,7 -26,7 +26,7 @@@ const struct tcphdr *nf_reject_ip6_tcph
        int tcphoff;
  
        proto = oip6h->nexthdr;
 -      tcphoff = ipv6_skip_exthdr(oldskb, ((u8*)(oip6h+1) - oldskb->data),
 +      tcphoff = ipv6_skip_exthdr(oldskb, ((u8 *)(oip6h + 1) - oldskb->data),
                                   &proto, &frag_off);
  
        if ((tcphoff < 0) || (tcphoff > oldskb->len)) {
@@@ -206,7 -206,7 +206,7 @@@ void nf_send_reset6(struct net *net, st
                dev_queue_xmit(nskb);
        } else
  #endif
-               ip6_local_out(nskb);
+               ip6_local_out(net, nskb->sk, nskb);
  }
  EXPORT_SYMBOL_GPL(nf_send_reset6);
  
@@@ -224,7 -224,7 +224,7 @@@ static bool reject6_csum_ok(struct sk_b
                return true;
  
        proto = ip6h->nexthdr;
 -      thoff = ipv6_skip_exthdr(skb, ((u8*)(ip6h+1) - skb->data), &proto, &fo);
 +      thoff = ipv6_skip_exthdr(skb, ((u8 *)(ip6h + 1) - skb->data), &proto, &fo);
  
        if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
                return false;
index ce37d204fcf12cfc9cf767ba4a87b3684b0e1e24,07a791ecdfbab9fee7f6c78bcc53a6f9204cbe90..1e24fff53e4b5eef8fab776b2e3dc93a3ae4545c
@@@ -547,6 -547,7 +547,6 @@@ ip_vs_schedule(struct ip_vs_service *sv
        return cp;
  }
  
 -#ifdef CONFIG_SYSCTL
  static inline int ip_vs_addr_is_unicast(struct net *net, int af,
                                        union nf_inet_addr *addr)
  {
  #endif
        return (inet_addr_type(net, addr->ip) == RTN_UNICAST);
  }
 -#endif
  
  /*
   *  Pass or drop the packet.
@@@ -692,7 -694,7 +692,7 @@@ static inline int ip_vs_gather_frags(st
        int err;
  
        local_bh_disable();
-       err = ip_defrag(skb, user);
+       err = ip_defrag(ipvs->net, skb, user);
        local_bh_enable();
        if (!err)
                ip_send_check(ip_hdr(skb));
@@@ -1172,6 -1174,7 +1172,6 @@@ drop
  static unsigned int
  ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int af)
  {
 -      struct net *net = ipvs->net;
        struct ip_vs_iphdr iph;
        struct ip_vs_protocol *pp;
        struct ip_vs_proto_data *pd;
  #ifdef CONFIG_IP_VS_IPV6
                                if (af == AF_INET6) {
                                        if (!skb->dev)
 -                                              skb->dev = net->loopback_dev;
 +                                              skb->dev = ipvs->net->loopback_dev;
                                        icmpv6_send(skb,
                                                    ICMPV6_DEST_UNREACH,
                                                    ICMPV6_PORT_UNREACH,
@@@ -1923,6 -1926,7 +1923,6 @@@ static struct nf_hook_ops ip_vs_ops[] _
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply4,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_NAT_SRC - 2,
         * applied to IPVS. */
        {
                .hook           = ip_vs_remote_request4,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP_PRI_NAT_SRC - 1,
        /* Before ip_vs_in, change source only for VS/NAT */
        {
                .hook           = ip_vs_local_reply4,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_NAT_DST + 1,
        /* After mangle, schedule and forward local requests */
        {
                .hook           = ip_vs_local_request4,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP_PRI_NAT_DST + 2,
         * destined for 0.0.0.0/0, which is for incoming IPVS connections */
        {
                .hook           = ip_vs_forward_icmp,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 99,
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply4,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV4,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 100,
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_NAT_SRC - 2,
         * applied to IPVS. */
        {
                .hook           = ip_vs_remote_request6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_IN,
                .priority       = NF_IP6_PRI_NAT_SRC - 1,
        /* Before ip_vs_in, change source only for VS/NAT */
        {
                .hook           = ip_vs_local_reply6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_NAT_DST + 1,
        /* After mangle, schedule and forward local requests */
        {
                .hook           = ip_vs_local_request6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_LOCAL_OUT,
                .priority       = NF_IP6_PRI_NAT_DST + 2,
         * destined for 0.0.0.0/0, which is for incoming IPVS connections */
        {
                .hook           = ip_vs_forward_icmp_v6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 99,
        /* After packet filtering, change source only for VS/NAT */
        {
                .hook           = ip_vs_reply6,
 -              .owner          = THIS_MODULE,
                .pf             = NFPROTO_IPV6,
                .hooknum        = NF_INET_FORWARD,
                .priority       = 100,
index a5b9680a1821c28868e3b022a0686b72c6e7b724,cc2300f4e177136c96763a06c90e19614e79e2f7..06eb48fceb42e4c31dba2d91c0d182bfc82e5b19
@@@ -27,7 -27,6 +27,7 @@@
  #include <net/netlink.h>
  #include <linux/netfilter/nfnetlink.h>
  #include <linux/netfilter/nfnetlink_log.h>
 +#include <linux/netfilter/nf_conntrack_common.h>
  #include <linux/spinlock.h>
  #include <linux/sysctl.h>
  #include <linux/proc_fs.h>
@@@ -402,9 -401,7 +402,9 @@@ __build_packet_message(struct nfnl_log_
                        unsigned int hooknum,
                        const struct net_device *indev,
                        const struct net_device *outdev,
 -                      const char *prefix, unsigned int plen)
 +                      const char *prefix, unsigned int plen,
 +                      const struct nfnl_ct_hook *nfnl_ct,
 +                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  {
        struct nfulnl_msg_packet_hdr pmsg;
        struct nlmsghdr *nlh;
  
        if (skb->tstamp.tv64) {
                struct nfulnl_msg_packet_timestamp ts;
-               struct timeval tv = ktime_to_timeval(skb->tstamp);
-               ts.sec = cpu_to_be64(tv.tv_sec);
-               ts.usec = cpu_to_be64(tv.tv_usec);
+               struct timespec64 kts = ktime_to_timespec64(skb->tstamp);
+               ts.sec = cpu_to_be64(kts.tv_sec);
+               ts.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC);
  
                if (nla_put(inst->skb, NFULA_TIMESTAMP, sizeof(ts), &ts))
                        goto nla_put_failure;
                         htonl(atomic_inc_return(&log->global_seq))))
                goto nla_put_failure;
  
 +      if (ct && nfnl_ct->build(inst->skb, ct, ctinfo,
 +                               NFULA_CT, NFULA_CT_INFO) < 0)
 +              goto nla_put_failure;
 +
        if (data_len) {
                struct nlattr *nla;
                int size = nla_attr_size(data_len);
@@@ -627,16 -620,12 +627,16 @@@ nfulnl_log_packet(struct net *net
                  const struct nf_loginfo *li_user,
                  const char *prefix)
  {
 -      unsigned int size, data_len;
 +      size_t size;
 +      unsigned int data_len;
        struct nfulnl_instance *inst;
        const struct nf_loginfo *li;
        unsigned int qthreshold;
        unsigned int plen;
        struct nfnl_log_net *log = nfnl_log_pernet(net);
 +      const struct nfnl_ct_hook *nfnl_ct = NULL;
 +      struct nf_conn *ct = NULL;
 +      enum ip_conntrack_info uninitialized_var(ctinfo);
  
        if (li_user && li_user->type == NF_LOG_TYPE_ULOG)
                li = li_user;
                size += nla_total_size(sizeof(u_int32_t));
        if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
                size += nla_total_size(sizeof(u_int32_t));
 +      if (inst->flags & NFULNL_CFG_F_CONNTRACK) {
 +              nfnl_ct = rcu_dereference(nfnl_ct_hook);
 +              if (nfnl_ct != NULL) {
 +                      ct = nfnl_ct->get_ct(skb, &ctinfo);
 +                      if (ct != NULL)
 +                              size += nfnl_ct->build_size(ct);
 +              }
 +      }
  
        qthreshold = inst->qthreshold;
        /* per-rule qthreshold overrides per-instance */
        inst->qlen++;
  
        __build_packet_message(log, inst, skb, data_len, pf,
 -                              hooknum, in, out, prefix, plen);
 +                              hooknum, in, out, prefix, plen,
 +                              nfnl_ct, ct, ctinfo);
  
        if (inst->qlen >= qthreshold)
                __nfulnl_flush(inst);
@@@ -825,7 -805,6 +825,7 @@@ nfulnl_recv_config(struct sock *ctnl, s
        struct net *net = sock_net(ctnl);
        struct nfnl_log_net *log = nfnl_log_pernet(net);
        int ret = 0;
 +      u16 flags;
  
        if (nfula[NFULA_CFG_CMD]) {
                u_int8_t pf = nfmsg->nfgen_family;
                goto out_put;
        }
  
 +      /* Check if we support these flags in first place, dependencies should
 +       * be there too not to break atomicity.
 +       */
 +      if (nfula[NFULA_CFG_FLAGS]) {
 +              flags = ntohs(nla_get_be16(nfula[NFULA_CFG_FLAGS]));
 +
 +              if ((flags & NFULNL_CFG_F_CONNTRACK) &&
 +                  !rcu_access_pointer(nfnl_ct_hook)) {
 +#ifdef CONFIG_MODULES
 +                      nfnl_unlock(NFNL_SUBSYS_ULOG);
 +                      request_module("ip_conntrack_netlink");
 +                      nfnl_lock(NFNL_SUBSYS_ULOG);
 +                      if (rcu_access_pointer(nfnl_ct_hook)) {
 +                              ret = -EAGAIN;
 +                              goto out_put;
 +                      }
 +#endif
 +                      ret = -EOPNOTSUPP;
 +                      goto out_put;
 +              }
 +      }
 +
        if (cmd != NULL) {
                switch (cmd->command) {
                case NFULNL_CFG_CMD_BIND:
                        ret = -ENOTSUPP;
                        break;
                }
 +      } else if (!inst) {
 +              ret = -ENODEV;
 +              goto out;
        }
  
        if (nfula[NFULA_CFG_MODE]) {
 -              struct nfulnl_msg_config_mode *params;
 -              params = nla_data(nfula[NFULA_CFG_MODE]);
 +              struct nfulnl_msg_config_mode *params =
 +                      nla_data(nfula[NFULA_CFG_MODE]);
  
 -              if (!inst) {
 -                      ret = -ENODEV;
 -                      goto out;
 -              }
                nfulnl_set_mode(inst, params->copy_mode,
                                ntohl(params->copy_range));
        }
        if (nfula[NFULA_CFG_TIMEOUT]) {
                __be32 timeout = nla_get_be32(nfula[NFULA_CFG_TIMEOUT]);
  
 -              if (!inst) {
 -                      ret = -ENODEV;
 -                      goto out;
 -              }
                nfulnl_set_timeout(inst, ntohl(timeout));
        }
  
        if (nfula[NFULA_CFG_NLBUFSIZ]) {
                __be32 nlbufsiz = nla_get_be32(nfula[NFULA_CFG_NLBUFSIZ]);
  
 -              if (!inst) {
 -                      ret = -ENODEV;
 -                      goto out;
 -              }
                nfulnl_set_nlbufsiz(inst, ntohl(nlbufsiz));
        }
  
        if (nfula[NFULA_CFG_QTHRESH]) {
                __be32 qthresh = nla_get_be32(nfula[NFULA_CFG_QTHRESH]);
  
 -              if (!inst) {
 -                      ret = -ENODEV;
 -                      goto out;
 -              }
                nfulnl_set_qthresh(inst, ntohl(qthresh));
        }
  
 -      if (nfula[NFULA_CFG_FLAGS]) {
 -              __be16 flags = nla_get_be16(nfula[NFULA_CFG_FLAGS]);
 -
 -              if (!inst) {
 -                      ret = -ENODEV;
 -                      goto out;
 -              }
 -              nfulnl_set_flags(inst, ntohs(flags));
 -      }
 +      if (nfula[NFULA_CFG_FLAGS])
 +              nfulnl_set_flags(inst, flags);
  
  out_put:
        instance_put(inst);
diff --combined security/selinux/hooks.c
index 659bb50f0232641685d5da0a104d04b40ce9ee7a,6e50841ef1f63355ead908559fbfe4793095601f..26f4039d54b8f6bd8dd0aba99837835ba13c871b
@@@ -4898,7 -4898,7 +4898,7 @@@ static unsigned int selinux_ip_output(s
        if (sk) {
                struct sk_security_struct *sksec;
  
-               if (sk->sk_state == TCP_LISTEN)
+               if (sk_listener(sk))
                        /* if the socket is the listening state then this
                         * packet is a SYN-ACK packet which means it needs to
                         * be labeled based on the connection/request_sock and
@@@ -5005,7 -5005,7 +5005,7 @@@ static unsigned int selinux_ip_postrout
         *       unfortunately, this means more work, but it is only once per
         *       connection. */
        if (skb_dst(skb) != NULL && skb_dst(skb)->xfrm != NULL &&
-           !(sk != NULL && sk->sk_state == TCP_LISTEN))
+           !(sk && sk_listener(sk)))
                return NF_ACCEPT;
  #endif
  
                        secmark_perm = PACKET__SEND;
                        peer_sid = SECINITSID_KERNEL;
                }
-       } else if (sk->sk_state == TCP_LISTEN) {
+       } else if (sk_listener(sk)) {
                /* Locally generated packet but the associated socket is in the
                 * listening state which means this is a SYN-ACK packet.  In
                 * this particular case the correct security label is assigned
                 * selinux_inet_conn_request().  See also selinux_ip_output()
                 * for similar problems. */
                u32 skb_sid;
-               struct sk_security_struct *sksec = sk->sk_security;
+               struct sk_security_struct *sksec;
+               if (sk->sk_state == TCP_NEW_SYN_RECV)
+                       sk = inet_reqsk(sk)->rsk_listener;
+               sksec = sk->sk_security;
                if (selinux_skb_peerlbl_sid(skb, family, &skb_sid))
                        return NF_DROP;
                /* At this point, if the returned skb peerlbl is SECSID_NULL
@@@ -6127,18 -6131,21 +6131,18 @@@ security_initcall(selinux_init)
  static struct nf_hook_ops selinux_nf_ops[] = {
        {
                .hook =         selinux_ipv4_postroute,
 -              .owner =        THIS_MODULE,
                .pf =           NFPROTO_IPV4,
                .hooknum =      NF_INET_POST_ROUTING,
                .priority =     NF_IP_PRI_SELINUX_LAST,
        },
        {
                .hook =         selinux_ipv4_forward,
 -              .owner =        THIS_MODULE,
                .pf =           NFPROTO_IPV4,
                .hooknum =      NF_INET_FORWARD,
                .priority =     NF_IP_PRI_SELINUX_FIRST,
        },
        {
                .hook =         selinux_ipv4_output,
 -              .owner =        THIS_MODULE,
                .pf =           NFPROTO_IPV4,
                .hooknum =      NF_INET_LOCAL_OUT,
                .priority =     NF_IP_PRI_SELINUX_FIRST,
  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
        {
                .hook =         selinux_ipv6_postroute,
 -              .owner =        THIS_MODULE,
                .pf =           NFPROTO_IPV6,
                .hooknum =      NF_INET_POST_ROUTING,
                .priority =     NF_IP6_PRI_SELINUX_LAST,
        },
        {
                .hook =         selinux_ipv6_forward,
 -              .owner =        THIS_MODULE,
                .pf =           NFPROTO_IPV6,
                .hooknum =      NF_INET_FORWARD,
                .priority =     NF_IP6_PRI_SELINUX_FIRST,