From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bl2nam02on0139.outbound.protection.outlook.com ([104.47.38.139]:10688 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753035AbeBCSE0 (ORCPT ); Sat, 3 Feb 2018 13:04:26 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Marcelo Ricardo Leitner , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 106/110] sctp: make use of pre-calculated len Date: Sat, 3 Feb 2018 18:01:34 +0000 Message-ID: <20180203180015.29073-106-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Marcelo Ricardo Leitner [ Upstream commit c76f97c99ae6d26d14c7f0e50e074382bfbc9f98 ] Some sockopt handling functions were calculating the length of the buffer to be written to userspace and then calculating it again when actually writing the buffer, which could lead to some write not using an up-to-date length. This patch updates such places to just make use of the len variable. Also, replace some sizeof(type) to sizeof(var). Signed-off-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/socket.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 978fc7d1cf53..53e3634afea0 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4948,7 +4948,7 @@ static int sctp_getsockopt_autoclose(struct sock *sk,= int len, char __user *optv len =3D sizeof(int); if (put_user(len, optlen)) return -EFAULT; - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int))) + if (copy_to_user(optval, &sctp_sk(sk)->autoclose, len)) return -EFAULT; return 0; } @@ -5579,6 +5579,9 @@ copy_getaddrs: err =3D -EFAULT; goto out; } + /* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too, + * but we can't change it anymore. + */ if (put_user(bytes_copied, optlen)) err =3D -EFAULT; out: @@ -6015,7 +6018,7 @@ static int sctp_getsockopt_maxseg(struct sock *sk, in= t len, params.assoc_id =3D 0; } else if (len >=3D sizeof(struct sctp_assoc_value)) { len =3D sizeof(struct sctp_assoc_value); - if (copy_from_user(¶ms, optval, sizeof(params))) + if (copy_from_user(¶ms, optval, len)) return -EFAULT; } else return -EINVAL; @@ -6185,7 +6188,9 @@ static int sctp_getsockopt_active_key(struct sock *sk= , int len, =20 if (len < sizeof(struct sctp_authkeyid)) return -EINVAL; - if (copy_from_user(&val, optval, sizeof(struct sctp_authkeyid))) + + len =3D sizeof(struct sctp_authkeyid); + if (copy_from_user(&val, optval, len)) return -EFAULT; =20 asoc =3D sctp_id2assoc(sk, val.scact_assoc_id); @@ -6197,7 +6202,6 @@ static int sctp_getsockopt_active_key(struct sock *sk= , int len, else val.scact_keynumber =3D ep->active_key_id; =20 - len =3D sizeof(struct sctp_authkeyid); if (put_user(len, optlen)) return -EFAULT; if (copy_to_user(optval, &val, len)) @@ -6223,7 +6227,7 @@ static int sctp_getsockopt_peer_auth_chunks(struct so= ck *sk, int len, if (len < sizeof(struct sctp_authchunks)) return -EINVAL; =20 - if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks))) + if (copy_from_user(&val, optval, sizeof(val))) return -EFAULT; =20 to =3D p->gauth_chunks; @@ -6268,7 +6272,7 @@ static int sctp_getsockopt_local_auth_chunks(struct s= ock *sk, int len, if (len < sizeof(struct sctp_authchunks)) return -EINVAL; =20 - if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks))) + if (copy_from_user(&val, optval, sizeof(val))) return -EFAULT; =20 to =3D p->gauth_chunks; --=20 2.11.0