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/sctp/socket.c | |
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/sctp/socket.c')
-rw-r--r-- | net/sctp/socket.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 89af37a6c871..c8d05758661d 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -2027,7 +2027,8 @@ out: | |||
2027 | * instead a error will be indicated to the user. | 2027 | * instead a error will be indicated to the user. |
2028 | */ | 2028 | */ |
2029 | static int sctp_setsockopt_disable_fragments(struct sock *sk, | 2029 | static int sctp_setsockopt_disable_fragments(struct sock *sk, |
2030 | char __user *optval, int optlen) | 2030 | char __user *optval, |
2031 | unsigned int optlen) | ||
2031 | { | 2032 | { |
2032 | int val; | 2033 | int val; |
2033 | 2034 | ||
@@ -2043,7 +2044,7 @@ static int sctp_setsockopt_disable_fragments(struct sock *sk, | |||
2043 | } | 2044 | } |
2044 | 2045 | ||
2045 | static int sctp_setsockopt_events(struct sock *sk, char __user *optval, | 2046 | static int sctp_setsockopt_events(struct sock *sk, char __user *optval, |
2046 | int optlen) | 2047 | unsigned int optlen) |
2047 | { | 2048 | { |
2048 | if (optlen > sizeof(struct sctp_event_subscribe)) | 2049 | if (optlen > sizeof(struct sctp_event_subscribe)) |
2049 | return -EINVAL; | 2050 | return -EINVAL; |
@@ -2064,7 +2065,7 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval, | |||
2064 | * association is closed. | 2065 | * association is closed. |
2065 | */ | 2066 | */ |
2066 | static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, | 2067 | static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, |
2067 | int optlen) | 2068 | unsigned int optlen) |
2068 | { | 2069 | { |
2069 | struct sctp_sock *sp = sctp_sk(sk); | 2070 | struct sctp_sock *sp = sctp_sk(sk); |
2070 | 2071 | ||
@@ -2318,7 +2319,8 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params, | |||
2318 | } | 2319 | } |
2319 | 2320 | ||
2320 | static int sctp_setsockopt_peer_addr_params(struct sock *sk, | 2321 | static int sctp_setsockopt_peer_addr_params(struct sock *sk, |
2321 | char __user *optval, int optlen) | 2322 | char __user *optval, |
2323 | unsigned int optlen) | ||
2322 | { | 2324 | { |
2323 | struct sctp_paddrparams params; | 2325 | struct sctp_paddrparams params; |
2324 | struct sctp_transport *trans = NULL; | 2326 | struct sctp_transport *trans = NULL; |
@@ -2430,7 +2432,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, | |||
2430 | */ | 2432 | */ |
2431 | 2433 | ||
2432 | static int sctp_setsockopt_delayed_ack(struct sock *sk, | 2434 | static int sctp_setsockopt_delayed_ack(struct sock *sk, |
2433 | char __user *optval, int optlen) | 2435 | char __user *optval, unsigned int optlen) |
2434 | { | 2436 | { |
2435 | struct sctp_sack_info params; | 2437 | struct sctp_sack_info params; |
2436 | struct sctp_transport *trans = NULL; | 2438 | struct sctp_transport *trans = NULL; |
@@ -2546,7 +2548,7 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, | |||
2546 | * by the change). With TCP-style sockets, this option is inherited by | 2548 | * by the change). With TCP-style sockets, this option is inherited by |
2547 | * sockets derived from a listener socket. | 2549 | * sockets derived from a listener socket. |
2548 | */ | 2550 | */ |
2549 | static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int optlen) | 2551 | static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, unsigned int optlen) |
2550 | { | 2552 | { |
2551 | struct sctp_initmsg sinit; | 2553 | struct sctp_initmsg sinit; |
2552 | struct sctp_sock *sp = sctp_sk(sk); | 2554 | struct sctp_sock *sp = sctp_sk(sk); |
@@ -2583,7 +2585,8 @@ static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int opt | |||
2583 | * to this call if the caller is using the UDP model. | 2585 | * to this call if the caller is using the UDP model. |
2584 | */ | 2586 | */ |
2585 | static int sctp_setsockopt_default_send_param(struct sock *sk, | 2587 | static int sctp_setsockopt_default_send_param(struct sock *sk, |
2586 | char __user *optval, int optlen) | 2588 | char __user *optval, |
2589 | unsigned int optlen) | ||
2587 | { | 2590 | { |
2588 | struct sctp_sndrcvinfo info; | 2591 | struct sctp_sndrcvinfo info; |
2589 | struct sctp_association *asoc; | 2592 | struct sctp_association *asoc; |
@@ -2622,7 +2625,7 @@ static int sctp_setsockopt_default_send_param(struct sock *sk, | |||
2622 | * association peer's addresses. | 2625 | * association peer's addresses. |
2623 | */ | 2626 | */ |
2624 | static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, | 2627 | static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, |
2625 | int optlen) | 2628 | unsigned int optlen) |
2626 | { | 2629 | { |
2627 | struct sctp_prim prim; | 2630 | struct sctp_prim prim; |
2628 | struct sctp_transport *trans; | 2631 | struct sctp_transport *trans; |
@@ -2651,7 +2654,7 @@ static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, | |||
2651 | * integer boolean flag. | 2654 | * integer boolean flag. |
2652 | */ | 2655 | */ |
2653 | static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, | 2656 | static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, |
2654 | int optlen) | 2657 | unsigned int optlen) |
2655 | { | 2658 | { |
2656 | int val; | 2659 | int val; |
2657 | 2660 | ||
@@ -2676,7 +2679,8 @@ static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, | |||
2676 | * be changed. | 2679 | * be changed. |
2677 | * | 2680 | * |
2678 | */ | 2681 | */ |
2679 | static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int optlen) { | 2682 | static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, unsigned int optlen) |
2683 | { | ||
2680 | struct sctp_rtoinfo rtoinfo; | 2684 | struct sctp_rtoinfo rtoinfo; |
2681 | struct sctp_association *asoc; | 2685 | struct sctp_association *asoc; |
2682 | 2686 | ||
@@ -2728,7 +2732,7 @@ static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int opt | |||
2728 | * See [SCTP] for more information. | 2732 | * See [SCTP] for more information. |
2729 | * | 2733 | * |
2730 | */ | 2734 | */ |
2731 | static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int optlen) | 2735 | static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, unsigned int optlen) |
2732 | { | 2736 | { |
2733 | 2737 | ||
2734 | struct sctp_assocparams assocparams; | 2738 | struct sctp_assocparams assocparams; |
@@ -2800,7 +2804,7 @@ static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int o | |||
2800 | * addresses and a user will receive both PF_INET6 and PF_INET type | 2804 | * addresses and a user will receive both PF_INET6 and PF_INET type |
2801 | * addresses on the socket. | 2805 | * addresses on the socket. |
2802 | */ | 2806 | */ |
2803 | static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int optlen) | 2807 | static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, unsigned int optlen) |
2804 | { | 2808 | { |
2805 | int val; | 2809 | int val; |
2806 | struct sctp_sock *sp = sctp_sk(sk); | 2810 | struct sctp_sock *sp = sctp_sk(sk); |
@@ -2844,7 +2848,7 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int op | |||
2844 | * changed (effecting future associations only). | 2848 | * changed (effecting future associations only). |
2845 | * assoc_value: This parameter specifies the maximum size in bytes. | 2849 | * assoc_value: This parameter specifies the maximum size in bytes. |
2846 | */ | 2850 | */ |
2847 | static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) | 2851 | static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen) |
2848 | { | 2852 | { |
2849 | struct sctp_assoc_value params; | 2853 | struct sctp_assoc_value params; |
2850 | struct sctp_association *asoc; | 2854 | struct sctp_association *asoc; |
@@ -2899,7 +2903,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optl | |||
2899 | * set primary request: | 2903 | * set primary request: |
2900 | */ | 2904 | */ |
2901 | static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, | 2905 | static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, |
2902 | int optlen) | 2906 | unsigned int optlen) |
2903 | { | 2907 | { |
2904 | struct sctp_sock *sp; | 2908 | struct sctp_sock *sp; |
2905 | struct sctp_endpoint *ep; | 2909 | struct sctp_endpoint *ep; |
@@ -2950,7 +2954,7 @@ static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optva | |||
2950 | } | 2954 | } |
2951 | 2955 | ||
2952 | static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval, | 2956 | static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval, |
2953 | int optlen) | 2957 | unsigned int optlen) |
2954 | { | 2958 | { |
2955 | struct sctp_setadaptation adaptation; | 2959 | struct sctp_setadaptation adaptation; |
2956 | 2960 | ||
@@ -2979,7 +2983,7 @@ static int sctp_setsockopt_adaptation_layer(struct sock *sk, char __user *optval | |||
2979 | * saved with outbound messages. | 2983 | * saved with outbound messages. |
2980 | */ | 2984 | */ |
2981 | static int sctp_setsockopt_context(struct sock *sk, char __user *optval, | 2985 | static int sctp_setsockopt_context(struct sock *sk, char __user *optval, |
2982 | int optlen) | 2986 | unsigned int optlen) |
2983 | { | 2987 | { |
2984 | struct sctp_assoc_value params; | 2988 | struct sctp_assoc_value params; |
2985 | struct sctp_sock *sp; | 2989 | struct sctp_sock *sp; |
@@ -3030,7 +3034,7 @@ static int sctp_setsockopt_context(struct sock *sk, char __user *optval, | |||
3030 | */ | 3034 | */ |
3031 | static int sctp_setsockopt_fragment_interleave(struct sock *sk, | 3035 | static int sctp_setsockopt_fragment_interleave(struct sock *sk, |
3032 | char __user *optval, | 3036 | char __user *optval, |
3033 | int optlen) | 3037 | unsigned int optlen) |
3034 | { | 3038 | { |
3035 | int val; | 3039 | int val; |
3036 | 3040 | ||
@@ -3063,7 +3067,7 @@ static int sctp_setsockopt_fragment_interleave(struct sock *sk, | |||
3063 | */ | 3067 | */ |
3064 | static int sctp_setsockopt_partial_delivery_point(struct sock *sk, | 3068 | static int sctp_setsockopt_partial_delivery_point(struct sock *sk, |
3065 | char __user *optval, | 3069 | char __user *optval, |
3066 | int optlen) | 3070 | unsigned int optlen) |
3067 | { | 3071 | { |
3068 | u32 val; | 3072 | u32 val; |
3069 | 3073 | ||
@@ -3096,7 +3100,7 @@ static int sctp_setsockopt_partial_delivery_point(struct sock *sk, | |||
3096 | */ | 3100 | */ |
3097 | static int sctp_setsockopt_maxburst(struct sock *sk, | 3101 | static int sctp_setsockopt_maxburst(struct sock *sk, |
3098 | char __user *optval, | 3102 | char __user *optval, |
3099 | int optlen) | 3103 | unsigned int optlen) |
3100 | { | 3104 | { |
3101 | struct sctp_assoc_value params; | 3105 | struct sctp_assoc_value params; |
3102 | struct sctp_sock *sp; | 3106 | struct sctp_sock *sp; |
@@ -3140,8 +3144,8 @@ static int sctp_setsockopt_maxburst(struct sock *sk, | |||
3140 | * will only effect future associations on the socket. | 3144 | * will only effect future associations on the socket. |
3141 | */ | 3145 | */ |
3142 | static int sctp_setsockopt_auth_chunk(struct sock *sk, | 3146 | static int sctp_setsockopt_auth_chunk(struct sock *sk, |
3143 | char __user *optval, | 3147 | char __user *optval, |
3144 | int optlen) | 3148 | unsigned int optlen) |
3145 | { | 3149 | { |
3146 | struct sctp_authchunk val; | 3150 | struct sctp_authchunk val; |
3147 | 3151 | ||
@@ -3172,8 +3176,8 @@ static int sctp_setsockopt_auth_chunk(struct sock *sk, | |||
3172 | * endpoint requires the peer to use. | 3176 | * endpoint requires the peer to use. |
3173 | */ | 3177 | */ |
3174 | static int sctp_setsockopt_hmac_ident(struct sock *sk, | 3178 | static int sctp_setsockopt_hmac_ident(struct sock *sk, |
3175 | char __user *optval, | 3179 | char __user *optval, |
3176 | int optlen) | 3180 | unsigned int optlen) |
3177 | { | 3181 | { |
3178 | struct sctp_hmacalgo *hmacs; | 3182 | struct sctp_hmacalgo *hmacs; |
3179 | u32 idents; | 3183 | u32 idents; |
@@ -3215,7 +3219,7 @@ out: | |||
3215 | */ | 3219 | */ |
3216 | static int sctp_setsockopt_auth_key(struct sock *sk, | 3220 | static int sctp_setsockopt_auth_key(struct sock *sk, |
3217 | char __user *optval, | 3221 | char __user *optval, |
3218 | int optlen) | 3222 | unsigned int optlen) |
3219 | { | 3223 | { |
3220 | struct sctp_authkey *authkey; | 3224 | struct sctp_authkey *authkey; |
3221 | struct sctp_association *asoc; | 3225 | struct sctp_association *asoc; |
@@ -3260,8 +3264,8 @@ out: | |||
3260 | * the association shared key. | 3264 | * the association shared key. |
3261 | */ | 3265 | */ |
3262 | static int sctp_setsockopt_active_key(struct sock *sk, | 3266 | static int sctp_setsockopt_active_key(struct sock *sk, |
3263 | char __user *optval, | 3267 | char __user *optval, |
3264 | int optlen) | 3268 | unsigned int optlen) |
3265 | { | 3269 | { |
3266 | struct sctp_authkeyid val; | 3270 | struct sctp_authkeyid val; |
3267 | struct sctp_association *asoc; | 3271 | struct sctp_association *asoc; |
@@ -3288,8 +3292,8 @@ static int sctp_setsockopt_active_key(struct sock *sk, | |||
3288 | * This set option will delete a shared secret key from use. | 3292 | * This set option will delete a shared secret key from use. |
3289 | */ | 3293 | */ |
3290 | static int sctp_setsockopt_del_key(struct sock *sk, | 3294 | static int sctp_setsockopt_del_key(struct sock *sk, |
3291 | char __user *optval, | 3295 | char __user *optval, |
3292 | int optlen) | 3296 | unsigned int optlen) |
3293 | { | 3297 | { |
3294 | struct sctp_authkeyid val; | 3298 | struct sctp_authkeyid val; |
3295 | struct sctp_association *asoc; | 3299 | struct sctp_association *asoc; |
@@ -3332,7 +3336,7 @@ static int sctp_setsockopt_del_key(struct sock *sk, | |||
3332 | * optlen - the size of the buffer. | 3336 | * optlen - the size of the buffer. |
3333 | */ | 3337 | */ |
3334 | SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname, | 3338 | SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname, |
3335 | char __user *optval, int optlen) | 3339 | char __user *optval, unsigned int optlen) |
3336 | { | 3340 | { |
3337 | int retval = 0; | 3341 | int retval = 0; |
3338 | 3342 | ||