Skip to contentSkip to conversation

block/blklogwrites: Make sure the log sector size is not too small

PATCH Applied Ari Sundholm 2 participants 3 messages Jul 6, 2018 – Jul 10, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/blklogwrites: Make sure the log sector size is not too small

The sector size needs to be large enough to accommodate the data structures for the log super block and log write entries. This was previously not properly checked, which made it possible to cause QEMU to badly misbehave.

---
 block/blklogwrites.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
block/blklogwrites.c +4 -1
index 63bf6b3..efa2c7a 100644
@@ -89,7 +89,10 @@ static inline uint32_t blk_log_writes_log2(uint32_t value)
 
 static inline bool blk_log_writes_sector_size_valid(uint32_t sector_size)
 {
-    return sector_size < (1ull << 24) && is_power_of_2(sector_size);
+    return is_power_of_2(sector_size) &&
+        sector_size >= sizeof(struct log_write_super) &&
+        sector_size >= sizeof(struct log_write_entry) &&
+        sector_size < (1ull << 24);
 }
 
 static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log,
Signature · 1 line
2.7.4
#1 lore raw

Would there be a chance of getting this included in 3.0?

Quoted 27 lines · Ari Sundholm

The sector size needs to be large enough to accommodate the data structures for the log super block and log write entries. This was previously not properly checked, which made it possible to cause QEMU to badly misbehave.

---
  block/blklogwrites.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
block/blklogwrites.c +4 -1
index 63bf6b3..efa2c7a 100644
@@ -89,7 +89,10 @@ static inline uint32_t blk_log_writes_log2(uint32_t value)
 
  static inline bool blk_log_writes_sector_size_valid(uint32_t sector_size)
  {
-    return sector_size < (1ull << 24) && is_power_of_2(sector_size);
+    return is_power_of_2(sector_size) &&
+        sector_size >= sizeof(struct log_write_super) &&
+        sector_size >= sizeof(struct log_write_entry) &&
+        sector_size < (1ull << 24);
  }
 
  static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log,
Applied
#2 lore raw

Am 09.07.2018 um 17:01 hat Ari Sundholm geschrieben:

Quoted 1 line

Would there be a chance of getting this included in 3.0?

Sure, this is clearly a bug fix.

Thanks, applied to the block branch.

Kevin

Quoted 27 lines · Ari Sundholm
Quoted 25 lines

The sector size needs to be large enough to accommodate the data structures for the log super block and log write entries. This was previously not properly checked, which made it possible to cause QEMU to badly misbehave.

---
  block/blklogwrites.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
block/blklogwrites.c +4 -1
index 63bf6b3..efa2c7a 100644
@@ -89,7 +89,10 @@ static inline uint32_t blk_log_writes_log2(uint32_t value)
  static inline bool blk_log_writes_sector_size_valid(uint32_t sector_size)
  {
-    return sector_size < (1ull << 24) && is_power_of_2(sector_size);
+    return is_power_of_2(sector_size) &&
+        sector_size >= sizeof(struct log_write_super) &&
+        sector_size >= sizeof(struct log_write_entry) &&
+        sector_size < (1ull << 24);
  }
  static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log,