“ __fortify_fail”是做什么的?

uml*_*ute 3 security debian gcc

一个用户提交了一个错误报告,其中我的应用程序在“ __fortify_fail()”中出现了段错误。

我知道这与使用Debian的“强化”标志构建应用程序有关-D_FORTIFY_SOURCE=2 -fstack-protector

不幸的是,用户的回溯并没有告诉我太多,并且用户没有超级响应(现在)。

为了更好地了解正在发生的事情,我想知道__fortify_fail实际发生了什么。

Kon*_*rov 5

此功能通常只是错误报告程序。来自glibc的示例代码是:

extern char **__libc_argv attribute_hidden;

void
__attribute__ ((noreturn))
__fortify_fail (msg)
     const char *msg;
{
  /* The loop is added only to keep gcc happy.  */
  while (1)
    __libc_message (2, "*** %s ***: %s terminated\n",
                    msg, __libc_argv[0] ?: "<unknown>");
}
libc_hidden_def (__fortify_fail)
Run Code Online (Sandbox Code Playgroud)

它可能在这里和那里被称为要加强来源的地方。“设防”本身只是几个运行时检查。openat来自的函数的示例用法io/openat.c是:

int
__openat_2 (fd, file, oflag)
     int fd;
     const char *file;
     int oflag;
{
  if (oflag & O_CREAT)
    __fortify_fail ("invalid openat call: O_CREAT without mode");

  return __openat (fd, file, oflag);
}
Run Code Online (Sandbox Code Playgroud)

没有设防,O_CREAT没有模式是可以接受的(这种情况仍然高度可疑,这合法的)。

考虑一下__fortify_failprintf + abort。

开启心灵感应,您可能会建议用户在用户代码中使用libc时遇到一些问题。/lib/x86_64-linux-gnu/libc.so.6(+0xebdf0)[0x7f75d3576df0]是libc内部某个运行时检查失败pd[0x49b5c0]的地方,也是libc错误地从中调用的地方。