From: Xin Long Date: Wed, 3 Feb 2016 15:33:30 +0000 (+0800) Subject: sctp: translate network order to host order when users get a hmacid X-Git-Tag: v3.2.78~13 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff_plain;h=152e8fcbc0e7102a037b0dfd7551bb95e289ce16 sctp: translate network order to host order when users get a hmacid commit 7a84bd46647ff181eb2659fdc99590e6f16e501d upstream. Commit ed5a377d87dc ("sctp: translate host order to network order when setting a hmacid") corrected the hmacid byte-order when setting a hmacid. but the same issue also exists on getting a hmacid. We fix it by changing hmacids to host order when users get them with getsockopt. Fixes: Commit ed5a377d87dc ("sctp: translate host order to network order when setting a hmacid") Signed-off-by: Xin Long Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- diff --git a/net/sctp/socket.c b/net/sctp/socket.c index bb8c3b4e7feb..5b0e16cfaff5 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -5309,6 +5309,7 @@ static int sctp_getsockopt_hmac_ident(struct sock *sk, int len, struct sctp_hmac_algo_param *hmacs; __u16 data_len = 0; u32 num_idents; + int i; if (!sctp_auth_enable) return -EACCES; @@ -5326,8 +5327,12 @@ static int sctp_getsockopt_hmac_ident(struct sock *sk, int len, return -EFAULT; if (put_user(num_idents, &p->shmac_num_idents)) return -EFAULT; - if (copy_to_user(p->shmac_idents, hmacs->hmac_ids, data_len)) - return -EFAULT; + for (i = 0; i < num_idents; i++) { + __u16 hmacid = ntohs(hmacs->hmac_ids[i]); + + if (copy_to_user(&p->shmac_idents[i], &hmacid, sizeof(__u16))) + return -EFAULT; + } return 0; }