diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2013-11-18 01:07:45 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-11-18 16:02:03 -0500 |
commit | cf970c002d270c36202bd5b9c2804d3097a52da0 (patch) | |
tree | 5a8f07507f36caef9274c29504f428fef07f9760 | |
parent | 4861292f730d7c461758575e2557e285a1d4521e (diff) |
ping: prevent NULL pointer dereference on write to msg_name
A plain read() on a socket does set msg->msg_name to NULL. So check for
NULL pointer first.
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/ping.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index aacefa0caa36..91bfe0437e7a 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c | |||
@@ -870,11 +870,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
870 | if (family == AF_INET) { | 870 | if (family == AF_INET) { |
871 | struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; | 871 | struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; |
872 | 872 | ||
873 | sin->sin_family = AF_INET; | 873 | if (sin) { |
874 | sin->sin_port = 0 /* skb->h.uh->source */; | 874 | sin->sin_family = AF_INET; |
875 | sin->sin_addr.s_addr = ip_hdr(skb)->saddr; | 875 | sin->sin_port = 0 /* skb->h.uh->source */; |
876 | memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); | 876 | sin->sin_addr.s_addr = ip_hdr(skb)->saddr; |
877 | *addr_len = sizeof(*sin); | 877 | memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); |
878 | *addr_len = sizeof(*sin); | ||
879 | } | ||
878 | 880 | ||
879 | if (isk->cmsg_flags) | 881 | if (isk->cmsg_flags) |
880 | ip_cmsg_recv(msg, skb); | 882 | ip_cmsg_recv(msg, skb); |
@@ -886,16 +888,18 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
886 | struct sockaddr_in6 *sin6 = | 888 | struct sockaddr_in6 *sin6 = |
887 | (struct sockaddr_in6 *)msg->msg_name; | 889 | (struct sockaddr_in6 *)msg->msg_name; |
888 | 890 | ||
889 | sin6->sin6_family = AF_INET6; | 891 | if (sin6) { |
890 | sin6->sin6_port = 0; | 892 | sin6->sin6_family = AF_INET6; |
891 | sin6->sin6_addr = ip6->saddr; | 893 | sin6->sin6_port = 0; |
892 | sin6->sin6_flowinfo = 0; | 894 | sin6->sin6_addr = ip6->saddr; |
893 | if (np->sndflow) | 895 | sin6->sin6_flowinfo = 0; |
894 | sin6->sin6_flowinfo = ip6_flowinfo(ip6); | 896 | if (np->sndflow) |
895 | 897 | sin6->sin6_flowinfo = ip6_flowinfo(ip6); | |
896 | sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr, | 898 | sin6->sin6_scope_id = |
897 | IP6CB(skb)->iif); | 899 | ipv6_iface_scope_id(&sin6->sin6_addr, |
898 | *addr_len = sizeof(*sin6); | 900 | IP6CB(skb)->iif); |
901 | *addr_len = sizeof(*sin6); | ||
902 | } | ||
899 | 903 | ||
900 | if (inet6_sk(sk)->rxopt.all) | 904 | if (inet6_sk(sk)->rxopt.all) |
901 | pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb); | 905 | pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb); |