Two fixes and fallout
Subsystems (2)
Phil Sutter
reviewercover Two fixes and fallout
Fix two cases of illegal memory access and speed up the testsuite while waiting for results.
Phil Sutter (3):
lib: data: Fix for global-buffer-overflow warning by ASAN
lib: ipset: Avoid 'argv' array overstepping
tests: Reduce testsuite run-time
lib/data.c | 3 +++ lib/ipset.c | 4 ++-- tests/resize.sh | 4 ++-- tests/resizec.sh | 32 +++++++++++++-------------- tests/resizen.sh | 49 ++++++++++++++++++++--------------------- tests/resizet.sh | 40 ++++++++++++++++----------------- tests/setlist_resize.sh | 4 ++-- 7 files changed, 69 insertions(+), 67 deletions(-)
Signature · 1 line
2.43.0
Phil Sutter
reviewerPATCH 1/3 lib: data: Fix for global-buffer-overflow warning by ASAN
After compiling with CFLAGS="-fsanitize=address -g", running the testsuite triggers the following warning:
| ipmap: Range: Check syntax error: missing range/from-to: FAILED | Failed test: ../src/ipset 2>.foo.err -N test ipmap | ================================================================= | ==4204==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55a21e77172a at pc 0x7f1ef246f2a6 bp 0x7fffed8f4f40 sp 0x7fffed8f46e8 | READ of size 32 at 0x55a21e77172a thread T0 | #0 0x7f1ef246f2a5 in __interceptor_memcpy /var/tmp/portage/sys-devel/gcc-13.2.1_p20231014/work/gcc-13-20231014/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:899 | #1 0x55a21e758bf6 in ipset_strlcpy /home/n0-1/git/ipset/lib/data.c:119 | #2 0x55a21e758bf6 in ipset_data_set /home/n0-1/git/ipset/lib/data.c:349 | #3 0x55a21e75ee2f in ipset_parse_typename /home/n0-1/git/ipset/lib/parse.c:1819 | #4 0x55a21e754119 in ipset_parser /home/n0-1/git/ipset/lib/ipset.c:1205 | #5 0x55a21e752cef in ipset_parse_argv /home/n0-1/git/ipset/lib/ipset.c:1344 | #6 0x55a21e74ea45 in main /home/n0-1/git/ipset/src/ipset.c:38 | #7 0x7f1ef224cf09 (/lib64/libc.so.6+0x23f09) | #8 0x7f1ef224cfc4 in __libc_start_main (/lib64/libc.so.6+0x23fc4) | #9 0x55a21e74f040 in _start (/home/n0-1/git/ipset/src/ipset+0x1d040) | | 0x55a21e77172a is located 54 bytes before global variable '*.LC1' defined in 'ipset_bitmap_ip.c' (0x55a21e771760) of size 19 | '*.LC1' is ascii string 'IP|IP/CIDR|FROM-TO' | 0x55a21e77172a is located 0 bytes after global variable '*.LC0' defined in 'ipset_bitmap_ip.c' (0x55a21e771720) of size 10 | '*.LC0' is ascii string 'bitmap:ip'
Fix this by avoiding 'src' array overstep in ipset_strlcpy(): In contrast to strncpy(), memcpy() does not respect NUL-chars in input but stubbornly reads as many bytes as specified.
--- lib/data.c | 3 +++ 1 file changed, 3 insertions(+)
lib/data.c +3 -0
@@ -111,6 +111,9 @@ ipset_strlcpy(char *dst, const char *src, size_t len)assert (dst);assert (src); +if (strlen (src) < len) + len =strlen (src) +1 ; +memcpy (dst, src, len); dst[len -1 ] ='\0' ; }
Signature · 1 line
2.43.0
Phil Sutter
reviewerPATCH 2/3 lib: ipset: Avoid 'argv' array overstepping
In reply to Phil SutterThe maximum accepted value for 'argc' is MAX_ARGS which matches 'argv' array size. The maximum allowed array index is therefore argc-1.
This fix will leave items in argv non-NULL-terminated, so explicitly NULL the formerly last entry after shifting.
Looks like a day-1 bug. Interestingly, this neither triggered ASAN nor valgrind. Yet adding debug output printing argv entries being copied did.
--- lib/ipset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ipset.c +2 -2
@@ -343,9 +343,9 @@ ipset_shift_argv(int *argc, char *argv[], int from)assert (*argc >= from +1 ); -for (i = from +1 ; i <= *argc; i++) +for (i = from +1 ; i < *argc; i++) argv[i-1 ] = argv[i]; - (*argc)--; + argv[--(*argc)] =NULL ;return ; }
Signature · 1 line
2.43.0
Phil Sutter
reviewerPATCH 3/3 tests: Reduce testsuite run-time
In reply to Phil SutterWhere acceptable, batch add set element calls to avoid overhead of excessive 'ipset' program spawns. On my (slow) testing VM, this patch reduces a full run of tests/runtest.sh from ~70min down to ~11min.
This might eliminate the situation being tested: resize.sh might be such a case so batch only 255 'ipset add' calls and continue to repeat these batched calls 32 times in hopes that it still qualifies as the resizing stress test tests/hash:ip.t calls it.
--- tests/resize.sh | 4 ++-- tests/resizec.sh | 32 +++++++++++++-------------- tests/resizen.sh | 49 ++++++++++++++++++++--------------------- tests/resizet.sh | 40 ++++++++++++++++----------------- tests/setlist_resize.sh | 4 ++-- 5 files changed, 64 insertions(+), 65 deletions(-)
tests/resize.sh +2 -2
@@ -9,6 +9,6 @@ set -e $ipset n resize-test hash:ip hashsize 64 for x in `seq 1 32`; do for y in `seq 1 255`; do - $ipset a resize-test 192.168.$x.$y - done + echo "a resize-test 192.168.$x.$y" + done | $ipset restore done
tests/resizec.sh +16 -16
@@ -25,65 +25,65 @@ case "$2" in $ipset n test hash:ip $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y comment "text $ip$x$sep$y" + echo "a test $ip$x$sep$y comment \"text $ip$x$sep$y\"" done - done + done | $ipset restore ;; ipport) $ipset n test hash:ip,port $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023 "text $ip$x$sep$y,1023" + echo "a test $ip$x$sep$y,1023 \"text $ip$x$sep$y,1023\"" done - done + done | $ipset restore ;; ipportip) $ipset n test hash:ip,port,ip $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023,$ip2 comment "text $ip$x$sep$y,1023,$ip2" + echo "a test $ip$x$sep$y,1023,$ip2 comment \"text $ip$x$sep$y,1023,$ip2\"" done - done + done | $ipset restore ;; ipportnet) $ipset n test hash:ip,port,net $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023,$ip2/$net comment "text $ip$x$sep$y,1023,$ip2/$net" + echo "a test $ip$x$sep$y,1023,$ip2/$net comment \"text $ip$x$sep$y,1023,$ip2/$net\"" done - done + done | $ipset restore ;; net) $ipset n test hash:net $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net comment "text $ip$x$sep$y/$net" + echo "a test $ip$x$sep$y/$net comment \"text $ip$x$sep$y/$net\"" done - done + done | $ipset restore ;; netnet) $ipset n test hash:net,net $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,$ip$y$sep$x/$net comment "text $ip$x$sep$y/$net,$ip$y$sep$x/$net" + echo "a test $ip$x$sep$y/$net,$ip$y$sep$x/$net comment \"text $ip$x$sep$y/$net,$ip$y$sep$x/$net\"" done - done + done | $ipset restore ;; netport) $ipset n test hash:net,port $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,1023 comment "text $ip$x$sep$y/$net,1023" + echo "a test $ip$x$sep$y/$net,1023 comment \"text $ip$x$sep$y/$net,1023\"" done - done + done | $ipset restore ;; netiface) $ipset n test hash:net,iface $1 hashsize 64 comment for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,eth0 comment "text $ip$x$sep$y/$net,eth0" + echo "$ipset a test $ip$x$sep$y/$net,eth0 comment \"text $ip$x$sep$y/$net,eth0\"" done - done + done | $ipset restore ;; esac $ipset l test | grep ^$ip | while read x y z; do
tests/resizen.sh +24 -25
104 lines not on this page · raw message
tests/resizet.sh +20 -20
@@ -25,81 +25,81 @@ case "$2" in $ipset n test hash:ip $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y + echo "a test $ip$x$sep$y" done - done + done | $ipset restore ;; ipmark) $ipset n test hash:ip,mark $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023 + echo "a test $ip$x$sep$y,1023" done - done + done | $ipset restore ;; ipport) $ipset n test hash:ip,port $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023 + echo "a test $ip$x$sep$y,1023" done - done + done | $ipset restore ;; ipportip) $ipset n test hash:ip,port,ip $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023,$ip2 + echo "a test $ip$x$sep$y,1023,$ip2" done - done + done | $ipset restore ;; ipportnet) $ipset n test hash:ip,port,net $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y,1023,$ip2/$net + echo "a test $ip$x$sep$y,1023,$ip2/$net" done - done + done | $ipset restore ;; netportnet) $ipset n test hash:net,port,net $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 128`; do - $ipset a test $ip$x$sep$y/$net,1023,$ip$y$sep$x/$net + echo "a test $ip$x$sep$y/$net,1023,$ip$y$sep$x/$net" done - done + done | $ipset restore ;; net) $ipset n test hash:net $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net + echo "a test $ip$x$sep$y/$net" done - done + done | $ipset restore ;; netnet) $ipset n test hash:net,net $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,$ip$y$sep$x/$net + echo "a test $ip$x$sep$y/$net,$ip$y$sep$x/$net" done - done + done | $ipset restore ;; netport) $ipset n test hash:net,port $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,1023 + echo "a test $ip$x$sep$y/$net,1023" done - done + done | $ipset restore ;; netiface) $ipset n test hash:net,iface $1 hashsize 64 timeout 100 for x in `seq 0 16`; do for y in `seq 0 255`; do - $ipset a test $ip$x$sep$y/$net,eth0 + echo "a test $ip$x$sep$y/$net,eth0" done - done + done | $ipset restore ;; esac $ipset l test | grep ^$ip | while read x y z; do
tests/setlist_resize.sh +2 -2
@@ -18,9 +18,9 @@ done create() { n=$1 while [ $n -le 1024 ]; do - $ipset c test$n hash:ip + echo "c test$n hash:ip" n=$((n+2)) - done + done | $ipset restore } for x in `seq 1 $loop`; do
Signature · 1 line
2.43.0
Hi Phil,
Quoted 7 lines · Phil Sutter
Fix two cases of illegal memory access and speed up the testsuite while waiting for results.
Phil Sutter (3):
lib: data: Fix for global-buffer-overflow warning by ASAN
lib: ipset: Avoid 'argv' array overstepping
tests: Reduce testsuite run-time
All patches are applied in the ipset git tree, thanks!
Best regards,
Jozsef
Quoted 13 lines
lib/data.c | 3 +++ lib/ipset.c | 4 ++-- tests/resize.sh | 4 ++-- tests/resizec.sh | 32 +++++++++++++-------------- tests/resizen.sh | 49 ++++++++++++++++++++--------------------- tests/resizet.sh | 40 ++++++++++++++++----------------- tests/setlist_resize.sh | 4 ++-- 7 files changed, 69 insertions(+), 67 deletions(-)Signature · 1 line
2.43.0
Signature · 4 lines
E-mail : [email protected], [email protected] PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt Address : Wigner Research Centre for Physics H-1525 Budapest 114, POB. 49, Hungary