Skip to content

Commit 40106e0

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net 1) Don't refresh timeout for SCTP flows in CLOSED state. 2) Don't allow access to transport header if fragment offset is set on. 3) Reinitialize internal conntrack state for retransmitted TCP syn-ack packet. 4) Update MAINTAINER file to add the Netfilter group tree. Moving forward, Florian Westphal has access to this tree so he can also send pull requests. 5) Set on IPS_HELPER for entries created via ctnetlink, otherwise NAT might zap it. All patches from Florian Westphal. * git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: ctnetlink: disable helper autoassign MAINTAINERS: netfilter: update git links netfilter: conntrack: re-init state for retransmitted syn-ack netfilter: conntrack: move synack init code to helper netfilter: nft_payload: don't allow th access for fragments netfilter: conntrack: don't refresh sctp entries in closed state ==================== Link: https://lore.kernel.org/r/20220204151903.320786-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents fe68195 + d1ca60e commit 40106e0

File tree

7 files changed

+61
-27
lines changed

7 files changed

+61
-27
lines changed

MAINTAINERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13297,8 +13297,8 @@ W: http://www.iptables.org/
1329713297
W: http://www.nftables.org/
1329813298
Q: http://patchwork.ozlabs.org/project/netfilter-devel/list/
1329913299
C: irc://irc.libera.chat/netfilter
13300-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
13301-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
13300+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git
13301+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git
1330213302
F: include/linux/netfilter*
1330313303
F: include/linux/netfilter/
1330413304
F: include/net/netfilter/

include/uapi/linux/netfilter/nf_conntrack_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ enum ip_conntrack_status {
106106
IPS_NAT_CLASH = IPS_UNTRACKED,
107107
#endif
108108

109-
/* Conntrack got a helper explicitly attached via CT target. */
109+
/* Conntrack got a helper explicitly attached (ruleset, ctnetlink). */
110110
IPS_HELPER_BIT = 13,
111111
IPS_HELPER = (1 << IPS_HELPER_BIT),
112112

net/netfilter/nf_conntrack_netlink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,8 @@ ctnetlink_create_conntrack(struct net *net,
23112311
if (helper->from_nlattr)
23122312
helper->from_nlattr(helpinfo, ct);
23132313

2314-
/* not in hash table yet so not strictly necessary */
2314+
/* disable helper auto-assignment for this entry */
2315+
ct->status |= IPS_HELPER;
23152316
RCU_INIT_POINTER(help->helper, helper);
23162317
}
23172318
} else {

net/netfilter/nf_conntrack_proto_sctp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,15 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
489489
pr_debug("Setting vtag %x for dir %d\n",
490490
ih->init_tag, !dir);
491491
ct->proto.sctp.vtag[!dir] = ih->init_tag;
492+
493+
/* don't renew timeout on init retransmit so
494+
* port reuse by client or NAT middlebox cannot
495+
* keep entry alive indefinitely (incl. nat info).
496+
*/
497+
if (new_state == SCTP_CONNTRACK_CLOSED &&
498+
old_state == SCTP_CONNTRACK_CLOSED &&
499+
nf_ct_is_confirmed(ct))
500+
ignore = true;
492501
}
493502

494503
ct->proto.sctp.state = new_state;

net/netfilter/nf_conntrack_proto_tcp.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,32 @@ static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
446446
}
447447
}
448448

