]> Git Repo - linux.git/commitdiff
ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg
authorWang Yufen <[email protected]>
Tue, 7 Jun 2022 12:00:28 +0000 (20:00 +0800)
committerJakub Kicinski <[email protected]>
Wed, 8 Jun 2022 17:56:43 +0000 (10:56 -0700)
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
net/l2tp/l2tp_ip6.c

index c6ff8bf9b55f916e80380bb2e4ea81b11e544a32..9dbd801ddb98c7f0878ffa69fda8113490344fda 100644 (file)
@@ -504,14 +504,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)
This page took 0.056754 seconds and 4 git commands to generate.