Skip to content

Commit fa514db

Browse files
markjdbtonyhutter
authored andcommitted
Zero pad bytes following TX_WRITE log data
When logging a TX_WRITE record in the case where file data has to be copied from the DMU, we pad the log record size to a multiple of 8 bytes. In this case, any padding bytes should be zeroed, otherwise the contents of uninitialized memory are written to the ZIL. This was found using KMSAN. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Mark Johnston <[email protected]> Closes #12383
1 parent a902d19 commit fa514db

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

module/zfs/zil.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb)
16171617
lr_t *lrcb, *lrc;
16181618
lr_write_t *lrwb, *lrw;
16191619
char *lr_buf;
1620-
uint64_t dlen, dnow, lwb_sp, reclen, txg, max_log_data;
1620+
uint64_t dlen, dnow, dpad, lwb_sp, reclen, txg, max_log_data;
16211621

16221622
ASSERT(MUTEX_HELD(&zilog->zl_issuer_lock));
16231623
ASSERT3P(lwb, !=, NULL);
@@ -1651,8 +1651,9 @@ zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb)
16511651
if (lrc->lrc_txtype == TX_WRITE && itx->itx_wr_state == WR_NEED_COPY) {
16521652
dlen = P2ROUNDUP_TYPED(
16531653
lrw->lr_length, sizeof (uint64_t), uint64_t);
1654+
dpad = dlen - lrw->lr_length;
16541655
} else {
1655-
dlen = 0;
1656+
dlen = dpad = 0;
16561657
}
16571658
reclen = lrc->lrc_reclen;
16581659
zilog->zl_cur_used += (reclen + dlen);
@@ -1746,6 +1747,9 @@ zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb)
17461747
error = zilog->zl_get_data(itx->itx_private,
17471748
itx->itx_gen, lrwb, dbuf, lwb,
17481749
lwb->lwb_write_zio);
1750+
if (dbuf != NULL && error == 0 && dnow == dlen)
1751+
/* Zero any padding bytes in the last block. */
1752+
bzero((char *)dbuf + lrwb->lr_length, dpad);
17491753

17501754
if (error == EIO) {
17511755
txg_wait_synced(zilog->zl_dmu_pool, txg);

0 commit comments

Comments
 (0)