Skip to content

Commit c530e3d

Browse files
committed
Merge: bpf: stable backports for 10.1 (phase 2)
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1255 JIRA: https://issues.redhat.com/browse/RHEL-96605 JIRA: https://issues.redhat.com/browse/RHEL-100445 JIRA: https://issues.redhat.com/browse/RHEL-87917 CVE: CVE-2025-21867 CVE: CVE-2025-21997 Backporting fixes for serious issues from upstream. Signed-off-by: Felix Maurer <fmaurer@redhat.com> Approved-by: Murphy Zhou <xzhou@redhat.com> Approved-by: Toke Høiland-Jørgensen <toke@redhat.com> Approved-by: Guillaume Nault <gnault@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Julio Faracco <jfaracco@redhat.com>
2 parents 32f8278 + e11cd6e commit c530e3d

File tree

10 files changed

+103
-17
lines changed

10 files changed

+103
-17
lines changed

kernel/bpf/btf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6509,6 +6509,8 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
65096509
{ "rxrpc_resend", 0x10 },
65106510
{ "rxrpc_tq", 0x10 },
65116511
{ "rxrpc_client", 0x1 },
6512+
/* skb */
6513+
{"kfree_skb", 0x1000},
65126514
/* sunrpc */
65136515
{ "xs_stream_read_data", 0x1 },
65146516
/* ... from xprt_cong_event event class */

kernel/trace/bpf_trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,7 +3404,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
34043404
}
34053405

34063406
if (pid) {
3407+
rcu_read_lock();
34073408
task = get_pid_task(find_vpid(pid), PIDTYPE_TGID);
3409+
rcu_read_unlock();
34083410
if (!task) {
34093411
err = -ESRCH;
34103412
goto error_path_put;

net/bpf/test_run.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,9 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 user_size,
660660
void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
661661
void *data;
662662

663-
if (size < ETH_HLEN || size > PAGE_SIZE - headroom - tailroom)
663+
if (user_size < ETH_HLEN || user_size > PAGE_SIZE - headroom - tailroom)
664664
return ERR_PTR(-EINVAL);
665665

666-
if (user_size > size)
667-
return ERR_PTR(-EMSGSIZE);
668-
669666
size = SKB_DATA_ALIGN(size);
670667
data = kzalloc(size + headroom + tailroom, GFP_USER);
671668
if (!data)

net/core/filter.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,13 @@ static const struct bpf_func_proto bpf_skb_vlan_pop_proto = {
32263226
.arg1_type = ARG_PTR_TO_CTX,
32273227
};
32283228

3229+
static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto)
3230+
{
3231+
skb->protocol = htons(proto);
3232+
if (skb_valid_dst(skb))
3233+
skb_dst_drop(skb);
3234+
}
3235+
32293236
static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len)
32303237
{
32313238
/* Caller already did skb_cow() with len as headroom,
@@ -3322,7 +3329,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
33223329
}
33233330
}
33243331

3325-
skb->protocol = htons(ETH_P_IPV6);
3332+
bpf_skb_change_protocol(skb, ETH_P_IPV6);
33263333
skb_clear_hash(skb);
33273334

33283335
return 0;
@@ -3352,7 +3359,7 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
33523359
}
33533360
}
33543361

3355-
skb->protocol = htons(ETH_P_IP);
3362+
bpf_skb_change_protocol(skb, ETH_P_IP);
33563363
skb_clear_hash(skb);
33573364

33583365
return 0;
@@ -3543,10 +3550,10 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
35433550
/* Match skb->protocol to new outer l3 protocol */
35443551
if (skb->protocol == htons(ETH_P_IP) &&
35453552
flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV6)
3546-
skb->protocol = htons(ETH_P_IPV6);
3553+
bpf_skb_change_protocol(skb, ETH_P_IPV6);
35473554
else if (skb->protocol == htons(ETH_P_IPV6) &&
35483555
flags & BPF_F_ADJ_ROOM_ENCAP_L3_IPV4)
3549-
skb->protocol = htons(ETH_P_IP);
3556+
bpf_skb_change_protocol(skb, ETH_P_IP);
35503557
}
35513558

