1

我有一个作为循环设备安装的文件。为了在 C 中实现dm-integrity的功能,我必须用 NULL 覆盖超级块。

无论如何我可以直接写入超级块吗?还是从超级块开始将文件写入循环设备?由于它包含元数据,我会假设在写入时使用“数据区域”,而不是元数据区域?

谢谢你的帮助!

编辑:这是我当前的超级块格式:

DEBUG("[+] Formatting the Device");
// Create 4kb NULL buffer
char null_array[4096];
memset(&null_array[0],0,4096);

// Format superblock
int ret_val = file_write(loop_device,&null_array[0],4096);
if(ret_val < 0)
{
    ERROR_ERRNO("[+] Could not write to file! Superblock not clear. Aborting");
    return -1;
}else
{
    DEBUG("[+] Formatting worked! Return value: %d", ret_val);
}

它适用于使用随机文件创建的测试循环设备:

dd if=/dev/urandom of=./diskimage.img bs=1M count=512
losetup /dev/loop6 ./diskimage.img

但是在真正的目标上它将不起作用(如 ioctl 系统调用与 DM_TABLE_LOAD 退出(errno 22: Invalid Argument + device-mapper: table: 252:0: integrity: The device is not initialized -> 发生在超级块不完全为零)

4

0 回答 0