Skip to content

Commit 15d7039

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net coming late in the 5.17-rc process: 1) Revert port remap to mitigate shadowing service ports, this is causing problems in existing setups and this mitigation can be achieved with explicit ruleset, eg. ... tcp sport < 16386 tcp dport >= 32768 masquerade random This patches provided a built-in policy similar to the one described above. 2) Disable register tracking infrastructure in nf_tables. Florian reported two issues: - Existing expressions with no implemented .reduce interface that causes data-store on register should cancel the tracking. - Register clobbering might be possible storing data on registers that are larger than 32-bits. This might lead to generating incorrect ruleset bytecode. These two issues are scheduled to be addressed in the next release cycle. * git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: nf_tables: disable register tracking Revert "netfilter: conntrack: tag conntracks picked up in local out hook" Revert "netfilter: nat: force port remap to prevent shadowing well-known ports" ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 837d9e4 + ed5f85d commit 15d7039

File tree

5 files changed

+12
-49
lines changed

5 files changed

+12
-49
lines changed

include/net/netfilter/nf_conntrack.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct nf_conn {
9797
unsigned long status;
9898

9999
u16 cpu;
100-
u16 local_origin:1;
101100
possible_net_t ct_net;
102101

103102
#if IS_ENABLED(CONFIG_NF_NAT)

net/netfilter/nf_conntrack_core.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,9 +1748,6 @@ resolve_normal_ct(struct nf_conn *tmpl,
17481748
return 0;
17491749
if (IS_ERR(h))
17501750
return PTR_ERR(h);
1751-
1752-
ct = nf_ct_tuplehash_to_ctrack(h);
1753-
ct->local_origin = state->hook == NF_INET_LOCAL_OUT;
17541751
}
17551752
ct = nf_ct_tuplehash_to_ctrack(h);
17561753

net/netfilter/nf_nat_core.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -494,38 +494,6 @@ static void nf_nat_l4proto_unique_tuple(struct nf_conntrack_tuple *tuple,
494494
goto another_round;
495495
}
496496

497-
static bool tuple_force_port_remap(const struct nf_conntrack_tuple *tuple)
498-
{
499-
u16 sp, dp;
500-
501-
switch (tuple->dst.protonum) {
502-
case IPPROTO_TCP:
503-
sp = ntohs(tuple->src.u.tcp.port);
504-
dp = ntohs(tuple->dst.u.tcp.port);
505-
break;
506-
case IPPROTO_UDP:
507-
case IPPROTO_UDPLITE:
508-
sp = ntohs(tuple->src.u.udp.port);
509-
dp = ntohs(tuple->dst.u.udp.port);
510-
break;
511-
default:
512-
return false;
513-
}
514-
515-
/* IANA: System port range: 1-1023,
516-
* user port range: 1024-49151,
517-
* private port range: 49152-65535.
518-
*
519-
* Linux default ephemeral port range is 32768-60999.
520-
*
521-
* Enforce port remapping if sport is significantly lower
522-
* than dport to prevent NAT port shadowing, i.e.
523-
* accidental match of 'new' inbound connection vs.
524-
* existing outbound one.
525-
*/
526-
return sp < 16384 && dp >= 32768;
527-
}
528-
529497
/* Manipulate the tuple into the range given. For NF_INET_POST_ROUTING,
530498
* we change the source to map into the range. For NF_INET_PRE_ROUTING
531499
* and NF_INET_LOCAL_OUT, we change the destination to map into the
@@ -539,17 +507,11 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
539507
struct nf_conn *ct,
540508
enum nf_nat_manip_type maniptype)
541509
{
542-
bool random_port = range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL;
543510
const struct nf_conntrack_zone *zone;
544511
struct net *net = nf_ct_net(ct);
545512

546513
zone = nf_ct_zone(ct);
547514

548-
if (maniptype == NF_NAT_MANIP_SRC &&
549-
!random_port &&
550-
!ct->local_origin)
551-
random_port = tuple_force_port_remap(orig_tuple);
552-
553515
/* 1) If this srcip/proto/src-proto-part is currently mapped,
554516
* and that same mapping gives a unique tuple within the given
555517
* range, use that.
@@ -558,7 +520,8 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
558520
* So far, we don't do local source mappings, so multiple
559521
* manips not an issue.
560522
*/
561-
if (maniptype == NF_NAT_MANIP_SRC && !random_port) {
523+
if (maniptype == NF_NAT_MANIP_SRC &&
524+
!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) {
562525
/* try the original tuple first */
563526
if (in_range(orig_tuple, range)) {
564527
if (!nf_nat_used_tuple(orig_tuple, ct)) {
@@ -582,7 +545,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
582545
*/
583546

584547
/* Only bother mapping if it's not already in range and unique */
585-
if (!random_port) {
548+
if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) {
586549
if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
587550
if (!(range->flags & NF_NAT_RANGE_PROTO_OFFSET) &&
588551
l4proto_in_range(tuple, maniptype,

net/netfilter/nf_tables_api.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8260,6 +8260,12 @@ void nf_tables_trans_destroy_flush_work(void)
82608260
}
82618261
EXPORT_SYMBOL_GPL(nf_tables_trans_destroy_flush_work);
82628262

8263+
static bool nft_expr_reduce(struct nft_regs_track *track,
8264+
const struct nft_expr *expr)
8265+
{
8266+
return false;
8267+
}
8268+
82638269
static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *chain)
82648270
{
82658271
const struct nft_expr *expr, *last;
@@ -8307,8 +8313,7 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha
83078313
nft_rule_for_each_expr(expr, last, rule) {
83088314
track.cur = expr;
83098315

8310-
if (expr->ops->reduce &&
8311-
expr->ops->reduce(&track, expr)) {
8316+
if (nft_expr_reduce(&track, expr)) {
83128317
expr = track.cur;
83138318
continue;
83148319
}

tools/testing/selftests/netfilter/nft_nat.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,8 @@ EOF
880880
return $ksft_skip
881881
fi
882882

883-
# test default behaviour. Packet from ns1 to ns0 is not redirected
884-
# due to automatic port translation.
885-
test_port_shadow "default" "ROUTER"
883+
# test default behaviour. Packet from ns1 to ns0 is redirected to ns2.
884+
test_port_shadow "default" "CLIENT"
886885

887886
# test packet filter based mitigation: prevent forwarding of
888887
# packets claiming to come from the service port.

0 commit comments

Comments
 (0)