Skip to content

Commit 347cb5d

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf 2022-04-27 We've added 5 non-merge commits during the last 20 day(s) which contain a total of 6 files changed, 34 insertions(+), 12 deletions(-). The main changes are: 1) Fix xsk sockets when rx and tx are separately bound to the same umem, also fix xsk copy mode combined with busy poll, from Maciej Fijalkowski. 2) Fix BPF tunnel/collect_md helpers with bpf_xmit lwt hook usage which triggered a crash due to invalid metadata_dst access, from Eyal Birger. 3) Fix release of page pool in XDP live packet mode, from Toke Høiland-Jørgensen. 4) Fix potential NULL pointer dereference in kretprobes, from Adam Zabrocki. (Masami & Steven preferred this small fix to be routed via bpf tree given it's follow-up fix to Masami's rethook work that went via bpf earlier, too.) * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: xsk: Fix possible crash when multiple sockets are created kprobes: Fix KRETPROBES when CONFIG_KRETPROBE_ON_RETHOOK is set bpf, lwt: Fix crash when using bpf_skb_set_tunnel_key() from bpf_xmit lwt hook bpf: Fix release of page_pool in BPF_PROG_RUN in test runner xsk: Fix l2fwd for copy mode + busy poll combo ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 7b5148b + ba3beec commit 347cb5d

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

include/net/xsk_buff_pool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool, struct net_device *dev,
9797
u16 queue_id, u16 flags);
9898
int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_umem *umem,
9999
struct net_device *dev, u16 queue_id);
100+
int xp_alloc_tx_descs(struct xsk_buff_pool *pool, struct xdp_sock *xs);
100101
void xp_destroy(struct xsk_buff_pool *pool);
101102
void xp_get_pool(struct xsk_buff_pool *pool);
102103
bool xp_put_pool(struct xsk_buff_pool *pool);

kernel/kprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ static void kretprobe_rethook_handler(struct rethook_node *rh, void *data,
21262126
struct kprobe_ctlblk *kcb;
21272127

21282128
/* The data must NOT be null. This means rethook data structure is broken. */
2129-
if (WARN_ON_ONCE(!data))
2129+
if (WARN_ON_ONCE(!data) || !rp->handler)
21302130
return;
21312131

21322132
__this_cpu_write(current_kprobe, &rp->kp);

net/bpf/test_run.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct xdp_test_data {
108108
struct page_pool *pp;
109109
struct xdp_frame **frames;
110110
struct sk_buff **skbs;
111+
struct xdp_mem_info mem;
111112
u32 batch_size;
112113
u32 frame_cnt;
113114
};
@@ -147,7 +148,6 @@ static void xdp_test_run_init_page(struct page *page, void *arg)
147148

148149
static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_ctx)
149150
{
150-
struct xdp_mem_info mem = {};
151151
struct page_pool *pp;
152152
int err = -ENOMEM;
153153
struct page_pool_params pp_params = {
@@ -174,7 +174,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c
174174
}
175175

176176
/* will copy 'mem.id' into pp->xdp_mem_id */
177-
err = xdp_reg_mem_model(&mem, MEM_TYPE_PAGE_POOL, pp);
177+
err = xdp_reg_mem_model(&xdp->mem, MEM_TYPE_PAGE_POOL, pp);
178178
if (err)
179179
goto err_mmodel;
180180

@@ -202,6 +202,7 @@ static int xdp_test_run_setup(struct xdp_test_data *xdp, struct xdp_buff *orig_c
202202

203203
static void xdp_test_run_teardown(struct xdp_test_data *xdp)
204204
{
205+
xdp_unreg_mem_model(&xdp->mem);
205206
page_pool_destroy(xdp->pp);
206207
kfree(xdp->frames);
207208
kfree(xdp->skbs);

net/core/lwt_bpf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ static int bpf_output(struct net *net, struct sock *sk, struct sk_buff *skb)
159159
return dst->lwtstate->orig_output(net, sk, skb);
160160
}
161161

162-
static int xmit_check_hhlen(struct sk_buff *skb)
162+
static int xmit_check_hhlen(struct sk_buff *skb, int hh_len)
163163
{
164-
int hh_len = skb_dst(skb)->dev->hard_header_len;
165-
166164
if (skb_headroom(skb) < hh_len) {
167165
int nhead = HH_DATA_ALIGN(hh_len - skb_headroom(skb));
168166

@@ -274,6 +272,7 @@ static int bpf_xmit(struct sk_buff *skb)
274272

275273
bpf = bpf_lwt_lwtunnel(dst->lwtstate);
276274
if (bpf->xmit.prog) {
275+
int hh_len = dst->dev->hard_header_len;
277276
__be16 proto = skb->protocol;
278277
int ret;
279278

@@ -291,7 +290,7 @@ static int bpf_xmit(struct sk_buff *skb)
291290
/* If the header was expanded, headroom might be too
292291
* small for L2 header to come, expand as needed.
293292
*/
294-
ret = xmit_check_hhlen(skb);
293+
ret = xmit_check_hhlen(skb, hh_len);
295294
if (unlikely(ret))
296295
return ret;
297296

net/xdp/xsk.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static int __xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len
639639
if (sk_can_busy_loop(sk))
640640
sk_busy_loop(sk, 1); /* only support non-blocking sockets */
641641

642-
if (xsk_no_wakeup(sk))
642+
if (xs->zc && xsk_no_wakeup(sk))
643643
return 0;
644644

645645
pool = xs->pool;
@@ -967,6 +967,19 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
967967

968968
xp_get_pool(umem_xs->pool);
969969
xs->pool = umem_xs->pool;
970+
971+
/* If underlying shared umem was created without Tx
972+
* ring, allocate Tx descs array that Tx batching API
973+
* utilizes
974+
*/
975+
if (xs->tx && !xs->pool->tx_descs) {
976+
err = xp_alloc_tx_descs(xs->pool, xs);
977+
if (err) {
978+
xp_put_pool(xs->pool);
979+
sockfd_put(sock);
980+
goto out_unlock;
981+
}
982+
}
970983
}
971984

972985
xdp_get_umem(umem_xs->umem);

net/xdp/xsk_buff_pool.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ void xp_destroy(struct xsk_buff_pool *pool)
4242
kvfree(pool);
4343
}
4444

45+
int xp_alloc_tx_descs(struct xsk_buff_pool *pool, struct xdp_sock *xs)
46+
{
47+
pool->tx_descs = kvcalloc(xs->tx->nentries, sizeof(*pool->tx_descs),
48+
GFP_KERNEL);
49+
if (!pool->tx_descs)
50+
return -ENOMEM;
51+
52+
return 0;
53+
}
54+
4555
struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
4656
struct xdp_umem *umem)
4757
{
@@ -59,11 +69,9 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
5969
if (!pool->heads)
6070
goto out;
6171

62-
if (xs->tx) {
63-
pool->tx_descs = kcalloc(xs->tx->nentries, sizeof(*pool->tx_descs), GFP_KERNEL);
64-
if (!pool->tx_descs)
72+
if (xs->tx)
73+
if (xp_alloc_tx_descs(pool, xs))
6574
goto out;
66-
}
6775

6876
pool->chunk_mask = ~((u64)umem->chunk_size - 1);
6977
pool->addrs_cnt = umem->size;

0 commit comments

Comments
 (0)