449+
static void tcp_init_sender(struct ip_ct_tcp_state *sender,
450+
struct ip_ct_tcp_state *receiver,
451+
const struct sk_buff *skb,
452+
unsigned int dataoff,
453+
const struct tcphdr *tcph,
454+
u32 end, u32 win)
455+
{
456+
/* SYN-ACK in reply to a SYN
457+
* or SYN from reply direction in simultaneous open.
458+
*/
459+
sender->td_end =
460+
sender->td_maxend = end;
461+
sender->td_maxwin = (win == 0 ? 1 : win);
462+
463+
tcp_options(skb, dataoff, tcph, sender);
464+
/* RFC 1323:
465+
* Both sides must send the Window Scale option
466+
* to enable window scaling in either direction.
467+
*/
468+
if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE &&
469+
receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE)) {
470+
sender->td_scale = 0;
471+
receiver->td_scale = 0;
472+
}
473+
}
474+
449475
static bool tcp_in_window(struct nf_conn *ct,
450476
enum ip_conntrack_dir dir,
451477
unsigned int index,
@@ -499,24 +525,9 @@ static bool tcp_in_window(struct nf_conn *ct,
499525
* Initialize sender data.
500526
*/
501527
if (tcph->syn) {
502-
/*
503-
* SYN-ACK in reply to a SYN
504-
* or SYN from reply direction in simultaneous open.
505-
*/
506-
sender->td_end =
507-
sender->td_maxend = end;
508-
sender->td_maxwin = (win == 0 ? 1 : win);
509-
510-
tcp_options(skb, dataoff, tcph, sender);
511-
/*
512-
* RFC 1323:
513-
* Both sides must send the Window Scale option
514-
* to enable window scaling in either direction.
515-
*/
516-
if (!(sender->flags & IP_CT_TCP_FLAG_WINDOW_SCALE
517-
&& receiver->flags & IP_CT_TCP_FLAG_WINDOW_SCALE))
518-
sender->td_scale =
519-
receiver->td_scale = 0;
528+
tcp_init_sender(sender, receiver,
529+
skb, dataoff, tcph,
530+
end, win);
520531
if (!tcph->ack)
521532
/* Simultaneous open */
522533
return true;
@@ -560,6 +571,18 @@ static bool tcp_in_window(struct nf_conn *ct,
560571
sender->td_maxwin = (win == 0 ? 1 : win);
561572

562573
tcp_options(skb, dataoff, tcph, sender);
574+
} else if (tcph->syn && dir == IP_CT_DIR_REPLY &&
575+
state->state == TCP_CONNTRACK_SYN_SENT) {
576+
/* Retransmitted syn-ack, or syn (simultaneous open).
577+
*
578+
* Re-init state for this direction, just like for the first
579+
* syn(-ack) reply, it might differ in seq, ack or tcp options.
580+
*/
581+
tcp_init_sender(sender, receiver,
582+
skb, dataoff, tcph,
583+
end, win);
584+
if (!tcph->ack)
585+
return true;
563586
}
564587

565588
if (!(tcph->ack)) {

net/netfilter/nft_exthdr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ nft_tcp_header_pointer(const struct nft_pktinfo *pkt,
167167
{
168168
struct tcphdr *tcph;
169169

170-
if (pkt->tprot != IPPROTO_TCP)
170+
if (pkt->tprot != IPPROTO_TCP || pkt->fragoff)
171171
return NULL;
172172

173173
tcph = skb_header_pointer(pkt->skb, nft_thoff(pkt), sizeof(*tcph), buffer);

net/netfilter/nft_payload.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int __nft_payload_inner_offset(struct nft_pktinfo *pkt)
8383
{
8484
unsigned int thoff = nft_thoff(pkt);
8585

86-
if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
86+
if (!(pkt->flags & NFT_PKTINFO_L4PROTO) || pkt->fragoff)
8787
return -1;
8888

8989
switch (pkt->tprot) {
@@ -147,7 +147,7 @@ void nft_payload_eval(const struct nft_expr *expr,
147147
offset = skb_network_offset(skb);
148148
break;
149149
case NFT_PAYLOAD_TRANSPORT_HEADER:
150-
if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
150+
if (!(pkt->flags & NFT_PKTINFO_L4PROTO) || pkt->fragoff)
151151
goto err;
152152
offset = nft_thoff(pkt);
153153
break;
@@ -688,7 +688,7 @@ static void nft_payload_set_eval(const struct nft_expr *expr,
688688
offset = skb_network_offset(skb);
689689
break;
690690
case NFT_PAYLOAD_TRANSPORT_HEADER:
691-
if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
691+
if (!(pkt->flags & NFT_PKTINFO_L4PROTO) || pkt->fragoff)
692692
goto err;
693693
offset = nft_thoff(pkt);
694694
break;
@@ -728,7 +728,8 @@ static void nft_payload_set_eval(const struct nft_expr *expr,
728728
if (priv->csum_type == NFT_PAYLOAD_CSUM_SCTP &&
729729
pkt->tprot == IPPROTO_SCTP &&
730730
skb->ip_summed != CHECKSUM_PARTIAL) {
731-
if (nft_payload_csum_sctp(skb, nft_thoff(pkt)))
731+
if (pkt->fragoff == 0 &&
732+
nft_payload_csum_sctp(skb, nft_thoff(pkt)))
732733
goto err;
733734
}
734735

0 commit comments

Comments
 (0)