用户态应用程序中使用的 mincore 系统调用是什么?

What is the mincore syscall used for in userland applications?

Linux' mincore(2) 在用户态应用程序中有什么用?为什么它会暴露给非特权用户?

我可以想象一些数据库利用知道缓存了哪些页面,但还有哪些其他示例?

What is Linux mincore(2) useful for in userland applications?

我想说这很可能是基于意见的。分析、统计、性能评估和类似的东西浮现在脑海中。除此之外,我想不出其他现实的合法用例。

以下是我发现的一些使用 mincore 的程序示例(如您所见,所有 profiling/statistics 相关):

Why is it exposed to non-privileged users?

这实际上是一个围绕 one year ago, when the syscall's semantics weren't clearly defined, and the existence of such a syscall was rather questionable. Prior to kernel version 4.14.2 mincore could in fact have been abused to leak uninitialized kernel memory from user space (see CVE-2017-16994 and the relative Project Zero bug report 的好问题。

从那时起,系统调用已被修补并更新了其语义。进程通过调用它可以做的唯一事情就是查询有关其虚拟内存映射的信息。没有什么真正有害的,只是自我检查,因此可以用于非特权进程。没有真正的理由让它成为特权系统调用,如果这样做也可以被视为 API 破坏。