Skip to content

Commit bfa6407

Browse files
jrfastabdavem330
authored andcommitted
bpf: rename sk_actions to align with bpf infrastructure
Recent additions to support multiple programs in cgroups impose a strict requirement, "all yes is yes, any no is no". To enforce this the infrastructure requires the 'no' return code, SK_DROP in this case, to be 0. To apply these rules to SK_SKB program types the sk_actions return codes need to be adjusted. This fix adds SK_PASS and makes 'SK_DROP = 0'. Finally, remove SK_ABORTED to remove any chance that the API may allow aborted program flows to be passed up the stack. This would be incorrect behavior and allow programs to break existing policies. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8108a77 commit bfa6407

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

include/uapi/linux/bpf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ union bpf_attr {
575575
* @map: pointer to sockmap
576576
* @key: key to lookup sock in map
577577
* @flags: reserved for future use
578-
* Return: SK_REDIRECT
578+
* Return: SK_PASS
579579
*
580580
* int bpf_sock_map_update(skops, map, key, flags)
581581
* @skops: pointer to bpf_sock_ops
@@ -786,8 +786,8 @@ struct xdp_md {
786786
};
787787

788788
enum sk_action {
789-
SK_ABORTED = 0,
790-
SK_DROP,
789+
SK_DROP = 0,
790+
SK_PASS,
791791
SK_REDIRECT,
792792
};
793793

kernel/bpf/sockmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static int smap_verdict_func(struct smap_psock *psock, struct sk_buff *skb)
122122
preempt_enable();
123123
skb->sk = NULL;
124124

125-
return rc;
125+
return rc == SK_PASS ?
126+
(TCP_SKB_CB(skb)->bpf.map ? SK_REDIRECT : SK_PASS) : SK_DROP;
126127
}
127128

128129
static void smap_do_verdict(struct smap_psock *psock, struct sk_buff *skb)

net/core/filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,14 +1844,15 @@ BPF_CALL_4(bpf_sk_redirect_map, struct sk_buff *, skb,
18441844
{
18451845
struct tcp_skb_cb *tcb = TCP_SKB_CB(skb);
18461846

1847+
/* If user passes invalid input drop the packet. */
18471848
if (unlikely(flags))
1848-
return SK_ABORTED;
1849+
return SK_DROP;
18491850

18501851
tcb->bpf.key = key;
18511852
tcb->bpf.flags = flags;
18521853
tcb->bpf.map = map;
18531854

1854-
return SK_REDIRECT;
1855+
return SK_PASS;
18551856
}
18561857

18571858
struct sock *do_sk_redirect_map(struct sk_buff *skb)

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ struct xdp_md {
787787
};
788788

789789
enum sk_action {
790-
SK_ABORTED = 0,
791-
SK_DROP,
790+
SK_DROP = 0,
791+
SK_PASS,
792792
SK_REDIRECT,
793793
};
794794

0 commit comments

Comments
 (0)