History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf

Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net: 1) Set VLAN tag in tcp reset/icmp unreachable packets to reject connections in the bridge family, from Michael Braun. 2) Incorrect subcounter flag update in ipset, from Phil Sutter. 3) Possible buffer overflow in the pptp conntrack helper, based on patch from Dan Carpenter. 4) Restore userspace conntrack helper hook logic that broke after hook consolidation rework. 5) Unbreak userspace conntrack helper registration via nfnetlink_cthelper. ====================

David S. Miller committed 6 years ago

Commit 963bdfc2 parents 1a6da4f 703acd77 files · +119 −41Browse files

Unified · Split

7 files
  1. include/linux/netfilter/nf_conntrack_pptp.h +1 −1
  2. net/bridge/netfilter/nft_reject_bridge.c +6 −0
  3. net/ipv4/netfilter/nf_nat_pptp.c +2 −5
  4. net/netfilter/ipset/ip_set_list_set.c +1 −1
  5. net/netfilter/nf_conntrack_core.c +72 −6
  6. net/netfilter/nf_conntrack_pptp.c +35 −27
  7. net/netfilter/nfnetlink_cthelper.c +2 −1
include/linux/netfilter/nf_conntrack_pptp.h+1−1
@@ -10,7 +10,7 @@ · 9 unmodified lines
10#include <net/netfilter/nf_conntrack_expect.h>10#include <net/netfilter/nf_conntrack_expect.h>
11#include <uapi/linux/netfilter/nf_conntrack_tuple_common.h>11#include <uapi/linux/netfilter/nf_conntrack_tuple_common.h>
12 12
13extern const char *const pptp_msg_name[];13extern const char *const pptp_msg_name(u_int16_t msg);
14 14
15/* state of the control session */15/* state of the control session */
16enum pptp_ctrlsess_state {16enum pptp_ctrlsess_state {
net/bridge/netfilter/nft_reject_bridge.c+6−0
@@ -31,6 +31,12 @@ static void nft_reject_br_push_etherhdr(struct sk_buff *oldskb, · 30 unmodified lines
31 ether_addr_copy(eth->h_dest, eth_hdr(oldskb)->h_source);31 ether_addr_copy(eth->h_dest, eth_hdr(oldskb)->h_source);
32 eth->h_proto = eth_hdr(oldskb)->h_proto;32 eth->h_proto = eth_hdr(oldskb)->h_proto;
33 skb_pull(nskb, ETH_HLEN);33 skb_pull(nskb, ETH_HLEN);
34
35 if (skb_vlan_tag_present(oldskb)) {
36 u16 vid = skb_vlan_tag_get(oldskb);
37
38 __vlan_hwaccel_put_tag(nskb, oldskb->vlan_proto, vid);
39 }
34}40}
35 41
36static int nft_bridge_iphdr_validate(struct sk_buff *skb)42static int nft_bridge_iphdr_validate(struct sk_buff *skb)
net/ipv4/netfilter/nf_nat_pptp.c+2−5
@@ -166,8 +166,7 @@ pptp_outbound_pkt(struct sk_buff *skb, · 165 unmodified lines
166 break;166 break;
167 default:167 default:
168 pr_debug("unknown outbound packet 0x%04x:%s\n", msg,168 pr_debug("unknown outbound packet 0x%04x:%s\n", msg,
169 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] :169 pptp_msg_name(msg));
170 pptp_msg_name[0]);
171 fallthrough;170 fallthrough;
172 case PPTP_SET_LINK_INFO:171 case PPTP_SET_LINK_INFO:
173 /* only need to NAT in case PAC is behind NAT box */172 /* only need to NAT in case PAC is behind NAT box */
@@ -268,9 +267,7 @@ pptp_inbound_pkt(struct sk_buff *skb, · 94 unmodified lines
268 pcid_off = offsetof(union pptp_ctrl_union, setlink.peersCallID);267 pcid_off = offsetof(union pptp_ctrl_union, setlink.peersCallID);
269 break;268 break;
270 default:269 default:
271 pr_debug("unknown inbound packet %s\n",270 pr_debug("unknown inbound packet %s\n", pptp_msg_name(msg));
272 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] :
273 pptp_msg_name[0]);
274 fallthrough;271 fallthrough;
275 case PPTP_START_SESSION_REQUEST:272 case PPTP_START_SESSION_REQUEST:
276 case PPTP_START_SESSION_REPLY:273 case PPTP_START_SESSION_REPLY:
net/netfilter/ipset/ip_set_list_set.c+1−1
@@ -59,7 +59,7 @@ list_set_ktest(struct ip_set *set, const struct sk_buff *skb, · 58 unmodified lines
59 /* Don't lookup sub-counters at all */59 /* Don't lookup sub-counters at all */
60 opt->cmdflags &= ~IPSET_FLAG_MATCH_COUNTERS;60 opt->cmdflags &= ~IPSET_FLAG_MATCH_COUNTERS;
61 if (opt->cmdflags & IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE)61 if (opt->cmdflags & IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE)
62 opt->cmdflags &= ~IPSET_FLAG_SKIP_COUNTER_UPDATE;62 opt->cmdflags |= IPSET_FLAG_SKIP_COUNTER_UPDATE;
63 list_for_each_entry_rcu(e, &map->members, list) {63 list_for_each_entry_rcu(e, &map->members, list) {
64 ret = ip_set_test(e->id, skb, par, opt);64 ret = ip_set_test(e->id, skb, par, opt);
65 if (ret <= 0)65 if (ret <= 0)
net/netfilter/nf_conntrack_core.c+72−6
@@ -2016,22 +2016,18 @@ static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb) · 2015 unmodified lines
2016 nf_conntrack_get(skb_nfct(nskb));2016 nf_conntrack_get(skb_nfct(nskb));
2017}2017}
2018 2018
2019static int nf_conntrack_update(struct net *net, struct sk_buff *skb)2019static int __nf_conntrack_update(struct net *net, struct sk_buff *skb,
2020 struct nf_conn *ct)
2020{2021{
2021 struct nf_conntrack_tuple_hash *h;2022 struct nf_conntrack_tuple_hash *h;
2022 struct nf_conntrack_tuple tuple;2023 struct nf_conntrack_tuple tuple;
2023 enum ip_conntrack_info ctinfo;2024 enum ip_conntrack_info ctinfo;
2024 struct nf_nat_hook *nat_hook;2025 struct nf_nat_hook *nat_hook;
2025 unsigned int status;2026 unsigned int status;
2026 struct nf_conn *ct;
2027 int dataoff;2027 int dataoff;
2028 u16 l3num;2028 u16 l3num;
2029 u8 l4num;2029 u8 l4num;
2030 2030
2031 ct = nf_ct_get(skb, &ctinfo);
2032 if (!ct || nf_ct_is_confirmed(ct))
2033 return 0;
2034
2035 l3num = nf_ct_l3num(ct);2031 l3num = nf_ct_l3num(ct);
2036 2032
2037 dataoff = get_l4proto(skb, skb_network_offset(skb), l3num, &l4num);2033 dataoff = get_l4proto(skb, skb_network_offset(skb), l3num, &l4num);
@@ -2088,6 +2084,76 @@ static int nf_conntrack_update(struct net *net, struct sk_buff *skb) · 50 unmodified lines
2088 return 0;2084 return 0;
2089}2085}
2090 2086
2087/* This packet is coming from userspace via nf_queue, complete the packet
2088 * processing after the helper invocation in nf_confirm().
2089 */
2090static int nf_confirm_cthelper(struct sk_buff *skb, struct nf_conn *ct,
2091 enum ip_conntrack_info ctinfo)
2092{
2093 const struct nf_conntrack_helper *helper;
2094 const struct nf_conn_help *help;
2095 unsigned int protoff;
2096
2097 help = nfct_help(ct);
2098 if (!help)
2099 return 0;
2100
2101 helper = rcu_dereference(help->helper);
2102 if (!(helper->flags & NF_CT_HELPER_F_USERSPACE))
2103 return 0;
2104
2105 switch (nf_ct_l3num(ct)) {
2106 case NFPROTO_IPV4:
2107 protoff = skb_network_offset(skb) + ip_hdrlen(skb);
2108 break;
2109#if IS_ENABLED(CONFIG_IPV6)
2110 case NFPROTO_IPV6: {
2111 __be16 frag_off;
2112 u8 pnum;
2113
2114 pnum = ipv6_hdr(skb)->nexthdr;
2115 protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &pnum,
2116 &frag_off);
2117 if (protoff < 0 || (frag_off & htons(~0x7)) != 0)
2118 return 0;
2119 break;
2120 }
2121#endif
2122 default:
2123 return 0;
2124 }
2125
2126 if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
2127 !nf_is_loopback_packet(skb)) {
2128 if (!nf_ct_seq_adjust(skb, ct, ctinfo, protoff)) {
2129 NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
2130 return -1;
2131 }
2132 }
2133
2134 /* We've seen it coming out the other side: confirm it */
2135 return nf_conntrack_confirm(skb) == NF_DROP ? - 1 : 0;
2136}
2137
2138static int nf_conntrack_update(struct net *net, struct sk_buff *skb)
2139{
2140 enum ip_conntrack_info ctinfo;
2141 struct nf_conn *ct;
2142 int err;
2143
2144 ct = nf_ct_get(skb, &ctinfo);
2145 if (!ct)
2146 return 0;
2147
2148 if (!nf_ct_is_confirmed(ct)) {
2149 err = __nf_conntrack_update(net, skb, ct);
2150 if (err < 0)
2151 return err;
2152 }
2153
2154 return nf_confirm_cthelper(skb, ct, ctinfo);
2155}
2156
2091static bool nf_conntrack_get_tuple_skb(struct nf_conntrack_tuple *dst_tuple,2157static bool nf_conntrack_get_tuple_skb(struct nf_conntrack_tuple *dst_tuple,
2092 const struct sk_buff *skb)2158 const struct sk_buff *skb)
2093{2159{
net/netfilter/nf_conntrack_pptp.c+35−27
@@ -72,24 +72,32 @@ EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn); · 71 unmodified lines
72 72
73#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)73#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
74/* PptpControlMessageType names */74/* PptpControlMessageType names */
75const char *const pptp_msg_name[] = {75static const char *const pptp_msg_name_array[PPTP_MSG_MAX + 1] = {
76 "UNKNOWN_MESSAGE",76 [0] = "UNKNOWN_MESSAGE",
77 "START_SESSION_REQUEST",77 [PPTP_START_SESSION_REQUEST] = "START_SESSION_REQUEST",
78 "START_SESSION_REPLY",78 [PPTP_START_SESSION_REPLY] = "START_SESSION_REPLY",
79 "STOP_SESSION_REQUEST",79 [PPTP_STOP_SESSION_REQUEST] = "STOP_SESSION_REQUEST",
80 "STOP_SESSION_REPLY",80 [PPTP_STOP_SESSION_REPLY] = "STOP_SESSION_REPLY",
81 "ECHO_REQUEST",81 [PPTP_ECHO_REQUEST] = "ECHO_REQUEST",
82 "ECHO_REPLY",82 [PPTP_ECHO_REPLY] = "ECHO_REPLY",
83 "OUT_CALL_REQUEST",83 [PPTP_OUT_CALL_REQUEST] = "OUT_CALL_REQUEST",
84 "OUT_CALL_REPLY",84 [PPTP_OUT_CALL_REPLY] = "OUT_CALL_REPLY",
85 "IN_CALL_REQUEST",85 [PPTP_IN_CALL_REQUEST] = "IN_CALL_REQUEST",
86 "IN_CALL_REPLY",86 [PPTP_IN_CALL_REPLY] = "IN_CALL_REPLY",
87 "IN_CALL_CONNECT",87 [PPTP_IN_CALL_CONNECT] = "IN_CALL_CONNECT",
88 "CALL_CLEAR_REQUEST",88 [PPTP_CALL_CLEAR_REQUEST] = "CALL_CLEAR_REQUEST",
89 "CALL_DISCONNECT_NOTIFY",89 [PPTP_CALL_DISCONNECT_NOTIFY] = "CALL_DISCONNECT_NOTIFY",
90 "WAN_ERROR_NOTIFY",90 [PPTP_WAN_ERROR_NOTIFY] = "WAN_ERROR_NOTIFY",
91 "SET_LINK_INFO"91 [PPTP_SET_LINK_INFO] = "SET_LINK_INFO"
92};92};
93
94const char *const pptp_msg_name(u_int16_t msg)
95{
96 if (msg > PPTP_MSG_MAX)
97 return pptp_msg_name_array[0];
98
99 return pptp_msg_name_array[msg];
100}
93EXPORT_SYMBOL(pptp_msg_name);101EXPORT_SYMBOL(pptp_msg_name);
94#endif102#endif
95 103
@@ -276,7 +284,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 180 unmodified lines
276 typeof(nf_nat_pptp_hook_inbound) nf_nat_pptp_inbound;284 typeof(nf_nat_pptp_hook_inbound) nf_nat_pptp_inbound;
277 285
278 msg = ntohs(ctlh->messageType);286 msg = ntohs(ctlh->messageType);
279 pr_debug("inbound control message %s\n", pptp_msg_name[msg]);287 pr_debug("inbound control message %s\n", pptp_msg_name(msg));
280 288
281 switch (msg) {289 switch (msg) {
282 case PPTP_START_SESSION_REPLY:290 case PPTP_START_SESSION_REPLY:
@@ -311,7 +319,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 28 unmodified lines
311 pcid = pptpReq->ocack.peersCallID;319 pcid = pptpReq->ocack.peersCallID;
312 if (info->pns_call_id != pcid)320 if (info->pns_call_id != pcid)
313 goto invalid;321 goto invalid;
314 pr_debug("%s, CID=%X, PCID=%X\n", pptp_msg_name[msg],322 pr_debug("%s, CID=%X, PCID=%X\n", pptp_msg_name(msg),
315 ntohs(cid), ntohs(pcid));323 ntohs(cid), ntohs(pcid));
316 324
317 if (pptpReq->ocack.resultCode == PPTP_OUTCALL_CONNECT) {325 if (pptpReq->ocack.resultCode == PPTP_OUTCALL_CONNECT) {
@@ -328,7 +336,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 10 unmodified lines
328 goto invalid;336 goto invalid;
329 337
330 cid = pptpReq->icreq.callID;338 cid = pptpReq->icreq.callID;
331 pr_debug("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));339 pr_debug("%s, CID=%X\n", pptp_msg_name(msg), ntohs(cid));
332 info->cstate = PPTP_CALL_IN_REQ;340 info->cstate = PPTP_CALL_IN_REQ;
333 info->pac_call_id = cid;341 info->pac_call_id = cid;
334 break;342 break;
@@ -347,7 +355,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 12 unmodified lines
347 if (info->pns_call_id != pcid)355 if (info->pns_call_id != pcid)
348 goto invalid;356 goto invalid;
349 357
350 pr_debug("%s, PCID=%X\n", pptp_msg_name[msg], ntohs(pcid));358 pr_debug("%s, PCID=%X\n", pptp_msg_name(msg), ntohs(pcid));
351 info->cstate = PPTP_CALL_IN_CONF;359 info->cstate = PPTP_CALL_IN_CONF;
352 360
353 /* we expect a GRE connection from PAC to PNS */361 /* we expect a GRE connection from PAC to PNS */
@@ -357,7 +365,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 3 unmodified lines
357 case PPTP_CALL_DISCONNECT_NOTIFY:365 case PPTP_CALL_DISCONNECT_NOTIFY:
358 /* server confirms disconnect */366 /* server confirms disconnect */
359 cid = pptpReq->disc.callID;367 cid = pptpReq->disc.callID;
360 pr_debug("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));368 pr_debug("%s, CID=%X\n", pptp_msg_name(msg), ntohs(cid));
361 info->cstate = PPTP_CALL_NONE;369 info->cstate = PPTP_CALL_NONE;
362 370
363 /* untrack this call id, unexpect GRE packets */371 /* untrack this call id, unexpect GRE packets */
@@ -384,7 +392,7 @@ pptp_inbound_pkt(struct sk_buff *skb, unsigned int protoff, · 20 unmodified lines
384invalid:392invalid:
385 pr_debug("invalid %s: type=%d cid=%u pcid=%u "393 pr_debug("invalid %s: type=%d cid=%u pcid=%u "
386 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",394 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
387 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0],395 pptp_msg_name(msg),
388 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,396 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,
389 ntohs(info->pns_call_id), ntohs(info->pac_call_id));397 ntohs(info->pns_call_id), ntohs(info->pac_call_id));
390 return NF_ACCEPT;398 return NF_ACCEPT;
@@ -404,7 +412,7 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff, · 13 unmodified lines
404 typeof(nf_nat_pptp_hook_outbound) nf_nat_pptp_outbound;412 typeof(nf_nat_pptp_hook_outbound) nf_nat_pptp_outbound;
405 413
406 msg = ntohs(ctlh->messageType);414 msg = ntohs(ctlh->messageType);
407 pr_debug("outbound control message %s\n", pptp_msg_name[msg]);415 pr_debug("outbound control message %s\n", pptp_msg_name(msg));
408 416
409 switch (msg) {417 switch (msg) {
410 case PPTP_START_SESSION_REQUEST:418 case PPTP_START_SESSION_REQUEST:
@@ -426,7 +434,7 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff, · 15 unmodified lines
426 info->cstate = PPTP_CALL_OUT_REQ;434 info->cstate = PPTP_CALL_OUT_REQ;
427 /* track PNS call id */435 /* track PNS call id */
428 cid = pptpReq->ocreq.callID;436 cid = pptpReq->ocreq.callID;
429 pr_debug("%s, CID=%X\n", pptp_msg_name[msg], ntohs(cid));437 pr_debug("%s, CID=%X\n", pptp_msg_name(msg), ntohs(cid));
430 info->pns_call_id = cid;438 info->pns_call_id = cid;
431 break;439 break;
432 440
@@ -440,7 +448,7 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff, · 7 unmodified lines
440 pcid = pptpReq->icack.peersCallID;448 pcid = pptpReq->icack.peersCallID;
441 if (info->pac_call_id != pcid)449 if (info->pac_call_id != pcid)
442 goto invalid;450 goto invalid;
443 pr_debug("%s, CID=%X PCID=%X\n", pptp_msg_name[msg],451 pr_debug("%s, CID=%X PCID=%X\n", pptp_msg_name(msg),
444 ntohs(cid), ntohs(pcid));452 ntohs(cid), ntohs(pcid));
445 453
446 if (pptpReq->icack.resultCode == PPTP_INCALL_ACCEPT) {454 if (pptpReq->icack.resultCode == PPTP_INCALL_ACCEPT) {
@@ -480,7 +488,7 @@ pptp_outbound_pkt(struct sk_buff *skb, unsigned int protoff, · 33 unmodified lines
480invalid:488invalid:
481 pr_debug("invalid %s: type=%d cid=%u pcid=%u "489 pr_debug("invalid %s: type=%d cid=%u pcid=%u "
482 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",490 "cstate=%d sstate=%d pns_cid=%u pac_cid=%u\n",
483 msg <= PPTP_MSG_MAX ? pptp_msg_name[msg] : pptp_msg_name[0],491 pptp_msg_name(msg),
484 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,492 msg, ntohs(cid), ntohs(pcid), info->cstate, info->sstate,
485 ntohs(info->pns_call_id), ntohs(info->pac_call_id));493 ntohs(info->pns_call_id), ntohs(info->pac_call_id));
486 return NF_ACCEPT;494 return NF_ACCEPT;
net/netfilter/nfnetlink_cthelper.c+2−1
@@ -103,7 +103,7 @@ nfnl_cthelper_from_nlattr(struct nlattr *attr, struct nf_conn *ct) · 102 unmodified lines
103 if (help->helper->data_len == 0)103 if (help->helper->data_len == 0)
104 return -EINVAL;104 return -EINVAL;
105 105
106 nla_memcpy(help->data, nla_data(attr), sizeof(help->data));106 nla_memcpy(help->data, attr, sizeof(help->data));
107 return 0;107 return 0;
108}108}
109 109
@@ -240,6 +240,7 @@ nfnl_cthelper_create(const struct nlattr * const tb[], · 130 unmodified lines
240 ret = -ENOMEM;240 ret = -ENOMEM;
241 goto err2;241 goto err2;
242 }242 }
243 helper->data_len = size;
243 244
244 helper->flags |= NF_CT_HELPER_F_USERSPACE;245 helper->flags |= NF_CT_HELPER_F_USERSPACE;
245 memcpy(&helper->tuple, tuple, sizeof(struct nf_conntrack_tuple));246 memcpy(&helper->tuple, tuple, sizeof(struct nf_conntrack_tuple));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t