35523559
if (skb_is_gso(skb)) {
@@ -3599,10 +3606,10 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
35993606
/* Match skb->protocol to new outer l3 protocol */
36003607
if (skb->protocol == htons(ETH_P_IP) &&
36013608
flags & BPF_F_ADJ_ROOM_DECAP_L3_IPV6)
3602-
skb->protocol = htons(ETH_P_IPV6);
3609+
bpf_skb_change_protocol(skb, ETH_P_IPV6);
36033610
else if (skb->protocol == htons(ETH_P_IPV6) &&
36043611
flags & BPF_F_ADJ_ROOM_DECAP_L3_IPV4)
3605-
skb->protocol = htons(ETH_P_IP);
3612+
bpf_skb_change_protocol(skb, ETH_P_IP);
36063613

36073614
if (skb_is_gso(skb)) {
36083615
struct skb_shared_info *shinfo = skb_shinfo(skb);

net/core/skmsg.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,13 @@ static void sk_psock_backlog(struct work_struct *work)
649649
bool ingress;
650650
int ret;
651651

652+
/* Increment the psock refcnt to synchronize with close(fd) path in
653+
* sock_map_close(), ensuring we wait for backlog thread completion
654+
* before sk_socket freed. If refcnt increment fails, it indicates
655+
* sock_map_close() completed with sk_socket potentially already freed.
656+
*/
657+
if (!sk_psock_get(psock->sk))
658+
return;
652659
mutex_lock(&psock->work_mutex);
653660
if (unlikely(state->len)) {
654661
len = state->len;
@@ -696,6 +703,7 @@ static void sk_psock_backlog(struct work_struct *work)
696703
}
697704
end:
698705
mutex_unlock(&psock->work_mutex);
706+
sk_psock_put(psock->sk, psock);
699707
}
700708

701709
struct sk_psock *sk_psock_init(struct sock *sk, int node)
@@ -1117,9 +1125,9 @@ static void sk_psock_strp_data_ready(struct sock *sk)
11171125
if (tls_sw_has_ctx_rx(sk)) {
11181126
psock->saved_data_ready(sk);
11191127
} else {
1120-
write_lock_bh(&sk->sk_callback_lock);
1128+
read_lock_bh(&sk->sk_callback_lock);
11211129
strp_data_ready(&psock->strp);
1122-
write_unlock_bh(&sk->sk_callback_lock);
1130+
read_unlock_bh(&sk->sk_callback_lock);
11231131
}
11241132
}
11251133
rcu_read_unlock();

net/xdp/xsk_buff_pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
106106
if (pool->unaligned)
107107
pool->free_heads[i] = xskb;
108108
else
109-
xp_init_xskb_addr(xskb, pool, i * pool->chunk_size);
109+
xp_init_xskb_addr(xskb, pool, (u64)i * pool->chunk_size);
110110
}
111111

112112
return pool;

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,58 @@ static void test_sockmap_skb_verdict_shutdown(void)
501501
test_sockmap_pass_prog__destroy(skel);
502502
}
503503

