Futex 代码演练 - 返回 EFAULT

发布于 2024-12-04 22:46:07 字数 708 浏览 8 评论 0原文

在Linux内核源代码中futex.c的futex_wake_op函数中,我试图理解控制如何到达this 点。当在上述函数中,futex_atomic_op_inuser 返回时,就会发生这种情况-EFAULT,但 uaddr2 是可写的。

但来自来源的 futex_atomic_op_inuser ,我看到它仅在 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))

futex_atomic_op_inuser依次调用 __futex_atomic_op 宏,我在代码中看到 -EFAULT,但我被告知 EFAULT 的路径不涉及调用 __futex_atomic_op code>

控件是如何到达上述点的(即if (!fshared)goto retry_private;)然后呢?

提前致谢!

In the futex_wake_op function of futex.c in the Linux kernel source,I was trying to understand how the control reaches this point.This happens when in the above said function,the futex_atomic_op_inuser returns -EFAULT,and yet the uaddr2 is writable.

But from the source of futex_atomic_op_inuser, I see that it returns -EFAULT only on if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int))).

futex_atomic_op_inuserin turn calls a the __futex_atomic_op macro where I see a -EFAULT in the code but I'm told that path to EFAULT does not involve calling __futex_atomic_op

How does the control reach the aforementioned point (i.e.if (!fshared)goto retry_private;)then?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2024-12-11 22:46:07

access_ok 只是为了检查地址范围对于给定的访问是否有效,即使如此,它也不能总是给出明确的答案。请参阅源代码中的注释:

 * 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. 地址有效但当前已换出。

access_ok is only meant to check if the address range is valid for the given access, and even for that it can not always give a definite answer. See the comments in the source:

 * 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.

Next, even if the block is valid, it may not be present in memory (swapped out). futex_atomic_op_inuser calls pagefault_disable, which disables the normal swap-in process so you will get a hard fault, returning -EFAULT from __futex_atomic_op.

In conclusion all this means that the point in question will be reached if:

  1. the address is invalid but slips past the check in access_ok, or
  2. it is valid but currently swapped out.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文