Skip to contentSkip to conversation

samples/bpf: Fix broken tracex1 due to kprobe argument change

PATCH In review Yaqi Chen 3 participants 3 messages Apr 16, 2021 – Apr 20, 2021 BPF

lore
Share & tools
lore

Yaqi Chen

author
#0 lore raw

PATCH 1/1 samples/bpf: Fix broken tracex1 due to kprobe argument change

From commit c0bbbdc32feb ("__netif_receive_skb_core: pass skb by reference"), the first argument passed into __netif_receive_skb_core has changed to reference of a skb pointer.

This commit fixes by using bpf_probe_read_kernel.

---
 samples/bpf/tracex1_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
samples/bpf/tracex1_kern.c +2 -2
index 3f4599c9a202..ef30d2b353b0 100644
@@ -26,7 +26,7 @@
 SEC("kprobe/__netif_receive_skb_core")
 int bpf_prog1(struct pt_regs *ctx)
 {
-	/* attaches to kprobe netif_receive_skb,
+	/* attaches to kprobe __netif_receive_skb_core,
 	 * looks for packets on loobpack device and prints them
 	 */
 	char devname[IFNAMSIZ];
@@ -35,7 +35,7 @@ int bpf_prog1(struct pt_regs *ctx)
 	int len;
 
 	/* non-portable! works for the given kernel only */
-	skb = (struct sk_buff *) PT_REGS_PARM1(ctx);
+	bpf_probe_read_kernel(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx));
 	dev = _(skb->dev);
 	len = _(skb->len);
 
Signature · 1 line
2.18.4
#2 lore raw
In reply to Yaqi Chen
Quoted 17 lines · Yaqi Chen

From commit c0bbbdc32feb ("__netif_receive_skb_core: pass skb by reference"), the first argument passed into __netif_receive_skb_core has changed to reference of a skb pointer.

This commit fixes by using bpf_probe_read_kernel.

---
 samples/bpf/tracex1_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
samples/bpf/tracex1_kern.c +0 -0
index 3f4599c9a202..ef30d2b353b0 100644

samples/bpf/tracex1_kern.c line 27

Quoted 2 lines
samples/bpf/tracex1_kern.c +0 -0
@@ -26,7 +26,7 @@
 SEC("kprobe/__netif_receive_skb_core")
 int bpf_prog1(struct pt_regs *ctx)

This is a good opportunity to use BPF_KPROBE from bpf_tracing.h helper. It would look like:

SEC("kprobe/__netif_receive_skb_core")
int BPF_KPROBE(struct sk_buff **pskb, bool pfmemalloc, struct packet_type **ppt_prev)
{

    /* and here you'll be able to read sk_buff pointer as */
    bpf_probe_read_kernel(&skb, sizeof(skb), pskb);

}

Quoted 18 lines
samples/bpf/tracex1_kern.c +2 -3
 {
-       /* attaches to kprobe netif_receive_skb,
+       /* attaches to kprobe __netif_receive_skb_core,
         * looks for packets on loobpack device and prints them
         */
        char devname[IFNAMSIZ];
@@ -35,7 +35,7 @@ int bpf_prog1(struct pt_regs *ctx)
        int len;
 
        /* non-portable! works for the given kernel only */
-       skb = (struct sk_buff *) PT_REGS_PARM1(ctx);
+       bpf_probe_read_kernel(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx));
        dev = _(skb->dev);
        len = _(skb->len);
 
--

2.18.4