【发布时间】:2020-12-22 14:10:56
【问题描述】:
当启用未定义的消毒剂时,我在 GNU 科学库 (GSL) 中发现运行时错误:
deque.c:58:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
deque.c:59:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: note: pointer points here
00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
deque.c:60:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: note: pointer points here
00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
deque.c:61:12: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte alignment
0x0000024010f4: note: pointer points here
00 00 00 00 ff ff ff ff 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
但我不知道这些错误的原因,或者如何修复它们。有人可以帮忙解释一下吗?此外,这是否是应该向开发人员提出的重要问题(例如,这种蜜蜂是否可以被利用作为安全攻击)?
源代码“deque.c”可以在here找到,运行时错误的相关行如下所示(错误出现在第58、59、60、61行)。
而deque的定义在这里,在同一个文件中:
[添加]
调用deque_init 的代码如下,在mmacc.c of GSL's movstat library:
static int
mmacc_init(const size_t n, void * vstate)
{
mmacc_state_t * state = (mmacc_state_t *) vstate;
state->n = n;
state->k = 0;
state->xprev = 0.0;
state->rbuf = (ringbuf *) ((unsigned char *) vstate + sizeof(mmacc_state_t));
state->minque = (deque *) ((unsigned char *) state->rbuf + ringbuf_size(n));
state->maxque = (deque *) ((unsigned char *) state->minque + deque_size(n + 1));
ringbuf_init(n, state->rbuf);
deque_init(n + 1, state->minque);
deque_init(n + 1, state->maxque);
return GSL_SUCCESS;
}
上面代码中的ringbuf_size函数是指ringbuf.c of the movstat library of GSL.下面的代码
static size_t
ringbuf_size(const size_t n)
{
size_t size = 0;
size += sizeof(ringbuf);
size += n * sizeof(ringbuf_type_t); /* b->array */
return size;
}
【问题讨论】:
-
显示的代码只是切线相关的。重要的是调用
deque_init()的代码。为什么该代码将未对齐的地址传递给函数?此外,您应该在问题中发布代码,而不是代码的图像。 -
@JonathanLeffler 请在上面查看我的编辑。谢谢你的好建议。
标签: security gsl sanitizer ubsan