Skip to content

Commit 3219e8c

Browse files
Bill O'Donnelldjwong
authored andcommitted
xfs: assure zeroed memory buffers for certain kmem allocations
Guarantee zeroed memory buffers for cases where potential memory leak to disk can occur. In these cases, kmem_alloc is used and doesn't zero the buffer, opening the possibility of information leakage to disk. Use existing infrastucture (xfs_buf_allocate_memory) to obtain the already zeroed buffer from kernel memory. This solution avoids the performance issue that would occur if a wholesale change to replace kmem_alloc with kmem_zalloc was done. Signed-off-by: Bill O'Donnell <[email protected]> [darrick: fix bitwise complaint about kmflag_mask] Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent d5cc14d commit 3219e8c

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

fs/xfs/xfs_buf.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ xfs_buf_allocate_memory(
345345
unsigned short page_count, i;
346346
xfs_off_t start, end;
347347
int error;
348+
xfs_km_flags_t kmflag_mask = 0;
349+
350+
/*
351+
* assure zeroed buffer for non-read cases.
352+
*/
353+
if (!(flags & XBF_READ)) {
354+
kmflag_mask |= KM_ZERO;
355+
gfp_mask |= __GFP_ZERO;
356+
}
348357

349358
/*
350359
* for buffers that are contained within a single page, just allocate
@@ -354,7 +363,8 @@ xfs_buf_allocate_memory(
354363
size = BBTOB(bp->b_length);
355364
if (size < PAGE_SIZE) {
356365
int align_mask = xfs_buftarg_dma_alignment(bp->b_target);
357-
bp->b_addr = kmem_alloc_io(size, align_mask, KM_NOFS);
366+
bp->b_addr = kmem_alloc_io(size, align_mask,
367+
KM_NOFS | kmflag_mask);
358368
if (!bp->b_addr) {
359369
/* low memory - use alloc_page loop instead */
360370
goto use_alloc_page;

fs/xfs/xfs_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ xlog_alloc_log(
14431443
prev_iclog = iclog;
14441444

14451445
iclog->ic_data = kmem_alloc_io(log->l_iclog_size, align_mask,
1446-
KM_MAYFAIL);
1446+
KM_MAYFAIL | KM_ZERO);
14471447
if (!iclog->ic_data)
14481448
goto out_free_iclog;
14491449
#ifdef DEBUG

fs/xfs/xfs_log_recover.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ xlog_alloc_buffer(
127127
if (nbblks > 1 && log->l_sectBBsize > 1)
128128
nbblks += log->l_sectBBsize;
129129
nbblks = round_up(nbblks, log->l_sectBBsize);
130-
return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL);
130+
return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL | KM_ZERO);
131131
}
132132

133133
/*

0 commit comments

Comments
 (0)