summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-01-13 02:07:49 -0900
committerKent Overstreet <kent.overstreet@gmail.com>2017-01-18 21:41:35 -0900
commite97e1d82a6bf1382ccd2786c7c4bd233ee1c4299 (patch)
tree6f6e3cc98981b735fa1f9cb8b2cc3957bb8109e8
parentabf8953366dcbd8ab7a61873b25494d31ee721c2 (diff)
bcache: don't leak uninitialized memory
-rw-r--r--drivers/md/bcache/btree_io.c3
-rw-r--r--drivers/md/bcache/journal.c6
2 files changed, 8 insertions, 1 deletions
diff --git a/drivers/md/bcache/btree_io.c b/drivers/md/bcache/btree_io.c
index 1122b448d015..ff976b59441e 100644
--- a/drivers/md/bcache/btree_io.c
+++ b/drivers/md/bcache/btree_io.c
@@ -1423,6 +1423,9 @@ void __bch_btree_node_write(struct cache_set *c, struct btree *b,
bytes_to_write = (void *) bset_bkey_last(i) - data;
sectors_to_write = round_up(bytes_to_write, block_bytes(c)) >> 9;
+ memset(data + bytes_to_write, 0,
+ (sectors_to_write << 9) - bytes_to_write);
+
BUG_ON(b->written + sectors_to_write > c->sb.btree_node_size);
trace_bcache_btree_write(b, bytes_to_write, sectors_to_write);
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 1dcbaf251424..636f0e9231f3 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -1108,6 +1108,7 @@ static void __bch_journal_next_entry(struct journal *j)
buf = journal_cur_buf(j);
memset(buf->has_inode, 0, sizeof(buf->has_inode));
+ memset(buf->data, 0, sizeof(*buf->data));
buf->data->seq = cpu_to_le64(atomic64_read(&j->seq));
buf->data->u64s = 0;
@@ -2020,7 +2021,7 @@ static void journal_write(struct closure *cl)
struct journal_buf *w = journal_prev_buf(j);
struct bio *bio;
struct bch_extent_ptr *ptr;
- unsigned i, sectors;
+ unsigned i, sectors, bytes;
j->write_start_time = local_clock();
@@ -2052,6 +2053,9 @@ static void journal_write(struct closure *cl)
block_bytes(c)) * c->sb.block_size;
BUG_ON(sectors > j->prev_buf_sectors);
+ bytes = __set_bytes(w->data, le32_to_cpu(w->data->u64s));
+ memset((void *) w->data + bytes, 0, (sectors << 9) - bytes);
+
if (journal_write_alloc(j, sectors)) {
bch_journal_halt(j);
bch_err(c, "Unable to allocate journal write");