mptcp: Avoid NULL dereference in mptcp_getsockopt_subflow_addrs()
Subsystems (3)
PATCH 1/1 mptcp: Avoid NULL dereference in mptcp_getsockopt_subflow_addrs()
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.
[ I'm not at all sure this is the right thing to do since the final result is to return garbage to user space in mptcp_getsockopt_subflow_addrs(). Is this one of those cases where inet6_sk() can't fail ?]
--- net/mptcp/sockopt.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/sockopt.c +3 -0
@@ -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 (!np) +return ; + a->sin6_local.sin6_family =AF_INET6 ; a->sin6_local.sin6_port = inet->inet_sport;
Signature · 1 line
2.33.0
Quoted 19 lines · Tim Gardner
Coverity complains of a possible NULL dereference in
mptcp_getsockopt_subflow_addrs():861 } else if (
sk->sk_family==AF_INET6) {
3.returned_null:inet6_skreturns NULL. [show details]
4.var_assigned: Assigning: np = NULL return value frominet6_sk.
862 const structipv6_pinfo*np =inet6_sk(sk);Fix this by checking for NULL.
Cc Mat Martineau <[email protected]>Cc Matthieu Baerts <[email protected]>Cc "David S. Miller" <[email protected]>Cc Jakub Kicinski <[email protected]>Signed-off-by Tim Gardner <[email protected]>
Quoted 3 lines
[ I'm not at all sure this is the right thing to do since the final result is to return garbage to user space in
mptcp_getsockopt_subflow_addrs(). Is this one of those cases whereinet6_sk()can't fail ?]
Hi Tim -
Thanks for noticing this and proposing a fix.
As you commented, this isn't the right change to merge since mptcp_getsockopt_subflow_addrs() would copy garbage.
This block of code already checks that CONFIG_IPV6 is enabled, so the question is whether sk_fullsock() would return false because the subflow is in TCP_TIME_WAIT or TCP_NEW_SYN_RECV. The caller is iterating over sockets in the MPTCP socket's conn_list, which does not contain request_socks (so there are no sockets in the TCP_NEW_SYN_RECV state).
TCP subflow sockets are normally removed from the conn_list before they are closed by their parent MPTCP socket, but I need to double-check for corner cases. I created a github issue to track this: https://github.com/multipath-tcp/mptcp_net-next/issues/231
Thanks,
Mat
Quoted 22 lines
---
net/mptcp/sockopt.c| 3 +++1 file changed, 3 insertions(+)net/mptcp/sockopt.c +3
-0@@ -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 (!np) +return ; + a->sin6_local.sin6_family =AF_INET6 ; a->sin6_local.sin6_port = inet->inet_sport;Signature · 1 line
2.33.0
--
Mat Martineau
Intel
Quoted 27 lines · Mat Martineau
Quoted 19 lines · Tim Gardner
Coverity complains of a possible NULL dereference in
mptcp_getsockopt_subflow_addrs():861 } else if (
sk->sk_family==AF_INET6) {
3.returned_null:inet6_skreturns NULL. [show details]
4.var_assigned: Assigning: np = NULL return value frominet6_sk.
862 const structipv6_pinfo*np =inet6_sk(sk);Fix this by checking for NULL.
Cc Mat Martineau <[email protected]>Cc Matthieu Baerts <[email protected]>Cc "David S. Miller" <[email protected]>Cc Jakub Kicinski <[email protected]>Signed-off-by Tim Gardner <[email protected]>Quoted 3 lines
[ I'm not at all sure this is the right thing to do since the final result is to return garbage to user space in
mptcp_getsockopt_subflow_addrs(). Is this one of those cases whereinet6_sk()can't fail ?]Hi Tim -
Quoted 8 lines
Thanks for noticing this and proposing a fix.
As you commented, this isn't the right change to merge since
mptcp_getsockopt_subflow_addrs()would copy garbage.This block of code already checks that
CONFIG_IPV6is enabled, so the question is whethersk_fullsock()would return false because the subflow is inTCP_TIME_WAITorTCP_NEW_SYN_RECV. The caller is iterating over sockets in the MPTCP socket'sconn_list, which does not containrequest_socks(so there are no sockets in theTCP_NEW_SYN_RECVstate).TCP subflow sockets are normally removed from the
conn_listbefore they are closed by their parent MPTCP socket, but I need to double-check for corner cases. I created a github issue to track this: https://github.com/multipath-tcp/mptcp_net-next/issues/231
Tim,
Could you submit a v2 of this patch? Paolo took a look and the condition should not happen, but adding the NULL check would be a good idea and returning early as your patch does is ok. The data copied after the early return will be zeroed and look like the address family is AF_UNSPEC.
Could you add a
tag and make the one change below?
Quoted 14 lines
Quoted 14 lines
---
net/mptcp/sockopt.c| 3 +++1 file changed, 3 insertions(+)net/mptcp/sockopt.c +0
-0@@ -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);
Quoted 1 line
net/mptcp/sockopt.c static void mptcp_get_sub_addrs(const struct sock *sk, struct mptcp_subflow_addr · line 864
Quoted 1 line
net/mptcp/sockopt.c +1
-0+if (!np)
This could be
if (WARN_ON_ONCE(!np))
(as suggested by Paolo) to make it clear the condition is unexpected.
Quoted 7 lines
Quoted 7 lines
net/mptcp/sockopt.c +2
-0+return ; +a->sin6_local.sin6_family = AF_INET6; a->sin6_local.sin6_port = inet->inet_sport;Signature · 1 line
2.33.0
Thanks,
--
Mat Martineau
Intel