Skip to content

Commit

Permalink
mptcp: Avoid NULL dereference in mptcp_getsockopt_subflow_addrs()
Browse files Browse the repository at this point in the history
Coverity complains of a possible NULL dereference in
mptcp_getsockopt_subflow_addrs():

 861       } else if (sk->sk_family == AF_INET6) {
    	3. returned_null: inet6_sk returns NULL. [show details]
    	4. var_assigned: Assigning: np = NULL return value from inet6_sk.
 862                const struct ipv6_pinfo *np = inet6_sk(sk);

Fix this by checking for NULL.

Closes: #231
Fixes: c11c590 ("mptcp: add MPTCP_SUBFLOW_ADDRS getsockopt support")
Cc: Florian Westphal <[email protected]>
Signed-off-by: Tim Gardner <[email protected]>
[mjm: Added WARN_ON_ONCE() to the unexpected case]
Signed-off-by: Mat Martineau <[email protected]>
  • Loading branch information
rtg-canonical authored and jenkins-tessares committed Oct 16, 2021
1 parent 004b3bc commit f601f9b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ static void mptcp_get_sub_addrs(const struct sock *sk, struct mptcp_subflow_addr
} else if (sk->sk_family == AF_INET6) {
const struct ipv6_pinfo *np = inet6_sk(sk);

if (WARN_ON_ONCE(!np))
return;

a->sin6_local.sin6_family = AF_INET6;
a->sin6_local.sin6_port = inet->inet_sport;

Expand Down

0 comments on commit f601f9b

Please sign in to comment.