Author: vangyzen
Date: Fri Aug 28 19:50:40 2020
New Revision: 364933
URL: https://svnweb.freebsd.org/changeset/base/364933

Log:
  memstat_kvm_uma: fix reading of uma_zone_domain structures
  
  Coverity flagged the scaling by sizeof(uzd).  That is the type
  of the pointer, so the scaling was already done by pointer arithmetic.
  However, this was also passing a stack frame pointer to kvm_read,
  so it was doubly wrong.
  
  Move ZDOM_GET into the !_KERNEL section and use it in libmemstat.
  
  Reported by:  Coverity
  Reviewed by:  markj
  MFC after:    2 weeks
  Sponsored by: Dell EMC Isilon
  Differential Revision:        https://reviews.freebsd.org/D26213

Modified:
  head/lib/libmemstat/memstat_uma.c
  head/sys/vm/uma_int.h

Modified: head/lib/libmemstat/memstat_uma.c
==============================================================================
--- head/lib/libmemstat/memstat_uma.c   Fri Aug 28 19:21:11 2020        
(r364932)
+++ head/lib/libmemstat/memstat_uma.c   Fri Aug 28 19:50:40 2020        
(r364933)
@@ -455,9 +455,8 @@ skip_percpu:
                        mtp->mt_byteslimit = mtp->mt_countlimit * mtp->mt_size;
                        mtp->mt_count = mtp->mt_numallocs - mtp->mt_numfrees;
                        for (i = 0; i < ndomains; i++) {
-                               ret = kread(kvm,
-                                   &uz.uz_cpu[mp_maxid + 1] + i * sizeof(uzd),
-                                   &uzd, sizeof(uzd), 0);
+                               ret = kread(kvm, ZDOM_GET(uzp, i), &uzd,
+                                   sizeof(uzd), 0);
                                if (ret != 0)
                                        continue;
                                for (ubp =

Modified: head/sys/vm/uma_int.h
==============================================================================
--- head/sys/vm/uma_int.h       Fri Aug 28 19:21:11 2020        (r364932)
+++ head/sys/vm/uma_int.h       Fri Aug 28 19:50:40 2020        (r364933)
@@ -526,6 +526,10 @@ struct uma_zone {
        KASSERT(uma_zone_get_allocs((z)) == 0,                          \
            ("zone %s initialization after use.", (z)->uz_name))
 
+/* Domains are contiguous after the last CPU */
+#define        ZDOM_GET(z, n)                                                  
\
+       (&((uma_zone_domain_t)&(z)->uz_cpu[mp_maxid + 1])[n])
+
 #undef UMA_ALIGN
 
 #ifdef _KERNEL
@@ -560,10 +564,6 @@ static __inline uma_slab_t hash_sfind(struct uma_hash 
 #define        KEG_ASSERT_COLD(k)                                              
\
        KASSERT(uma_keg_get_allocs((k)) == 0,                           \
            ("keg %s initialization after use.", (k)->uk_name))
-
-/* Domains are contiguous after the last CPU */
-#define        ZDOM_GET(z, n)                                                  
\
-    (&((uma_zone_domain_t)&(z)->uz_cpu[mp_maxid + 1])[n])
 
 #define        ZDOM_LOCK_INIT(z, zdom, lc)                                     
\
        do {                                                            \
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to