【问题标题】:What does __latent_entropy is used for in C__latent_entropy 在 C 中的用途是什么
【发布时间】:2021-08-29 18:13:00
【问题描述】:

我想了解在什么情况下我们在 C 函数签名中使用关键字 __latent_entropy。 我看到一些关于 GCC 插件的谷歌搜索结果,但我仍然不明白它的影响是什么。 谢谢

【问题讨论】:

  • @AdrianMole 链接的答案没有解释 __latent_entropy 的作用,它只是说它是一个 GCC 插件(并且 OP 显然已经知道这一点)。

标签: c linux-kernel


【解决方案1】:

您可以查看at the Kconfig's description 了解启用latent_entropy GCC 插件的作用(它还提到了它对Linux 性能的影响):

config GCC_PLUGIN_LATENT_ENTROPY
    bool "Generate some entropy during boot and runtime"
    help
      By saying Y here the kernel will instrument some kernel code to
      extract some entropy from both original and artificially created
      program state.  This will help especially embedded systems where
      there is little 'natural' source of entropy normally.  The cost
      is some slowdown of the boot process (about 0.5%) and fork and
      irq processing.

      Note that entropy extracted this way is not cryptographically
      secure!

      This plugin was ported from grsecurity/PaX. More information at:
       * https://grsecurity.net/
       * https://pax.grsecurity.net/

Here 你会发现latent_entropy GCC 插件的更详细的描述。部分内容取自链接:

...

this is where the new gcc plugin comes in: we can instrument the kernel's
boot code to do some hash-like computation and extract some entropy from
whatever program state we decide to mix into that computation. a similar
idea has in fact been implemented by Larry Highsmith of Subreption fame
in http://www.phrack.org/issues.html?issue=66&id=15 where he (manually)
instrumented the kernel's boot code to extract entropy from a few kernel
variables such as time (jiffies) and context switch counts.

the latent entropy plugin takes this extraction to a whole new level. first,
we define a new global variable that we mix into the kernel's entropy pools
on each initcall. second, each initcall function (and all other boot-only
functions they call) gets instrumented to compute a 'random' number that
gets mixed into this global variable at the end of the function (you can
think of it as an artificially created return value that each instrumented
function computes for our purposes). the computation is a mix of add/xor/rol
(the happy recovery Halvar mix :) with compile-time chosen random constants
and the sequence of these operations follows the instrumented functions's
control flow graph. for the rest of the gory details see the source code ;).

...

【讨论】:

  • 感谢@Luca Polito 提供所有这些参考资料。我仔细阅读并仔细阅读。我不会说我什么都懂:) 但它让我对这个主题有了一个全球性的想法。我仍然难以理解的是熵的概念。
  • @Stella 你可能想看看this brief definition of entropy in computer science,它可以帮助你理解熵的概念以及为什么在 Linux 启动时收集熵如此重要。 P.S.:如果我的回答对您有帮助,您可以将其标记为已接受。
猜你喜欢
  • 1970-01-01
  • 2015-06-24
  • 2010-09-09
  • 2013-11-03
  • 1970-01-01
  • 2014-01-15
  • 2011-08-07
  • 1970-01-01
相关资源
最近更新 更多