diff options
author | David S. Miller <davem@davemloft.net> | 2009-09-30 19:12:20 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-09-30 19:12:20 -0400 |
commit | b7058842c940ad2c08dd829b21e5c92ebe3b8758 (patch) | |
tree | 5fe78d599fc345ca0bcd4b083b79095a54b2921b /net/ipv4 | |
parent | eb1cf0f8f7a9e5a6d573d5bd72c015686a042db0 (diff) |
net: Make setsockopt() optlen be unsigned.
This provides safety against negative optlen at the type
level instead of depending upon (sometimes non-trivial)
checks against this sprinkled all over the the place, in
each and every implementation.
Based upon work done by Arjan van de Ven and feedback
from Linus Torvalds.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/inet_connection_sock.c | 2 | ||||
-rw-r--r-- | net/ipv4/ip_sockglue.c | 6 | ||||
-rw-r--r-- | net/ipv4/ipmr.c | 2 | ||||
-rw-r--r-- | net/ipv4/raw.c | 6 | ||||
-rw-r--r-- | net/ipv4/tcp.c | 6 | ||||
-rw-r--r-- | net/ipv4/udp.c | 6 | ||||
-rw-r--r-- | net/ipv4/udp_impl.h | 4 |
7 files changed, 16 insertions, 16 deletions
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 22cd19ee44e5..4351ca2cf0b8 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c | |||
@@ -714,7 +714,7 @@ int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname, | |||
714 | EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt); | 714 | EXPORT_SYMBOL_GPL(inet_csk_compat_getsockopt); |
715 | 715 | ||
716 | int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname, | 716 | int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname, |
717 | char __user *optval, int optlen) | 717 | char __user *optval, unsigned int optlen) |
718 | { | 718 | { |
719 | const struct inet_connection_sock *icsk = inet_csk(sk); | 719 | const struct inet_connection_sock *icsk = inet_csk(sk); |
720 | 720 | ||
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 5a0693576e82..0c0b6e363a20 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c | |||
@@ -440,7 +440,7 @@ out: | |||
440 | */ | 440 | */ |
441 | 441 | ||
442 | static int do_ip_setsockopt(struct sock *sk, int level, | 442 | static int do_ip_setsockopt(struct sock *sk, int level, |
443 | int optname, char __user *optval, int optlen) | 443 | int optname, char __user *optval, unsigned int optlen) |
444 | { | 444 | { |
445 | struct inet_sock *inet = inet_sk(sk); | 445 | struct inet_sock *inet = inet_sk(sk); |
446 | int val = 0, err; | 446 | int val = 0, err; |
@@ -950,7 +950,7 @@ e_inval: | |||
950 | } | 950 | } |
951 | 951 | ||
952 | int ip_setsockopt(struct sock *sk, int level, | 952 | int ip_setsockopt(struct sock *sk, int level, |
953 | int optname, char __user *optval, int optlen) | 953 | int optname, char __user *optval, unsigned int optlen) |
954 | { | 954 | { |
955 | int err; | 955 | int err; |
956 | 956 | ||
@@ -975,7 +975,7 @@ EXPORT_SYMBOL(ip_setsockopt); | |||
975 | 975 | ||
976 | #ifdef CONFIG_COMPAT | 976 | #ifdef CONFIG_COMPAT |
977 | int compat_ip_setsockopt(struct sock *sk, int level, int optname, | 977 | int compat_ip_setsockopt(struct sock *sk, int level, int optname, |
978 | char __user *optval, int optlen) | 978 | char __user *optval, unsigned int optlen) |
979 | { | 979 | { |
980 | int err; | 980 | int err; |
981 | 981 | ||
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index c43ec2d51ce2..630a56df7b47 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -931,7 +931,7 @@ static void mrtsock_destruct(struct sock *sk) | |||
931 | * MOSPF/PIM router set up we can clean this up. | 931 | * MOSPF/PIM router set up we can clean this up. |
932 | */ | 932 | */ |
933 | 933 | ||
934 | int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int optlen) | 934 | int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsigned int optlen) |
935 | { | 935 | { |
936 | int ret; | 936 | int ret; |
937 | struct vifctl vif; | 937 | struct vifctl vif; |
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index ebb1e5848bc6..757c9171e7c2 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -741,7 +741,7 @@ out: return ret; | |||
741 | } | 741 | } |
742 | 742 | ||
743 | static int do_raw_setsockopt(struct sock *sk, int level, int optname, | 743 | static int do_raw_setsockopt(struct sock *sk, int level, int optname, |
744 | char __user *optval, int optlen) | 744 | char __user *optval, unsigned int optlen) |
745 | { | 745 | { |
746 | if (optname == ICMP_FILTER) { | 746 | if (optname == ICMP_FILTER) { |
747 | if (inet_sk(sk)->num != IPPROTO_ICMP) | 747 | if (inet_sk(sk)->num != IPPROTO_ICMP) |
@@ -753,7 +753,7 @@ static int do_raw_setsockopt(struct sock *sk, int level, int optname, | |||
753 | } | 753 | } |
754 | 754 | ||
755 | static int raw_setsockopt(struct sock *sk, int level, int optname, | 755 | static int raw_setsockopt(struct sock *sk, int level, int optname, |
756 | char __user *optval, int optlen) | 756 | char __user *optval, unsigned int optlen) |
757 | { | 757 | { |
758 | if (level != SOL_RAW) | 758 | if (level != SOL_RAW) |
759 | return ip_setsockopt(sk, level, optname, optval, optlen); | 759 | return ip_setsockopt(sk, level, optname, optval, optlen); |
@@ -762,7 +762,7 @@ static int raw_setsockopt(struct sock *sk, int level, int optname, | |||
762 | 762 | ||
763 | #ifdef CONFIG_COMPAT | 763 | #ifdef CONFIG_COMPAT |
764 | static int compat_raw_setsockopt(struct sock *sk, int level, int optname, | 764 | static int compat_raw_setsockopt(struct sock *sk, int level, int optname, |
765 | char __user *optval, int optlen) | 765 | char __user *optval, unsigned int optlen) |
766 | { | 766 | { |
767 | if (level != SOL_RAW) | 767 | if (level != SOL_RAW) |
768 | return compat_ip_setsockopt(sk, level, optname, optval, optlen); | 768 | return compat_ip_setsockopt(sk, level, optname, optval, optlen); |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 21387ebabf00..5a15e7629d8e 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -2032,7 +2032,7 @@ int tcp_disconnect(struct sock *sk, int flags) | |||
2032 | * Socket option code for TCP. | 2032 | * Socket option code for TCP. |
2033 | */ | 2033 | */ |
2034 | static int do_tcp_setsockopt(struct sock *sk, int level, | 2034 | static int do_tcp_setsockopt(struct sock *sk, int level, |
2035 | int optname, char __user *optval, int optlen) | 2035 | int optname, char __user *optval, unsigned int optlen) |
2036 | { | 2036 | { |
2037 | struct tcp_sock *tp = tcp_sk(sk); | 2037 | struct tcp_sock *tp = tcp_sk(sk); |
2038 | struct inet_connection_sock *icsk = inet_csk(sk); | 2038 | struct inet_connection_sock *icsk = inet_csk(sk); |
@@ -2220,7 +2220,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level, | |||
2220 | } | 2220 | } |
2221 | 2221 | ||
2222 | int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, | 2222 | int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, |
2223 | int optlen) | 2223 | unsigned int optlen) |
2224 | { | 2224 | { |
2225 | struct inet_connection_sock *icsk = inet_csk(sk); | 2225 | struct inet_connection_sock *icsk = inet_csk(sk); |
2226 | 2226 | ||
@@ -2232,7 +2232,7 @@ int tcp_setsockopt(struct sock *sk, int level, int optname, char __user *optval, | |||
2232 | 2232 | ||
2233 | #ifdef CONFIG_COMPAT | 2233 | #ifdef CONFIG_COMPAT |
2234 | int compat_tcp_setsockopt(struct sock *sk, int level, int optname, | 2234 | int compat_tcp_setsockopt(struct sock *sk, int level, int optname, |
2235 | char __user *optval, int optlen) | 2235 | char __user *optval, unsigned int optlen) |
2236 | { | 2236 | { |
2237 | if (level != SOL_TCP) | 2237 | if (level != SOL_TCP) |
2238 | return inet_csk_compat_setsockopt(sk, level, optname, | 2238 | return inet_csk_compat_setsockopt(sk, level, optname, |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index ebaaa7f973d7..3326aff65906 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -1359,7 +1359,7 @@ void udp_destroy_sock(struct sock *sk) | |||
1359 | * Socket option code for UDP | 1359 | * Socket option code for UDP |
1360 | */ | 1360 | */ |
1361 | int udp_lib_setsockopt(struct sock *sk, int level, int optname, | 1361 | int udp_lib_setsockopt(struct sock *sk, int level, int optname, |
1362 | char __user *optval, int optlen, | 1362 | char __user *optval, unsigned int optlen, |
1363 | int (*push_pending_frames)(struct sock *)) | 1363 | int (*push_pending_frames)(struct sock *)) |
1364 | { | 1364 | { |
1365 | struct udp_sock *up = udp_sk(sk); | 1365 | struct udp_sock *up = udp_sk(sk); |
@@ -1441,7 +1441,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, | |||
1441 | EXPORT_SYMBOL(udp_lib_setsockopt); | 1441 | EXPORT_SYMBOL(udp_lib_setsockopt); |
1442 | 1442 | ||
1443 | int udp_setsockopt(struct sock *sk, int level, int optname, | 1443 | int udp_setsockopt(struct sock *sk, int level, int optname, |
1444 | char __user *optval, int optlen) | 1444 | char __user *optval, unsigned int optlen) |
1445 | { | 1445 | { |
1446 | if (level == SOL_UDP || level == SOL_UDPLITE) | 1446 | if (level == SOL_UDP || level == SOL_UDPLITE) |
1447 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, | 1447 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, |
@@ -1451,7 +1451,7 @@ int udp_setsockopt(struct sock *sk, int level, int optname, | |||
1451 | 1451 | ||
1452 | #ifdef CONFIG_COMPAT | 1452 | #ifdef CONFIG_COMPAT |
1453 | int compat_udp_setsockopt(struct sock *sk, int level, int optname, | 1453 | int compat_udp_setsockopt(struct sock *sk, int level, int optname, |
1454 | char __user *optval, int optlen) | 1454 | char __user *optval, unsigned int optlen) |
1455 | { | 1455 | { |
1456 | if (level == SOL_UDP || level == SOL_UDPLITE) | 1456 | if (level == SOL_UDP || level == SOL_UDPLITE) |
1457 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, | 1457 | return udp_lib_setsockopt(sk, level, optname, optval, optlen, |
diff --git a/net/ipv4/udp_impl.h b/net/ipv4/udp_impl.h index 9f4a6165f722..aaad650d47d9 100644 --- a/net/ipv4/udp_impl.h +++ b/net/ipv4/udp_impl.h | |||
@@ -11,13 +11,13 @@ extern void __udp4_lib_err(struct sk_buff *, u32, struct udp_table *); | |||
11 | extern int udp_v4_get_port(struct sock *sk, unsigned short snum); | 11 | extern int udp_v4_get_port(struct sock *sk, unsigned short snum); |
12 | 12 | ||
13 | extern int udp_setsockopt(struct sock *sk, int level, int optname, | 13 | extern int udp_setsockopt(struct sock *sk, int level, int optname, |
14 | char __user *optval, int optlen); | 14 | char __user *optval, unsigned int optlen); |
15 | extern int udp_getsockopt(struct sock *sk, int level, int optname, | 15 | extern int udp_getsockopt(struct sock *sk, int level, int optname, |
16 | char __user *optval, int __user *optlen); | 16 | char __user *optval, int __user *optlen); |
17 | 17 | ||
18 | #ifdef CONFIG_COMPAT | 18 | #ifdef CONFIG_COMPAT |
19 | extern int compat_udp_setsockopt(struct sock *sk, int level, int optname, | 19 | extern int compat_udp_setsockopt(struct sock *sk, int level, int optname, |
20 | char __user *optval, int optlen); | 20 | char __user *optval, unsigned int optlen); |
21 | extern int compat_udp_getsockopt(struct sock *sk, int level, int optname, | 21 | extern int compat_udp_getsockopt(struct sock *sk, int level, int optname, |
22 | char __user *optval, int __user *optlen); | 22 | char __user *optval, int __user *optlen); |
23 | #endif | 23 | #endif |