sctp: add verification checks to SCTP_AUTH_KEY option

The structure used for SCTP_AUTH_KEY option contains a
length that needs to be verfied to prevent buffer overflow
conditions. Spoted by Eugene Teo <eteo@redhat.com>.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Vlad Yasevich and committed by David S. Miller 30c2235c f410a1fb

+9
+4
net/sctp/auth.c
··· 80 80 { 81 81 struct sctp_auth_bytes *key; 82 82 83 + /* Verify that we are not going to overflow INT_MAX */ 84 + if ((INT_MAX - key_len) < sizeof(struct sctp_auth_bytes)) 85 + return NULL; 86 + 83 87 /* Allocate the shared key */ 84 88 key = kmalloc(sizeof(struct sctp_auth_bytes) + key_len, gfp); 85 89 if (!key)
+5
net/sctp/socket.c
··· 3144 3144 goto out; 3145 3145 } 3146 3146 3147 + if (authkey->sca_keylength > optlen) { 3148 + ret = -EINVAL; 3149 + goto out; 3150 + } 3151 + 3147 3152 asoc = sctp_id2assoc(sk, authkey->sca_assoc_id); 3148 3153 if (!asoc && authkey->sca_assoc_id && sctp_style(sk, UDP)) { 3149 3154 ret = -EINVAL;