【问题标题】:Futex code walkthrough- returning EFAULTFutex 代码演练 - 返回 EFAULT
【发布时间】:2011-11-18 02:21:22
【问题描述】:

在 Linux 内核源代码中 futex.c 的futex_wake_op function 中,我试图了解控件是如何到达this 点的。这发生在上述函数中,futex_atomic_op_inuser 返回-EFAULT,并且但是uaddr2 是可写的。

但从futex_atomic_op_inusersource 中,我看到它仅在if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))) 上返回-EFAULT。

futex_atomic_op_inuser反过来调用__futex_atomic_op宏,我在代码中看到-EFAULT,但我被告知EFAULT的路径不涉及调用__futex_atomic_op

控件如何达到上述点(即if (!fshared)goto retry_private;)那么?

提前致谢!

【问题讨论】:

  • 这是两个问题。 EFAULT 的路径不涉及调用__futex_atomic_op
  • @Igor 我已经修改了问题。

标签: kernel arm inline-assembly futex


【解决方案1】:

access_ok 仅用于检查地址范围是否对给定的访问权限有效,即使如此,它也不能总是给出明确的答案。查看源代码中的 cmets:

 * Returns true (nonzero) if the memory block may be valid, false (zero)
 * if it is definitely invalid.
 *
 * Note that, depending on architecture, this function probably just
 * checks that the pointer is in the user space range - after calling
 * this function, memory access functions may still return -EFAULT.

接下来,即使块是有效的,它也可能不存在于内存中(被换出)。 futex_atomic_op_inuser 调用 pagefault_disable,这会禁用正常的换入过程,因此您将遇到硬故障,从 __futex_atomic_op 返回 -EFAULT

总而言之,所有这一切都意味着如果满足以下条件,将达到问题点:

  1. 地址无效,但通过access_ok 中的检查,或
  2. 它有效,但目前已换出。

【讨论】:

    猜你喜欢
    • 2017-08-19
    • 1970-01-01
    • 2018-07-20
    • 2016-05-23
    • 2021-01-24
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2012-01-03
    相关资源
    最近更新 更多