I'm having trouble finding appropriate documentation for the problem I'm having generating consistent HMACs in the kernel and user space. According to Robert Love in Linux Kernel Development, the Memory Descriptors mm->start_code and mm->end_code are supposed to contain the .text segment. Finding the .text segment in a static executable is well defined in the ELF documentation and is easy to get at. So, given the following two code snippets, one would expect to get a matching HMAC:
Kernel:
__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; Userland:
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; } } In both cases the .text segment is exactly where it's documented to be but they never match. I've generated userland HMACs for all 17,000 executable files on the system so even if the code segment in the kernel memory descriptor were pointing to a dependency, rather than the primary executable, I still should get a match. But no dice. There's something fundamentally different between the two .text segments and I was wondering if anyone out there knew what it was so I can save some time--any clues?