加载地址 X 时,对于 Y 类型的对象没有足够的空间

Load of address X with insufficient space for an object of type Y

本文关键字:对象 空间 类型 地址 对于 加载      更新时间:2023-10-16

我正在通过未定义的行为清理器运行一些更新。消毒剂正在产生一条我不太明白的消息:

kalyna.cpp:1326:61: runtime error: load of address 0x0000016262c0 with insufficient space for an object of type 'const uint32_t'
0x0000016262c0: note: pointer points here
20 8b c1 1f  a9 f7 f9 5c 53 c4 cf d2  2f 3f 52 be 84 ed 96 1b  b8 7a b2 85 e0 96 7d 5d  70 ee 06 07
^

有问题的代码试图通过接触缓存行范围内的地址来使缓存计时攻击更加困难。1326 行是带有reinterpret_cast的线路:

// In KalynaTab namespace
uint64_t S[4][256] = {
...
};
...
// In library's namespace
const int cacheLineSize = GetCacheLineSize();
volatile uint32_t _u = 0;
uint32_t u = _u;
for (unsigned int i=0; i<256; i+=cacheLineSize)
u &= *reinterpret_cast<const uint32_t*>(KalynaTab::S+i);

为什么桑提齐尔声称uint32_t u没有足够的空间容纳uint32_t

或者,也许,我是否正确解析了错误消息?这是消毒员抱怨的吗?如果我解析不正确,那么消毒剂在抱怨什么?


$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
$ gcc --version
gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)

标识符S不会转换为您认为的类型的指针。因此,指针算法使您远远超出了数据范围,最好通过示例来显示:

#include <iostream>
#include <cstdint>
uint64_t S[4][256];
int main()
{
std::cout << static_cast<void*>(S+0) << 'n';
std::cout << static_cast<void*>(S+1) << 'n';
std::cout << static_cast<void*>(S+2) << 'n';
std::cout << static_cast<void*>(S+3) << 'n';
std::cout << 'n';
std::cout << static_cast<void*>(*S+0) << 'n';
std::cout << static_cast<void*>(*S+1) << 'n';
std::cout << static_cast<void*>(*S+2) << 'n';
std::cout << static_cast<void*>(*S+3) << 'n';
}

输出(明显取决于平台)

0x1000020b0
0x1000028b0
0x1000030b0
0x1000038b0
0x1000020b0
0x1000020b8
0x1000020c0
0x1000020c8

请注意每个下行第一个数字序列的步幅0x800。这是有道理的,因为每行由0x100个条目组成,每个条目 8 个字节(uint64_t 元素)。指针算术中使用的指针类型为uint64_t (*)[256]

现在注意第二个序列的步伐,它只窥视S[0]。步幅为 8 个字节,每个插槽一个。此计算中转换的指针的类型为uint64_t *

简而言之,您的指针算术假设S转换为uint64_t*,但事实并非如此。与所有数组到指针的转换一样,它转换为指向第一个元素的指针,包括相同类型。数组数组中的元素类型是uint64_t[256],所以转换后的指针类型是uint64_t (*)[256]