forked from iputils/iputils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping: Lower max allowed -s value back to 127992
This effectively reverts a647e2c. The implementation was wrong (signed integer overflow when -s > INT_MAX * 0.58. a647e2c commit increased value max allowed -s value from 127992 to INT_MAX (2147483647). To have space for this range datalen was changed from signed int to size_t, but it forgot to change other int variables which also work with this data (hold, packlen) to be able to store values > INT_MAX*2/3. But these variables are used as setsockopt() parameter and passing size_t to it is not a good idea: do_ip_setsockopt() and do_ipv6_setsockopt() in kernel net/ipv4/ip_sockglue.c net/ipv6/ipv6_sockglue.c does: if (optlen >= sizeof(int)) { if (copy_from_sockptr(&val, optval, sizeof(val))) return -EFAULT; } If bigger size than sizeof(int) passed, kernel will take a first sizeof(int) bytes from the value and use that. On 64bit the sizeof(int) == 32 and sizeof(size_t) == 64. Therefore kernel takes only the half of the value, which is working on little-endian machines. But on big-endian we will take the upper half of the integer and wrongly interpret the value as 0. Proof that the implementation never worked as expected is that reverting fixes signed integer overflow: $ export CC="clang" $ export CFLAGS="-O0 -g -fsanitize=address,undefined" $ export LDFLAGS="-O0 -g -fsanitize=address,undefined" $ ./configure && make $ ./builddir/ping/ping -s 2147483647 ::1 ../ping/ping6_common.c:317:7: runtime error: signed integer overflow: -2147483641 + -1174404560 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../ping/ping6_common.c:317:7 ./builddir/ping/ping: WARNING: probably, rcvbuf is not enough to hold preload PING ::1 (::1) 2147483647 data bytes $ ./builddir/ping/ping -s 2147483647 127.0.0.1 ../ping/ping.c:997:7: runtime error: signed integer overflow: -2147483641 + -1090518520 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../ping/ping.c:997:7 ./builddir/ping/ping: WARNING: probably, rcvbuf is not enough to hold preload PING 127.0.0.1 (127.0.0.1) 2147483647(2147483675) bytes of data. Fixes: iputils#542 Reported-by: Vladimir Ryabokon <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Reviewed-by: Benjamin Poirier <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
- Loading branch information
Showing
5 changed files
with
25 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters