Skip to content

Commit 118f31b

Browse files
Thore Sommersnitm
authored andcommitted
dm ima: fix wrong length calculation for no_data string
All entries measured by dm ima are prefixed by a version string (dm_version=N.N.N). When there is no data to measure, the entire buffer is overwritten with a string containing the version string again and the length of that string is added to the length of the version string. The new length is now wrong because it contains the version string twice. This caused entries like this: dm_version=4.45.0;name=test,uuid=test;table_clear=no_data; \ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \ current_device_capacity=204808; Signed-off-by: Thore Sommer <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 302f035 commit 118f31b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/md/dm-ima.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap)
455455
scnprintf(device_table_data, DM_IMA_DEVICE_BUF_LEN,
456456
"%sname=%s,uuid=%s;device_resume=no_data;",
457457
DM_IMA_VERSION_STR, dev_name, dev_uuid);
458-
l += strlen(device_table_data);
458+
l = strlen(device_table_data);
459459

460460
}
461461

@@ -568,7 +568,7 @@ void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all)
568568
scnprintf(device_table_data, DM_IMA_DEVICE_BUF_LEN,
569569
"%sname=%s,uuid=%s;device_remove=no_data;",
570570
DM_IMA_VERSION_STR, dev_name, dev_uuid);
571-
l += strlen(device_table_data);
571+
l = strlen(device_table_data);
572572
}
573573

574574
memcpy(device_table_data + l, remove_all_str, remove_all_len);
@@ -654,7 +654,7 @@ void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map)
654654
scnprintf(device_table_data, DM_IMA_DEVICE_BUF_LEN,
655655
"%sname=%s,uuid=%s;table_clear=no_data;",
656656
DM_IMA_VERSION_STR, dev_name, dev_uuid);
657-
l += strlen(device_table_data);
657+
l = strlen(device_table_data);
658658
}
659659

660660
capacity_len = strlen(capacity_str);

0 commit comments

Comments
 (0)