Skip to content

Commit 9c2010b

Browse files
ebiggersMikulas Patocka
authored andcommitted
dm-integrity: check mac_size against HASH_MAX_DIGESTSIZE in sb_mac()
sb_mac() verifies that the superblock + MAC don't exceed 512 bytes. Because the superblock is currently 64 bytes, this really verifies mac_size <= 448. This confuses smatch into thinking that mac_size may be as large as 448, which is inconsistent with the later code that assumes the MAC fits in a buffer of size HASH_MAX_DIGESTSIZE (64). In fact mac_size <= HASH_MAX_DIGESTSIZE is guaranteed by the crypto API, as that is the whole point of HASH_MAX_DIGESTSIZE. But, let's be defensive and explicitly check for this. This suppresses the false positive smatch warning. It does not fix an actual bug. Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent 90da779 commit 9c2010b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/md/dm-integrity.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ static int sb_mac(struct dm_integrity_c *ic, bool wr)
494494
__u8 *sb = (__u8 *)ic->sb;
495495
__u8 *mac = sb + (1 << SECTOR_SHIFT) - mac_size;
496496

497-
if (sizeof(struct superblock) + mac_size > 1 << SECTOR_SHIFT) {
497+
if (sizeof(struct superblock) + mac_size > 1 << SECTOR_SHIFT ||
498+
mac_size > HASH_MAX_DIGESTSIZE) {
498499
dm_integrity_io_error(ic, "digest is too long", -EINVAL);
499500
return -EINVAL;
500501
}

0 commit comments

Comments
 (0)