504+
static void test_sockmap_stream_pass(void)
505+
{
506+
int zero = 0, sent, recvd;
507+
int verdict, parser;
508+
int err, map;
509+
int c = -1, p = -1;
510+
struct test_sockmap_pass_prog *pass = NULL;
511+
char snd[256] = "0123456789";
512+
char rcv[256] = "0";
513+
514+
pass = test_sockmap_pass_prog__open_and_load();
515+
verdict = bpf_program__fd(pass->progs.prog_skb_verdict);
516+
parser = bpf_program__fd(pass->progs.prog_skb_parser);
517+
map = bpf_map__fd(pass->maps.sock_map_rx);
518+
519+
err = bpf_prog_attach(parser, map, BPF_SK_SKB_STREAM_PARSER, 0);
520+
if (!ASSERT_OK(err, "bpf_prog_attach stream parser"))
521+
goto out;
522+
523+
err = bpf_prog_attach(verdict, map, BPF_SK_SKB_STREAM_VERDICT, 0);
524+
if (!ASSERT_OK(err, "bpf_prog_attach stream verdict"))
525+
goto out;
526+
527+
err = create_pair(AF_INET, SOCK_STREAM, &c, &p);
528+
if (err)
529+
goto out;
530+
531+
/* sk_data_ready of 'p' will be replaced by strparser handler */
532+
err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST);
533+
if (!ASSERT_OK(err, "bpf_map_update_elem(p)"))
534+
goto out_close;
535+
536+
/*
537+
* as 'prog_skb_parser' return the original skb len and
538+
* 'prog_skb_verdict' return SK_PASS, the kernel will just
539+
* pass it through to original socket 'p'
540+
*/
541+
sent = xsend(c, snd, sizeof(snd), 0);
542+
ASSERT_EQ(sent, sizeof(snd), "xsend(c)");
543+
544+
recvd = recv_timeout(p, rcv, sizeof(rcv), SOCK_NONBLOCK,
545+
IO_TIMEOUT_SEC);
546+
ASSERT_EQ(recvd, sizeof(rcv), "recv_timeout(p)");
547+
548+
out_close:
549+
close(c);
550+
close(p);
551+
552+
out:
553+
test_sockmap_pass_prog__destroy(pass);
554+
}
555+
504556
static void test_sockmap_skb_verdict_fionread(bool pass_prog)
505557
{
506558
int err, map, verdict, c0 = -1, c1 = -1, p0 = -1, p1 = -1;
@@ -923,6 +975,8 @@ void test_sockmap_basic(void)
923975
test_sockmap_progs_query(BPF_SK_SKB_VERDICT);
924976
if (test__start_subtest("sockmap skb_verdict shutdown"))
925977
test_sockmap_skb_verdict_shutdown();
978+
if (test__start_subtest("sockmap stream parser and verdict pass"))
979+
test_sockmap_stream_pass();
926980
if (test__start_subtest("sockmap skb_verdict fionread"))
927981
test_sockmap_skb_verdict_fionread(true);
928982
if (test__start_subtest("sockmap skb_verdict fionread on drop"))

tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void test_xdp_with_devmap_helpers(void)
2323
__u32 len = sizeof(info);
2424
int err, dm_fd, dm_fd_redir, map_fd;
2525
struct nstoken *nstoken = NULL;
26-
char data[10] = {};
26+
char data[ETH_HLEN] = {};
2727
__u32 idx = 0;
2828

2929
SYS(out_close, "ip netns add %s", TEST_NS);
@@ -58,7 +58,7 @@ static void test_xdp_with_devmap_helpers(void)
5858
/* send a packet to trigger any potential bugs in there */
5959
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
6060
.data_in = &data,
61-
.data_size_in = 10,
61+
.data_size_in = sizeof(data),
6262
.flags = BPF_F_TEST_XDP_LIVE_FRAMES,
6363
.repeat = 1,
6464
);
@@ -158,7 +158,7 @@ static void test_xdp_with_devmap_helpers_veth(void)
158158
struct nstoken *nstoken = NULL;
159159
__u32 len = sizeof(info);
160160
int err, dm_fd, dm_fd_redir, map_fd, ifindex_dst;
161-
char data[10] = {};
161+
char data[ETH_HLEN] = {};
162162
__u32 idx = 0;
163163

164164
SYS(out_close, "ip netns add %s", TEST_NS);
@@ -208,7 +208,7 @@ static void test_xdp_with_devmap_helpers_veth(void)
208208
/* send a packet to trigger any potential bugs in there */
209209
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
210210
.data_in = &data,
211-
.data_size_in = 10,
211+
.data_size_in = sizeof(data),
212212
.flags = BPF_F_TEST_XDP_LIVE_FRAMES,
213213
.repeat = 1,
214214
);

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ TEST_PROGS += amt.sh
2727
TEST_PROGS += unicast_extensions.sh
2828
TEST_PROGS += udpgro_fwd.sh
2929
TEST_PROGS += udpgro_frglist.sh
30+
TEST_PROGS += nat6to4.sh
3031
TEST_PROGS += veth.sh
3132
TEST_PROGS += ioam6.sh
3233
TEST_PROGS += gro.sh
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NS="ns-peer-$(mktemp -u XXXXXX)"
5+
6+
ip netns add "${NS}"
7+
ip -netns "${NS}" link set lo up
8+
ip -netns "${NS}" route add default via 127.0.0.2 dev lo
9+
10+
tc -n "${NS}" qdisc add dev lo ingress
11+
tc -n "${NS}" filter add dev lo ingress prio 4 protocol ip \
12+
bpf object-file nat6to4.bpf.o section schedcls/egress4/snat4 direct-action
13+
14+
ip netns exec "${NS}" \
15+
bash -c 'echo 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abc | socat - UDP4-DATAGRAM:224.1.0.1:6666,ip-multicast-loop=1'

0 commit comments

Comments
 (0)