Skip to content

Commit bfa4b9c

Browse files
committed
Fix prev_hdr use-after-free in l2arc_write_sublist
prev_hdr is dereferenced after the sublist lock is dropped for write I/O but nothing prevents it from being freed during that window. Refresh prev_hdr from the local marker's neighbor after reacquiring the lock, since markers cannot be evicted. Add a NULL guard for the case where the marker is at the list boundary. Signed-off-by: Ameer Hamza <ahamza@ixsystems.com>
1 parent d308869 commit bfa4b9c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

module/zfs/arc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9829,10 +9829,15 @@ l2arc_write_sublist(spa_t *spa, l2arc_dev_t *dev, int pass, int sublist_idx,
98299829

98309830
next:
98319831
multilist_sublist_lock(mls);
9832-
if (scan_from_head)
9832+
if (scan_from_head) {
98339833
hdr = multilist_sublist_next(mls, local_marker);
9834-
else
9834+
prev_hdr = multilist_sublist_prev(mls,
9835+
local_marker);
9836+
} else {
98359837
hdr = multilist_sublist_prev(mls, local_marker);
9838+
prev_hdr = multilist_sublist_next(mls,
9839+
local_marker);
9840+
}
98369841
multilist_sublist_remove(mls, local_marker);
98379842
}
98389843

@@ -9854,7 +9859,7 @@ l2arc_write_sublist(spa_t *spa, l2arc_dev_t *dev, int pass, int sublist_idx,
98549859
multilist_sublist_insert_tail(mls, persistent_marker);
98559860
spa->spa_l2arc_info.l2arc_sublist_reset[pass][sublist_idx] =
98569861
B_FALSE;
9857-
} else if (save_position &&
9862+
} else if (save_position && prev_hdr != NULL &&
98589863
multilist_link_active(&prev_hdr->b_l1hdr.b_arc_node)) {
98599864
if (hdr != NULL) {
98609865
/*

0 commit comments

Comments
 (0)