diff mbox series

[bpf-next] bpf: bpf_setsockopt: reset sock dst on SO_MARK changes

Message ID 20190116164754.104170-1-posk@google.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpf: bpf_setsockopt: reset sock dst on SO_MARK changes | expand

Commit Message

Peter Oskolkov Jan. 16, 2019, 4:47 p.m. UTC
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.

Reported-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Peter Oskolkov <posk@google.com>
---
 net/core/filter.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--

Comments

Martin KaFai Lau Jan. 16, 2019, 6:09 p.m. UTC | #1
On Wed, Jan 16, 2019 at 08:47:54AM -0800, Peter Oskolkov wrote:
> 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.
> 
> Reported-by: Maciej Żenczykowski <maze@google.com>
> Signed-off-by: Peter Oskolkov <posk@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Maciej Żenczykowski Jan. 17, 2019, 12:35 a.m. UTC | #2
On Wed, Jan 16, 2019 at 10:09 AM Martin Lau <kafai@fb.com> wrote:
> > 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.
> >
> > Reported-by: Maciej Żenczykowski <maze@google.com>
> > Signed-off-by: Peter Oskolkov <posk@google.com>
> Acked-by: Martin KaFai Lau <kafai@fb.com>
Reviewed-by: Maciej Żenczykowski <maze@google.com>
Daniel Borkmann Jan. 17, 2019, 3:50 p.m. UTC | #3
On 01/16/2019 05:47 PM, Peter Oskolkov wrote:
> 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.
> 
> Reported-by: Maciej Żenczykowski <maze@google.com>
> Signed-off-by: Peter Oskolkov <posk@google.com>

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

Thanks,
Daniel
Peter Oskolkov Jan. 17, 2019, 4:36 p.m. UTC | #4
On Thu, Jan 17, 2019 at 7:50 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 01/16/2019 05:47 PM, Peter Oskolkov wrote:
> > 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.
> >
> > Reported-by: Maciej Żenczykowski <maze@google.com>
> > Signed-off-by: Peter Oskolkov <posk@google.com>
>
> Given this is a fix, I'm inclined to apply to bpf tree. Objections?

Up to the maintainer... :)

>
> Thanks,
> Daniel
Daniel Borkmann Jan. 17, 2019, 11:34 p.m. UTC | #5
On 01/17/2019 05:36 PM, Peter Oskolkov wrote:
> On Thu, Jan 17, 2019 at 7:50 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>>
>> On 01/16/2019 05:47 PM, Peter Oskolkov wrote:
>>> 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.
>>>
>>> Reported-by: Maciej Żenczykowski <maze@google.com>
>>> Signed-off-by: Peter Oskolkov <posk@google.com>
>>
>> Given this is a fix, I'm inclined to apply to bpf tree. Objections?
> 
> Up to the maintainer... :)

Applied to bpf, thanks!
diff mbox series

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index 2b3b436ef545..0c1bc6ccfd7f 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -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;