Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent_hive.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent_hive_dot-graph.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-dbg_bpf.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Documentation/cmdref/cilium-dbg_bpf_vtep-policy.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Documentation/cmdref/cilium-dbg_bpf_vtep-policy_delete.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Documentation/cmdref/cilium-dbg_bpf_vtep-policy_list.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Documentation/cmdref/cilium-dbg_bpf_vtep-policy_update.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Documentation/crdlist.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bpf/bpf_alignchecker.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ add_type(struct egress_gw_policy_entry6);

#include "lib/vtep.h"
add_type(struct vtep_key);
add_type(struct vtep_policy_key);
add_type(struct vtep_value);

add_type(struct srv6_vrf_key4);
Expand Down
24 changes: 24 additions & 0 deletions bpf/bpf_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "lib/wireguard.h"
#include "lib/l2_responder.h"
#include "lib/vtep.h"
#include "lib/crap.h"
#include "lib/subnet.h"

#define host_egress_policy_hook(ctx, src_sec_identity, ext_err) CTX_ACT_OK
Expand Down Expand Up @@ -708,6 +709,29 @@ handle_ipv4_cont(struct __ctx_buff *ctx, __u32 secctx, const bool from_host,
if (!revalidate_data(ctx, &data, &data_end, &ip4))
return DROP_INVALID;

struct crap_key key;
struct crap_value *tv;

key.dst_ip = ip4->daddr;

tv = map_lookup_elem (&cilium_crap_map, &key);
if (tv) {
ep = __lookup_ip4_endpoint(tv->pod_ip);
if (ep) {
int l3_off = ETH_HLEN;

return ipv4_local_delivery(ctx, l3_off, secctx, MARK_MAGIC_IDENTITY, ip4, ep,
METRIC_INGRESS, true, false, 0);
}

info = lookup_ip4_remote_endpoint(tv->pod_ip, 0);
if (info) {
return encap_and_redirect_with_nodeid(ctx, info, secctx,
info->sec_identity, &trace,
bpf_htons(ETH_P_IP));
}
}

#ifdef ENABLE_HOST_FIREWALL
from_host_raw = ctx_load_and_clear_meta(ctx, CB_FROM_HOST);

Expand Down
27 changes: 25 additions & 2 deletions bpf/bpf_lxc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "lib/fib.h"
#include "lib/nodeport.h"
#include "lib/policy_log.h"
#include "lib/crap.h"
#include "lib/vtep.h"
#include "lib/subnet.h"

Expand Down Expand Up @@ -1171,12 +1172,24 @@ ipv4_forward_to_destination(struct __ctx_buff *ctx, struct iphdr *ip4,
#if defined(ENABLE_VTEP)
{
struct vtep_key vkey = {};
struct vtep_policy_key vpkey = {
.prefixlen = 64,
.src_ip = ip4->saddr,
.dst_ip = ip4->daddr,
};
struct vtep_value *vtep;

vkey.vtep_ip = ip4->daddr & CONFIG(vtep_mask);
vtep = map_lookup_elem(&cilium_vtep_map, &vkey);
if (!vtep)
goto skip_vtep;
if (!vtep) {
if (!info || info->sec_identity == WORLD_IPV4_ID) {
vtep = map_lookup_elem(&cilium_vtep_policy_map, &vpkey);
if (!vtep)
goto skip_vtep;
} else {
goto skip_vtep;
}
}

if (vtep->vtep_mac && vtep->tunnel_endpoint) {
if (eth_store_daddr(ctx, (__u8 *)&vtep->vtep_mac, 0) < 0)
Expand Down Expand Up @@ -1550,6 +1563,16 @@ static __always_inline int __tail_handle_ipv4(struct __ctx_buff *ctx,
if (!revalidate_data_pull(ctx, &data, &data_end, &ip4))
return DROP_INVALID;

struct crap_key key;
struct crap_value *tv;

key.dst_ip = ip4->saddr;

tv = map_lookup_elem (&cilium_crap_map, &key);
if (tv) {
return CTX_ACT_OK;
}

/* If IPv4 fragmentation is disabled
* AND a IPv4 fragmented packet is received,
* then drop the packet.
Expand Down
17 changes: 17 additions & 0 deletions bpf/bpf_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "lib/clustermesh.h"
#include "lib/egress_gateway.h"
#include "lib/tailcall.h"
#include "lib/crap.h"
#include "lib/vtep.h"
#include "lib/arp.h"
#include "lib/encap.h"
Expand Down Expand Up @@ -291,6 +292,22 @@ static __always_inline int handle_ipv4(struct __ctx_buff *ctx,
if (!revalidate_data_pull(ctx, &data, &data_end, &ip4))
return DROP_INVALID;

struct crap_key key;
struct crap_value *tv;

key.dst_ip = ip4->daddr;

tv = map_lookup_elem (&cilium_crap_map, &key);
if (tv) {
ep = __lookup_ip4_endpoint(tv->pod_ip);
if (ep) {
int l3_off = ETH_HLEN;

return ipv4_local_delivery(ctx, l3_off, SECLABEL_IPV4, MARK_MAGIC_IDENTITY, ip4, ep,
METRIC_INGRESS, true, false, 0);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing remote endpoint fallback in overlay CRAP handling

Medium Severity

In bpf_host.c, when a CRAP entry exists but the local endpoint lookup fails, the code falls back to lookup_ip4_remote_endpoint and uses encap_and_redirect_with_nodeid to forward traffic to the correct node. However, bpf_overlay.c lacks this fallback—if the CRAP entry exists but the pod isn't local, traffic silently falls through to normal processing. This inconsistency means CRAP won't work correctly for overlay traffic when the target pod is on a different node.

Additional Locations (1)

Fix in Cursor Fix in Web


/* If IPv4 fragmentation is disabled
* AND a IPv4 fragmented packet is received,
* then drop the packet.
Expand Down
26 changes: 26 additions & 0 deletions bpf/lib/crap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
/* Copyright Authors of Cilium */

#pragma once

#include <linux/bpf.h>
#include <bpf/section.h>
#include <bpf/loader.h>
#include <lib/static_data.h>

struct crap_key {
__u32 dst_ip;
};

struct crap_value {
__u32 pod_ip;
};

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, struct crap_key);
__type(value, struct crap_value);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(max_entries, 8192);
__uint(map_flags, BPF_F_NO_PREALLOC);
} cilium_crap_map __section_maps_btf;
15 changes: 15 additions & 0 deletions bpf/lib/vtep.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ struct vtep_key {
__u32 vtep_ip;
};

struct vtep_policy_key {
__u32 prefixlen;
__u32 src_ip;
__u32 dst_ip;
};

struct vtep_value {
__u64 vtep_mac;
__u32 tunnel_endpoint;
Expand All @@ -26,6 +32,15 @@ struct {
__uint(max_entries, VTEP_MAP_SIZE);
__uint(map_flags, CONDITIONAL_PREALLOC);
} cilium_vtep_map __section_maps_btf;

struct {
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
__type(key, struct vtep_policy_key);
__type(value, struct vtep_value);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(max_entries, VTEP_POLICY_MAP_SIZE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} cilium_vtep_policy_map __section_maps_btf;
#endif /* ENABLE_VTEP */

DECLARE_CONFIG(__u32, vtep_mask, "VXLAN tunnel endpoint network mask")
1 change: 1 addition & 0 deletions bpf/node_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#define THROTTLE_MAP_SIZE 65536
#define ENABLE_ARP_RESPONDER
#define VTEP_MAP_SIZE 8
#define VTEP_POLICY_MAP_SIZE 16384
#define ENDPOINTS_MAP_SIZE 65536
#define METRICS_MAP_SIZE 65536
#define CILIUM_NET_MAC { .addr = { 0xce, 0x72, 0xa7, 0x03, 0x88, 0x57 } }
Expand Down
1 change: 1 addition & 0 deletions bugtool/cmd/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var bpfMapsPath = []string{
"tc/globals/cilium_snat_v4_alloc_retries",
"tc/globals/cilium_snat_v6_alloc_retries",
"tc/globals/cilium_vtep_map",
"tc/globals/cilium_vtep_policy_map",
"tc/globals/cilium_l2_responder_v4",
"tc/globals/cilium_l2_responder_v6",
"tc/globals/cilium_ratelimit",
Expand Down
18 changes: 18 additions & 0 deletions cilium-dbg/cmd/bpf_crap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package cmd

import (
"github.com/spf13/cobra"
)

// BPFCrapCmd represents the bpf command
var BPFCrapCmd = &cobra.Command{
Use: "crap",
Short: "Manage the CRAP rules",
}

func init() {
BPFCmd.AddCommand(BPFCrapCmd)
}
Loading