]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Restrict kstats and print real pointers
authorSara Hartse <sara.hartse@gmail.com>
Fri, 5 Apr 2019 01:57:06 +0000 (18:57 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 5 Apr 2019 01:57:06 +0000 (18:57 -0700)
There are several places where we use zfs_dbgmsg and %p to
print pointers. In the Linux kernel, these values obfuscated
to prevent information leaks which means the pointers aren't
very useful for debugging crash dumps. We decided to restrict
the permissions of dbgmsg (and some other kstats while we were
at it) and print pointers with %px in zfs_dbgmsg as well as
spl_dumpstack

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Gallagher <john.gallagher@delphix.com>
Signed-off-by: sara hartse <sara.hartse@delphix.com>
Closes #8467
Closes #8476

18 files changed:
cmd/ztest/ztest.c
include/spl/sys/debug.h
include/spl/sys/kstat.h
include/spl/sys/procfs_list.h
include/sys/zfs_context.h
lib/libzpool/kernel.c
module/spl/spl-kstat.c
module/spl/spl-procfs-list.c
module/zfs/arc.c
module/zfs/metaslab.c
module/zfs/range_tree.c
module/zfs/spa_stats.c
module/zfs/space_map.c
module/zfs/vdev_removal.c
module/zfs/zfs_debug.c
module/zfs/zil.c
module/zfs/zio.c
tests/zfs-tests/tests/functional/cli_user/misc/dbufstat_001_pos.ksh

index a1ab56bd2f52dd6290adb1fa32c091c4ef884155..9c2cf9501831b423c827d5a071a6ff4dc011c80a 100644 (file)
@@ -6468,7 +6468,7 @@ ztest_initialize(ztest_ds_t *zd, uint64_t id)
        char *path = strdup(rand_vd->vdev_path);
        boolean_t active = rand_vd->vdev_initialize_thread != NULL;
 
-       zfs_dbgmsg("vd %p, guid %llu", rand_vd, guid);
+       zfs_dbgmsg("vd %px, guid %llu", rand_vd, guid);
        spa_config_exit(spa, SCL_VDEV, FTAG);
 
        uint64_t cmd = ztest_random(POOL_INITIALIZE_FUNCS);
index d9336c7d158520e0fcaf24a6160c83db0b5a1a83..b17d77d280a994de5ee8b1a3d076a495b6d97354 100644 (file)
@@ -102,7 +102,7 @@ void spl_dumpstack(void);
                if (!(_verify3_left OP _verify3_right))                 \
                    spl_panic(__FILE__, __FUNCTION__, __LINE__,         \
                    "VERIFY3(" #LEFT " "  #OP " "  #RIGHT ") "          \
-                   "failed (%p " #OP " %p)\n",                         \
+                   "failed (%px" #OP " %px)\n",                        \
                    (void *) (_verify3_left),                           \
                    (void *) (_verify3_right));                         \
        } while (0)
index 53274d8f59c4e93df9af02e9afc8382ec5cad6f0..3ce4742488737a84b623fece39b23e3020a6cf3b 100644 (file)
@@ -196,7 +196,7 @@ extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
 extern void kstat_proc_entry_init(kstat_proc_entry_t *kpep,
     const char *module, const char *name);
 extern void kstat_proc_entry_delete(kstat_proc_entry_t *kpep);
