Commit 3c5b4d69 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

net: annotate data-races around sk->sk_mark



sk->sk_mark is often read while another thread could change the value.

Fixes: 4a19ec58 ("[NET]: Introducing socket mark socket option.")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b4b55325
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -107,11 +107,12 @@ static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)

static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb)
{
	if (!sk->sk_mark &&
	    READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept))
	u32 mark = READ_ONCE(sk->sk_mark);

	if (!mark && READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept))
		return skb->mark;

	return sk->sk_mark;
	return mark;
}

static inline int inet_request_bound_dev_if(const struct sock *sk,
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
{
	ipcm_init(ipcm);

	ipcm->sockc.mark = inet->sk.sk_mark;
	ipcm->sockc.mark = READ_ONCE(inet->sk.sk_mark);
	ipcm->sockc.tsflags = inet->sk.sk_tsflags;
	ipcm->oif = READ_ONCE(inet->sk.sk_bound_dev_if);
	ipcm->addr = inet->inet_saddr;
+2 −2
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi
						   __be16 dport, __be16 sport,
						   __u8 proto, __u8 tos, int oif)
{
	flowi4_init_output(fl4, oif, sk ? sk->sk_mark : 0, tos,
	flowi4_init_output(fl4, oif, sk ? READ_ONCE(sk->sk_mark) : 0, tos,
			   RT_SCOPE_UNIVERSE, proto,
			   sk ? inet_sk_flowi_flags(sk) : 0,
			   daddr, saddr, dport, sport, sock_net_uid(net, sk));
@@ -301,7 +301,7 @@ static inline void ip_route_connect_init(struct flowi4 *fl4, __be32 dst,
	if (inet_sk(sk)->transparent)
		flow_flags |= FLOWI_FLAG_ANYSRC;

	flowi4_init_output(fl4, oif, sk->sk_mark, ip_sock_rt_tos(sk),
	flowi4_init_output(fl4, oif, READ_ONCE(sk->sk_mark), ip_sock_rt_tos(sk),
			   ip_sock_rt_scope(sk), protocol, flow_flags, dst,
			   src, dport, sport, sk->sk_uid);
}
+1 −1
Original line number Diff line number Diff line
@@ -865,7 +865,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)

	skb->dev = dev;
	skb->priority = sk->sk_priority;
	skb->mark = sk->sk_mark;
	skb->mark = READ_ONCE(sk->sk_mark);
	skb->tstamp = sockc.transmit_time;

	skb_setup_tx_timestamp(skb, sockc.tsflags);
+2 −2
Original line number Diff line number Diff line
@@ -990,7 +990,7 @@ EXPORT_SYMBOL(sock_set_rcvbuf);
static void __sock_set_mark(struct sock *sk, u32 val)
{
	if (val != sk->sk_mark) {
		sk->sk_mark = val;
		WRITE_ONCE(sk->sk_mark, val);
		sk_dst_reset(sk);
	}
}
@@ -1851,7 +1851,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
							 optval, optlen, len);

	case SO_MARK:
		v.val = sk->sk_mark;
		v.val = READ_ONCE(sk->sk_mark);
		break;

	case SO_RCVMARK:
Loading