Commit 743df8b7 authored by John Fastabend's avatar John Fastabend Committed by Alexei Starovoitov

bpf, sockmap: Check skb_verdict and skb_parser programs explicitly

We are about to allow skb_verdict to run without skb_parser programs
as a first step change code to check each program type specifically.
This should be a mechanical change without any impact to actual result.
Signed-off-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160239294756.8495.5796595770890272219.stgit@john-Precision-5820-Tower
parent 20a6d915
...@@ -230,16 +230,16 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs, ...@@ -230,16 +230,16 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
{ {
struct bpf_prog *msg_parser, *skb_parser, *skb_verdict; struct bpf_prog *msg_parser, *skb_parser, *skb_verdict;
struct sk_psock *psock; struct sk_psock *psock;
bool skb_progs;
int ret; int ret;
skb_verdict = READ_ONCE(progs->skb_verdict); skb_verdict = READ_ONCE(progs->skb_verdict);
skb_parser = READ_ONCE(progs->skb_parser); skb_parser = READ_ONCE(progs->skb_parser);
skb_progs = skb_parser && skb_verdict; if (skb_verdict) {
if (skb_progs) {
skb_verdict = bpf_prog_inc_not_zero(skb_verdict); skb_verdict = bpf_prog_inc_not_zero(skb_verdict);
if (IS_ERR(skb_verdict)) if (IS_ERR(skb_verdict))
return PTR_ERR(skb_verdict); return PTR_ERR(skb_verdict);
}
if (skb_parser) {
skb_parser = bpf_prog_inc_not_zero(skb_parser); skb_parser = bpf_prog_inc_not_zero(skb_parser);
if (IS_ERR(skb_parser)) { if (IS_ERR(skb_parser)) {
bpf_prog_put(skb_verdict); bpf_prog_put(skb_verdict);
...@@ -264,7 +264,8 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs, ...@@ -264,7 +264,8 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
if (psock) { if (psock) {
if ((msg_parser && READ_ONCE(psock->progs.msg_parser)) || if ((msg_parser && READ_ONCE(psock->progs.msg_parser)) ||
(skb_progs && READ_ONCE(psock->progs.skb_parser))) { (skb_parser && READ_ONCE(psock->progs.skb_parser)) ||
(skb_verdict && READ_ONCE(psock->progs.skb_verdict))) {
sk_psock_put(sk, psock); sk_psock_put(sk, psock);
ret = -EBUSY; ret = -EBUSY;
goto out_progs; goto out_progs;
...@@ -285,7 +286,7 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs, ...@@ -285,7 +286,7 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
goto out_drop; goto out_drop;
write_lock_bh(&sk->sk_callback_lock); write_lock_bh(&sk->sk_callback_lock);
if (skb_progs && !psock->parser.enabled) { if (skb_parser && skb_verdict && !psock->parser.enabled) {
ret = sk_psock_init_strp(sk, psock); ret = sk_psock_init_strp(sk, psock);
if (ret) { if (ret) {
write_unlock_bh(&sk->sk_callback_lock); write_unlock_bh(&sk->sk_callback_lock);
...@@ -303,10 +304,10 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs, ...@@ -303,10 +304,10 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
if (msg_parser) if (msg_parser)
bpf_prog_put(msg_parser); bpf_prog_put(msg_parser);
out: out:
if (skb_progs) { if (skb_verdict)
bpf_prog_put(skb_verdict); bpf_prog_put(skb_verdict);
if (skb_parser)
bpf_prog_put(skb_parser); bpf_prog_put(skb_parser);
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment