Skip to contentSkip to conversation

bpf: bpf_setsockopt: reset sock dst on SO_MARK changes

PATCH Applied Peter Oskolkov 4 participants 6 messages Jan 16, 2019 – Jan 17, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: bpf_setsockopt: reset sock dst on SO_MARK changes

In sock_setsockopt() (net/core/sock.h), when SO_MARK option is used to change sk_mark, sk_dst_reset(sk) is called. The same should be done in bpf_setsockopt.

---
 net/core/filter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/core/filter.c +4 -1
index 2b3b436ef545..0c1bc6ccfd7f 100644
@@ -4132,7 +4132,10 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
 			sk->sk_rcvlowat = val ? : 1;
 			break;
 		case SO_MARK:
-			sk->sk_mark = val;
+			if (sk->sk_mark != val) {
+				sk->sk_mark = val;
+				sk_dst_reset(sk);
+			}
 			break;
 		default:
 			ret = -EINVAL;
#4 lore raw
Quoted 10 lines · Daniel Borkmann
Quoted 6 lines · Peter Oskolkov

In sock_setsockopt() (net/core/sock.h), when SO_MARK option is used to change sk_mark, sk_dst_reset(sk) is called. The same should be done in bpf_setsockopt.

Given this is a fix, I'm inclined to apply to bpf tree. Objections?

Up to the maintainer... :)

Quoted 3 lines

Thanks,
Daniel

maintainer Applied
#5 lore raw
Quoted 7 lines · Peter Oskolkov
Quoted 6 lines · Daniel Borkmann
Quoted 4 lines · Peter Oskolkov

In sock_setsockopt() (net/core/sock.h), when SO_MARK option is used to change sk_mark, sk_dst_reset(sk) is called. The same should be done in bpf_setsockopt.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Given this is a fix, I'm inclined to apply to bpf tree. Objections?

Up to the maintainer... :)

Applied to bpf, thanks!