-extern void kstat_proc_entry_install(kstat_proc_entry_t *kpep,
+extern void kstat_proc_entry_install(kstat_proc_entry_t *kpep, mode_t mode,
     const struct file_operations *file_ops, void *data);
 
 extern void __kstat_install(kstat_t *ksp);
index cbcb4bcfffff7e53b8220a41c3df77936bbcacde..eb1519c0ad63a8751caf5377b670fc15d2ecf699 100644 (file)
@@ -58,6 +58,7 @@ typedef struct procfs_list_node {
 
 void procfs_list_install(const char *module,
     const char *name,
+    mode_t mode,
     procfs_list_t *procfs_list,
     int (*show)(struct seq_file *f, void *p),
     int (*show_header)(struct seq_file *f),
index 87ddde30a3bfe074e88348593b22648a4cb9902c..e3fa2e61bdc94264d1ed722c3b9b36eb178691f5 100644 (file)
@@ -375,6 +375,7 @@ typedef struct procfs_list_node {
 
 void procfs_list_install(const char *module,
     const char *name,
+    mode_t mode,
     procfs_list_t *procfs_list,
     int (*show)(struct seq_file *f, void *p),
     int (*show_header)(struct seq_file *f),
index 926f4f4f40b42c9092e1e63119bc0cf8945ae96e..f22ad56b5335565aefda18942419f33d74a3d368 100644 (file)
@@ -437,6 +437,7 @@ seq_printf(struct seq_file *m, const char *fmt, ...)
 void
 procfs_list_install(const char *module,
     const char *name,
+    mode_t mode,
     procfs_list_t *procfs_list,
     int (*show)(struct seq_file *f, void *p),
     int (*show_header)(struct seq_file *f),
index 7207a35e04bec2177c55ef71b612cc08f8759884..feff31e6c75259957e33ee81ba093fe630e8cd32 100644 (file)
@@ -659,7 +659,7 @@ kstat_detect_collision(kstat_proc_entry_t *kpep)
  * kstat.
  */
 void
-kstat_proc_entry_install(kstat_proc_entry_t *kpep,
+kstat_proc_entry_install(kstat_proc_entry_t *kpep, mode_t mode,
     const struct file_operations *file_ops, void *data)
 {
        kstat_module_t *module;
@@ -693,7 +693,7 @@ kstat_proc_entry_install(kstat_proc_entry_t *kpep,
        list_add_tail(&kpep->kpe_list, &module->ksm_kstat_list);
 
        kpep->kpe_owner = module;
-       kpep->kpe_proc = proc_create_data(kpep->kpe_name, 0644,
+       kpep->kpe_proc = proc_create_data(kpep->kpe_name, mode,
            module->ksm_proc, file_ops, data);
        if (kpep->kpe_proc == NULL) {
                list_del_init(&kpep->kpe_list);
@@ -710,7 +710,15 @@ void
 __kstat_install(kstat_t *ksp)
 {
        ASSERT(ksp);
-       kstat_proc_entry_install(&ksp->ks_proc, &proc_kstat_operations, ksp);
+       mode_t mode;
+       /* Specify permission modes for different kstats */
+       if (strncmp(ksp->ks_proc.kpe_name, "dbufs", KSTAT_STRLEN) == 0) {
+               mode = 0600;
+       } else {
+               mode = 0644;
+       }
+       kstat_proc_entry_install(
+           &ksp->ks_proc, mode, &proc_kstat_operations, ksp);
 }
 EXPORT_SYMBOL(__kstat_install);
 
index 4902e0a56c67c76f183815ffbd249e3261844699..f6a00da5c9195b727b5bd40b5749e4fb1431cb32 100644 (file)
@@ -201,6 +201,7 @@ static struct file_operations procfs_list_operations = {
 void
 procfs_list_install(const char *module,
     const char *name,
+    mode_t mode,
     procfs_list_t *procfs_list,
     int (*show)(struct seq_file *f, void *p),
     int (*show_header)(struct seq_file *f),
@@ -218,7 +219,7 @@ procfs_list_install(const char *module,
        procfs_list->pl_node_offset = procfs_list_node_off;
 
        kstat_proc_entry_init(&procfs_list->pl_kstat_entry, module, name);
-       kstat_proc_entry_install(&procfs_list->pl_kstat_entry,
+       kstat_proc_entry_install(&procfs_list->pl_kstat_entry, mode,
            &procfs_list_operations, procfs_list);
 }
 EXPORT_SYMBOL(procfs_list_install);
index 50d0125df810033df137e69e7531706487909752..c724878948d513ed0cecc246166d3466af8014ab 100644 (file)
@@ -2266,7 +2266,7 @@ arc_buf_fill(arc_buf_t *buf, spa_t *spa, const zbookmark_phys_t *zb,
                         */
                        if (error != 0) {
                                zfs_dbgmsg(
-                                   "hdr %p, compress %d, psize %d, lsize %d",
+                                   "hdr %px, compress %d, psize %d, lsize %d",
                                    hdr, arc_hdr_get_compress(hdr),
                                    HDR_GET_PSIZE(hdr), HDR_GET_LSIZE(hdr));
                                if (hash_lock != NULL)
index 06d8383f09c93baea3762242672f7514fee3d89b..ec89810b48abeed5f31355537803f2d9634e03ee 100644 (file)
@@ -2643,7 +2643,7 @@ metaslab_condense(metaslab_t *msp, uint64_t txg, dmu_tx_t *tx)
        ASSERT(msp->ms_loaded);
 
 
-       zfs_dbgmsg("condensing: txg %llu, msp[%llu] %p, vdev id %llu, "
+       zfs_dbgmsg("condensing: txg %llu, msp[%llu] %px, vdev id %llu, "
            "spa %s, smp size %llu, segments %lu, forcing condense=%s", txg,
            msp->ms_id, msp, msp->ms_group->mg_vd->vdev_id,
            msp->ms_group->mg_vd->vdev_spa->spa_name,
index 1a31c11292525c1f703befe2c67fb45ffa342083..391533b3f49532b7f1ac83fa280b8f8fe8bfcb4c 100644 (file)
@@ -118,7 +118,7 @@ range_tree_stat_verify(range_tree_t *rt)
 
        for (i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++) {
                if (hist[i] != rt->rt_histogram[i]) {
-                       zfs_dbgmsg("i=%d, hist=%p, hist=%llu, rt_hist=%llu",
+                       zfs_dbgmsg("i=%d, hist=%px, hist=%llu, rt_hist=%llu",
                            i, hist, hist[i], rt->rt_histogram[i]);
                }
                VERIFY3U(hist[i], ==, rt->rt_histogram[i]);
index 3b51250c6832ae3b7b145aaaf0a85caedca5c725..6895428f4faabb0b1465e536af15ffccbb925385 100644 (file)
@@ -131,6 +131,7 @@ spa_read_history_init(spa_t *spa)
        shl->procfs_list.pl_private = shl;
        procfs_list_install(module,
            "reads",
+           0600,
            &shl->procfs_list,
            spa_read_history_show,
            spa_read_history_show_header,
@@ -301,6 +302,7 @@ spa_txg_history_init(spa_t *spa)
        shl->procfs_list.pl_private = shl;
        procfs_list_install(module,
            "txgs",
+           0644,
            &shl->procfs_list,
            spa_txg_history_show,
            spa_txg_history_show_header,
@@ -706,6 +708,7 @@ spa_mmp_history_init(spa_t *spa)
        shl->procfs_list.pl_private = shl;
        procfs_list_install(module,
            "multihost",
+           0644,
            &shl->procfs_list,
            spa_mmp_history_show,
            spa_mmp_history_show_header,
index 5cf3feaae108672fb8f2e05fc21965d27fce8fd7..d9cd8767e094de0d41627496bd786cbb80145663 100644 (file)
@@ -848,7 +848,7 @@ space_map_truncate(space_map_t *sm, int blocksize, dmu_tx_t *tx)
            doi.doi_bonus_size != sizeof (space_map_phys_t)) ||
            doi.doi_data_block_size != blocksize ||
            doi.doi_metadata_block_size != 1 << space_map_ibs) {
-               zfs_dbgmsg("txg %llu, spa %s, sm %p, reallocating "
+               zfs_dbgmsg("txg %llu, spa %s, sm %px, reallocating "
                    "object[%llu]: old bonus %u, old blocksz %u",
                    dmu_tx_get_txg(tx), spa_name(spa), sm, sm->sm_object,
                    doi.doi_bonus_size, doi.doi_data_block_size);
index 99d67b7be85f1b66545f1b565508aab5a06d922d..f2d18d9257bd3609712281d6a9a268f12139dacc 100644 (file)
@@ -340,7 +340,7 @@ vdev_remove_initiate_sync(void *arg, dmu_tx_t *tx)
         */
        vdev_config_dirty(vd);
 
-       zfs_dbgmsg("starting removal thread for vdev %llu (%p) in txg %llu "
+       zfs_dbgmsg("starting removal thread for vdev %llu (%px) in txg %llu "
            "im_obj=%llu", vd->vdev_id, vd, dmu_tx_get_txg(tx),
            vic->vic_mapping_object);
 
index 62c59e020923fc61ef1250a7f2c056afdbed6a57..538533d27d2b399042dba4c2bab94df01aef8227 100644 (file)
@@ -94,6 +94,7 @@ zfs_dbgmsg_init(void)
 {
        procfs_list_install("zfs",
            "dbgmsg",
+           0600,
            &zfs_dbgmsgs,
            zfs_dbgmsg_show,
            zfs_dbgmsg_show_header,
index e5de8b5e4c26f621a42ea1c8f1b2be5013ec846c..a70fe1a629eb4852778c09785572d4a2ec0be9ac 100644 (file)
@@ -3232,7 +3232,7 @@ zil_close(zilog_t *zilog)
                txg_wait_synced(zilog->zl_dmu_pool, txg);
 
        if (zilog_is_dirty(zilog))
-               zfs_dbgmsg("zil (%p) is dirty, txg %llu", zilog, txg);
+               zfs_dbgmsg("zil (%px) is dirty, txg %llu", zilog, txg);
        if (txg < spa_freeze_txg(zilog->zl_spa))
                VERIFY(!zilog_is_dirty(zilog));
 
index 1915de417295de81f36f69bc24ee6c8afc554ead..016ac07eabd92eed09bff77ba6f9bed37612cf7d 100644 (file)
@@ -1893,7 +1893,7 @@ zio_deadman_impl(zio_t *pio, int ziodepth)
                uint64_t delta = gethrtime() - pio->io_timestamp;
                uint64_t failmode = spa_get_deadman_failmode(pio->io_spa);
 
-               zfs_dbgmsg("slow zio[%d]: zio=%p timestamp=%llu "
+               zfs_dbgmsg("slow zio[%d]: zio=%px timestamp=%llu "
                    "delta=%llu queued=%llu io=%llu "
                    "path=%s last=%llu "
                    "type=%d priority=%d flags=0x%x "
@@ -3444,7 +3444,7 @@ zio_dva_allocate(zio_t *zio)
        }
 
        if (error != 0) {
-               zfs_dbgmsg("%s: metaslab allocation failure: zio %p, "
+               zfs_dbgmsg("%s: metaslab allocation failure: zio %px, "
                    "size %llu, error %d", spa_name(spa), zio, zio->io_size,
                    error);
                if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE)
index 95f0598c6187df538fdca8e1404151f0bc785d22..0e187015f8d6a1bac47f6b8e7a10b88ed915de78 100755 (executable)
@@ -33,11 +33,11 @@ log_assert "dbufstat generates output and doesn't return an error code"
 
 typeset -i i=0
 while [[ $i -lt ${#args[*]} ]]; do
-        log_must eval "dbufstat ${args[i]} > /dev/null"
+        log_must eval "sudo dbufstat ${args[i]} > /dev/null"
         ((i = i + 1))
 done
 
 # A simple test of dbufstat filter functionality
-log_must eval "dbufstat -F object=10,dbc=1,pool=$TESTPOOL > /dev/null"
+log_must eval "sudo dbufstat -F object=10,dbc=1,pool=$TESTPOOL > /dev/null"
 
 log_pass "dbufstat generates output and doesn't return an error code"