【发布时间】:2014-02-12 07:34:20
【问题描述】:
对于在内核和用户空间中生成一致的 HMACS 的问题,我找不到合适的文档。根据 LKD 中的 R. Love,内存描述符 mm->start_code 和 mm->end_code 应该包含 .text 段。在 ELF 文档中明确定义了在静态可执行文件中查找 .text 段,并且很容易找到。因此,给定以下两个代码 sn-ps,可以期望得到一个匹配的 HMAC:
内核:
__mm = get_task_mm(__task);
__retcode = ntru_crypto_hmac_init(__crypto_context);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
return 1;
__retcode = ntru_crypto_hmac_update(__crypto_context, (const uint8_t*)__mm->start_code,
__mm->end_code - __mm->start_code);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
return 1;
__retcode = ntru_crypto_hmac_final(__crypto_context, __hmac);
if(__retcode != NTRU_CRYPTO_HMAC_OK)
return 1;
return 0;
用户区:
for (j = 0; j < file_hdr32.e_shnum; j++)
{
if (!strcmp(".text", strIndex + section_hdr32[j]->sh_name))
{
retcode = ntru_crypto_hmac_init(__crypto_context());
if(retcode != NTRU_CRYPTO_HMAC_OK)
{
syslog(LOG_ERR, "ntru_crypto_hmac_init error: retcode = %d, TID(0x%lx)",
retcode,pthread_self());
return 0;
}
retcode = ntru_crypto_hmac_update(__crypto_context(),
filebuf + section_hdr32[j]->sh_offset, section_hdr32[j]->sh_size);
if(retcode != NTRU_CRYPTO_HMAC_OK)
{
syslog(LOG_ERR, "Internal crypto error (%d)", retcode);
return 0;
}
retcode = ntru_crypto_hmac_final(__crypto_context(), _hmac);
if(retcode != NTRU_CRYPTO_HMAC_OK)
{
syslog(LOG_ERR, "Failed to finalize HMAC, TID(0x%lx)", pthread_self());
return 0;
}
return 1;
}
}
在这两种情况下,.text 段正是其记录的位置,但它们从不匹配。我已经为系统上的所有 17,000 个可执行文件生成了用户级 HMACS,因此即使内核内存描述符中的代码段指向依赖项,而不是主可执行文件,我仍然应该得到匹配,但没有骰子。两个“.text”段之间有一些根本不同的地方,我想知道是否有人知道它是什么,这样我就可以节省一些时间——有什么线索吗?在此先感谢,皮特。;1
【问题讨论】:
标签: linux-kernel elf hmac