From e871059bc4087e69dbda7f78fe1d151014109673 Mon Sep 17 00:00:00 2001 From: Tim Chase Date: Sun, 10 Jul 2016 09:09:02 -0500 Subject: [PATCH] Prevent null dereferences when accessing dbuf kstat In arc_buf_info(), the arc_buf_t may have no header. If not, don't try to fetch the arc buffer stats and instead just zero them. The null dereferences were observed while accessing the dbuf kstat with awk on a system in which millions of small files were being created in order to overflow the system's metadata limit. Signed-off-by: Tim Chase Signed-off-by: Brian Behlendorf Signed-off-by: Chunwei Chen Closes #4837 --- module/zfs/arc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 2b7aa52381..7bcb7e3ee3 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -1451,6 +1451,13 @@ arc_buf_info(arc_buf_t *ab, arc_buf_info_t *abi, int state_index) l2arc_buf_hdr_t *l2hdr = NULL; arc_state_t *state = NULL; + memset(abi, 0, sizeof (arc_buf_info_t)); + + if (hdr == NULL) + return; + + abi->abi_flags = hdr->b_flags; + if (HDR_HAS_L1HDR(hdr)) { l1hdr = &hdr->b_l1hdr; state = l1hdr->b_state; @@ -1458,9 +1465,6 @@ arc_buf_info(arc_buf_t *ab, arc_buf_info_t *abi, int state_index) if (HDR_HAS_L2HDR(hdr)) l2hdr = &hdr->b_l2hdr; - memset(abi, 0, sizeof (arc_buf_info_t)); - abi->abi_flags = hdr->b_flags; - if (l1hdr) { abi->abi_datacnt = l1hdr->b_datacnt; abi->abi_access = l1hdr->b_arc_access;