DF-2215 / fix.diff
diff --git a/sys/dev/disk/dm/dm_target_zero.c b/sys/dev/disk/dm/dm_target_zero.c --- a/sys/dev/disk/dm/dm_target_zero.c +++ b/sys/dev/disk/dm/dm_target_zero.c @@ -40,6 +40,18 @@ static int dm_target_zero_strategy(dm_table_entry_t *table_en, struct buf *bp) { + /* + * Only zero data buffers (READ/WRITE). FREEBLKS (discard/TRIM) + * bios have b_data == NULL -- there is no data buffer for a + * discard, only an offset and length. Calling memset on a + * FREEBLKS bio would dereference NULL and panic. + */ + if (bp->b_cmd != BUF_CMD_READ && bp->b_cmd != BUF_CMD_WRITE) { + bp->b_resid = 0; + biodone(&bp->b_bio1); + return 0; + } + memset(bp->b_data, 0, bp->b_bcount); bp->b_resid = 0; biodone(&bp->b_bio1); |