Skip to content

Commit

Permalink
ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg
Browse files Browse the repository at this point in the history
[ Upstream commit f638a84 ]

When len >= INT_MAX - transhdrlen, ulen = len + transhdrlen will be
overflow. To fix, we can follow what udpv6 does and subtract the
transhdrlen from the max.

Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Link: https://lore.kernel.org/r/20220607120028.845916-2-wangyufen@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
wangyufen316 authored and gregkh committed Jun 22, 2022
1 parent 0eeec1a commit b8879ca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/l2tp/l2tp_ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,15 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
struct ipcm6_cookie ipc6;
int addr_len = msg->msg_namelen;
int transhdrlen = 4; /* zero session-id */
int ulen = len + transhdrlen;
int ulen;
int err;

/* Rough check on arithmetic overflow,
* better check is made in ip6_append_data().
*/
if (len > INT_MAX)
if (len > INT_MAX - transhdrlen)
return -EMSGSIZE;
ulen = len + transhdrlen;

/* Mirror BSD error message compatibility */
if (msg->msg_flags & MSG_OOB)
Expand Down

0 comments on commit b8879ca

Please sign in to comment.