-
-
Save eddyz87/38d832b3f1fc74120598d3480bc16ae1 to your computer and use it in GitHub Desktop.
sock_map_link_lookup() checks inline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/net/core/sock_map.c b/net/core/sock_map.c | |
index dafc9aa6e192..3ad0fbc24576 100644 | |
--- a/net/core/sock_map.c | |
+++ b/net/core/sock_map.c | |
@@ -1492,40 +1492,23 @@ static int sock_map_prog_lookup(struct bpf_map *map, struct bpf_prog ***pprog, | |
return 0; | |
} | |
-static int sock_map_link_lookup(struct bpf_map *map, struct bpf_link ***plink, | |
- struct bpf_link *link, bool skip_check, u32 which) | |
+static int sock_map_link_lookup(struct bpf_map *map, struct bpf_link ***plink, u32 which) | |
{ | |
struct sk_psock_progs *progs = sock_map_progs(map); | |
switch (which) { | |
case BPF_SK_MSG_VERDICT: | |
- if (!skip_check && | |
- ((!link && progs->msg_parser_link) || | |
- (link && link != progs->msg_parser_link))) | |
- return -EBUSY; | |
*plink = &progs->msg_parser_link; | |
break; | |
#if IS_ENABLED(CONFIG_BPF_STREAM_PARSER) | |
case BPF_SK_SKB_STREAM_PARSER: | |
- if (!skip_check && | |
- ((!link && progs->stream_parser_link) || | |
- (link && link != progs->stream_parser_link))) | |
- return -EBUSY; | |
*plink = &progs->stream_parser_link; | |
break; | |
#endif | |
case BPF_SK_SKB_STREAM_VERDICT: | |
- if (!skip_check && | |
- ((!link && progs->stream_verdict_link) || | |
- (link && link != progs->stream_verdict_link))) | |
- return -EBUSY; | |
*plink = &progs->stream_verdict_link; | |
break; | |
case BPF_SK_SKB_VERDICT: | |
- if (!skip_check && | |
- ((!link && progs->skb_verdict_link) || | |
- (link && link != progs->skb_verdict_link))) | |
- return -EBUSY; | |
*plink = &progs->skb_verdict_link; | |
break; | |
default: | |
@@ -1555,12 +1538,13 @@ static int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, | |
if (ret) | |
goto out; | |
- if (!link || prog) | |
- ret = sock_map_link_lookup(map, &plink, NULL, false, which); | |
- else | |
- ret = sock_map_link_lookup(map, &plink, NULL, true, which); | |
+ ret = sock_map_link_lookup(map, &plink, which); | |
if (ret) | |
goto out; | |
+ if ((!link || prog) && *plink) { | |
+ ret = -EBUSY; | |
+ goto out; | |
+ } | |
if (old) { | |
ret = psock_replace_prog(pprog, prog, old); | |
@@ -1799,10 +1783,13 @@ static int sock_map_link_update_prog(struct bpf_link *link, | |
goto out; | |
/* Ensure the same link between the one in map and the passed-in. */ | |
- ret = sock_map_link_lookup(sockmap_link->map, &plink, link, false, | |
- sockmap_link->attach_type); | |
+ ret = sock_map_link_lookup(sockmap_link->map, &plink, sockmap_link->attach_type); | |
if (ret) | |
goto out; | |
+ if (link != *plink) { | |
+ ret = -EBUSY; | |
+ goto out; | |
+ } | |
if (old) | |
return psock_replace_prog(pprog, prog, old); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment