Date: Tue, 21 Jul 2015 23:57:39 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285782 - head/usr.bin/netstat Message-ID: <201507212357.t6LNvd7K023794@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Tue Jul 21 23:57:38 2015 New Revision: 285782 URL: https://svnweb.freebsd.org/changeset/base/285782 Log: Fix counter reads on platforms where sizeof(uint64_t) != sizeof(uint64_t *). In the kernel, structs such as tcpstat are manipulated as an array of counter_u64_t (uint64_t *), but made visible to userland as an array of uint64_t. kread_counters() was previously copying the counter array into user space and sequentially overwriting each counter with its value. This mostly affects IPsec counters, as other counters are exported via sysctl. PR: 201700 Tested by: Jason Unovitch MFC after: 1 week Modified: head/usr.bin/netstat/main.c Modified: head/usr.bin/netstat/main.c ============================================================================== --- head/usr.bin/netstat/main.c Tue Jul 21 23:44:36 2015 (r285781) +++ head/usr.bin/netstat/main.c Tue Jul 21 23:57:38 2015 (r285782) @@ -776,19 +776,31 @@ kread_counter(u_long addr) int kread_counters(u_long addr, void *buf, size_t size) { - uint64_t *c = buf; + uint64_t *c; + u_long *counters; + size_t i, n; if (kvmd_init() < 0) return (-1); - if (kread(addr, buf, size) < 0) + if (size % sizeof(uint64_t) != 0) { + xo_warnx("kread_counters: invalid counter set size"); return (-1); + } - while (size != 0) { - *c = kvm_counter_u64_fetch(kvmd, *c); - size -= sizeof(*c); - c++; + n = size / sizeof(uint64_t); + if ((counters = malloc(n * sizeof(u_long))) == NULL) + xo_err(-1, "malloc"); + if (kread(addr, counters, n * sizeof(u_long)) < 0) { + free(counters); + return (-1); } + + c = buf; + for (i = 0; i < n; i++) + c[i] = kvm_counter_u64_fetch(kvmd, counters[i]); + + free(counters); return (0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507212357.t6LNvd7K023794>