Commit dd9082f4 authored by Alexander Aring's avatar Alexander Aring Committed by David S. Miller

net: sock: fix in-kernel mark setting

This patch fixes the in-kernel mark setting by doing an additional
sk_dst_reset() which was introduced by commit 50254256 ("sock: Reset
dst when changing sk_mark via setsockopt"). The code is now shared to
avoid any further suprises when changing the socket mark value.

Fixes: 84d1c617 ("net: sock: add sock_set_mark")
Reported-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarAlexander Aring <aahringo@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4ef8d857
...@@ -815,10 +815,18 @@ void sock_set_rcvbuf(struct sock *sk, int val) ...@@ -815,10 +815,18 @@ void sock_set_rcvbuf(struct sock *sk, int val)
} }
EXPORT_SYMBOL(sock_set_rcvbuf); EXPORT_SYMBOL(sock_set_rcvbuf);
static void __sock_set_mark(struct sock *sk, u32 val)
{
if (val != sk->sk_mark) {
sk->sk_mark = val;
sk_dst_reset(sk);
}
}
void sock_set_mark(struct sock *sk, u32 val) void sock_set_mark(struct sock *sk, u32 val)
{ {
lock_sock(sk); lock_sock(sk);
sk->sk_mark = val; __sock_set_mark(sk, val);
release_sock(sk); release_sock(sk);
} }
EXPORT_SYMBOL(sock_set_mark); EXPORT_SYMBOL(sock_set_mark);
...@@ -1126,10 +1134,10 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -1126,10 +1134,10 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_MARK: case SO_MARK:
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) { if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
ret = -EPERM; ret = -EPERM;
} else if (val != sk->sk_mark) { break;
sk->sk_mark = val;
sk_dst_reset(sk);
} }
__sock_set_mark(sk, val);
break; break;
case SO_RXQ_OVFL: case SO_RXQ_OVFL:
......
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