Skip to content

Commit a47e598

Browse files
edumazetkuba-moo
authored andcommitted
dccp: fix data-race around dp->dccps_mss_cache
dccp_sendmsg() reads dp->dccps_mss_cache before locking the socket. Same thing in do_dccp_getsockopt(). Add READ_ONCE()/WRITE_ONCE() annotations, and change dccp_sendmsg() to check again dccps_mss_cache after socket is locked. Fixes: 7c65787 ("[DCCP]: Initial implementation") Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20230803163021.2958262-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent fc2ea6a commit a47e598

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

net/dccp/output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
187187

188188
/* And store cached results */
189189
icsk->icsk_pmtu_cookie = pmtu;
190-
dp->dccps_mss_cache = cur_mps;
190+
WRITE_ONCE(dp->dccps_mss_cache, cur_mps);
191191

192192
return cur_mps;
193193
}

net/dccp/proto.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static int do_dccp_getsockopt(struct sock *sk, int level, int optname,
630630
return dccp_getsockopt_service(sk, len,
631631
(__be32 __user *)optval, optlen);
632632
case DCCP_SOCKOPT_GET_CUR_MPS:
633-
val = dp->dccps_mss_cache;
633+
val = READ_ONCE(dp->dccps_mss_cache);
634634
break;
635635
case DCCP_SOCKOPT_AVAILABLE_CCIDS:
636636
return ccid_getsockopt_builtin_ccids(sk, len, optval, optlen);
@@ -739,7 +739,7 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
739739

740740
trace_dccp_probe(sk, len);
741741

742-
if (len > dp->dccps_mss_cache)
742+
if (len > READ_ONCE(dp->dccps_mss_cache))
743743
return -EMSGSIZE;
744744

745745
lock_sock(sk);
@@ -772,6 +772,12 @@ int dccp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
772772
goto out_discard;
773773
}
774774

775+
/* We need to check dccps_mss_cache after socket is locked. */
776+
if (len > dp->dccps_mss_cache) {
777+
rc = -EMSGSIZE;
778+
goto out_discard;
779+
}
780+
775781
skb_reserve(skb, sk->sk_prot->max_header);
776782
rc = memcpy_from_msg(skb_put(skb, len), msg, len);
777783
if (rc != 0)

0 commit comments

Comments
 (0)