Skip to content

Commit

Permalink
net: sock: fix in-kernel mark setting
Browse files Browse the repository at this point in the history
[ Upstream commit dd9082f ]

This patch fixes the in-kernel mark setting by doing an additional
sk_dst_reset() which was introduced by commit 5025425 ("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: 84d1c61 ("net: sock: add sock_set_mark")
Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Alexander Aring authored and gregkh committed Jun 10, 2021
1 parent 09fdb67 commit a5de17b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions net/core/sock.c
Expand Up @@ -807,10 +807,18 @@ void sock_set_rcvbuf(struct sock *sk, int val)
}
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)
{
lock_sock(sk);
sk->sk_mark = val;
__sock_set_mark(sk, val);
release_sock(sk);
}
EXPORT_SYMBOL(sock_set_mark);
Expand Down Expand Up @@ -1118,10 +1126,10 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_MARK:
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
ret = -EPERM;
} else if (val != sk->sk_mark) {
sk->sk_mark = val;
sk_dst_reset(sk);
break;
}

__sock_set_mark(sk, val);
break;

case SO_RXQ_OVFL:
Expand Down

0 comments on commit a5de17b

Please sign in to comment.