修复:在 0.1.6 之前,libyaml 容易受到来自恶意 YAML 有效负载的堆溢出攻击

Posted

技术标签:

【中文标题】修复:在 0.1.6 之前,libyaml 容易受到来自恶意 YAML 有效负载的堆溢出攻击【英文标题】:Fix for: Prior to 0.1.6, libyaml is vulnerable to a heap overflow exploit from malicious YAML payloads 【发布时间】:2014-05-20 02:28:50 【问题描述】:

在添加 vcr gem 后运行 rspec 时出现以下错误。按照建议简单地运行gem install psych -- --enable-bundled-libyaml 并不能解决问题。我正在使用 rbenv 和 ruby​​-build,我使用的是 ruby​​ 2.1.1。我该怎么做才能解决这个问题?

SafeYAML Warning
  ----------------

  You appear to have an outdated version of libyaml (0.1.4) installed on your system.

  Prior to 0.1.6, libyaml is vulnerable to a heap overflow exploit from malicious YAML payloads.

  For more info, see:
  https://www.ruby-lang.org/en/news/2014/03/29/heap-overflow-in-yaml-uri-escape-parsing-cve-2014-2525/

  The easiest thing to do right now is probably to update Psych to the latest version and enable
  the 'bundled-libyaml' option, which will install a vendored libyaml with the vulnerability patched:

  gem install psych -- --enable-bundled-libyaml

【问题讨论】:

在 2.0.0p353 上遇到完全相同的问题 【参考方案1】:

首先,您必须更新Ruby-build,他们最近修复了这个安全问题。现在,它安装 libyaml 0.1.6 来编译 Ruby。

$ rm -rf ~/.rbenv/plugins/ruby-build
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

重新编译,重新安装您正在使用的Ruby 版本,在我的情况下为2.0.0-p451

$ rbenv install 2.0.0-p451
rbenv: /home/ubuntu/.rbenv/versions/2.0.0-p451 already exists
continue with installation? (y/N) y
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
...

它在我的情况下有效。

【讨论】:

【参考方案2】:

我只是按照此回复https://***.com/a/9510209/816002 中的说明进行操作,似乎成功了。不过我的做法略有不同:

rvm pkg install libyaml
rvm get stable
rvm reinstall all --force

如果您使用的是系统 Ruby,这可能无济于事,而 rbenv 显然会有所不同。

【讨论】:

由于某种原因在 osx (10.9.2) rvm pkg install libyaml 上安装的是 0.1.5,所以这对我没有任何作用。 @TKH 看看这个答案是否有帮助:***.com/questions/22919990/… @ouranos 似乎 brew 已经安装了 0.1.6。尝试重新安装无济于事。 :( 我的 Fetching yaml-0.1.4.tar.gz 失败,rvm.io/src/yaml-0.1.4.tar.gz 出现 404 错误【参考方案3】:

作为 rvm 的用户,我通过构建 libyaml 的 0.1.6 版本,然后(重新)安装 Ruby,传递以下配置标志,设法让我的设置打球

rvm install 1.9.3 -- --with-libyaml-dir=/usr/local

希望这在短期内对人们有所帮助,直到尘埃落定。

【讨论】:

在有关此问题的链接帖子的所有建议中……这个有效!在此之后我不得不重新安装导致问题的gem,但是它起作用了!在没有此 rvm 安装的情况下重新安装 gem 并不能解决问题。【参考方案4】:

如果您使用的是 Mac OS X / Mavericks,那么您可能正在系统安装的 Ruby 上运行。 Thoughbot encourages you not to do this。我也遇到了这个问题,所以我按照他们的建议安装了brewrbenv,问题就消失了。

【讨论】:

【参考方案5】:

对于 rvm 这对我有用:

rvm pkg install libyaml
$LIBYAML_PATH will be the path where RVM installs the upated yaml
rvm get stable
rvm reinstall all --force --with-libyaml-dir=$LIBYAML_PATH

http://synaptian.com/2014/04/fixing-the-safeyaml-warning-on-ubuntu-12-04-with-rvm/

【讨论】:

以上是关于修复:在 0.1.6 之前,libyaml 容易受到来自恶意 YAML 有效负载的堆溢出攻击的主要内容,如果未能解决你的问题,请参考以下文章

酿造安装 libyaml 错误

如何在“Red Hat Enterprise Linux 7.4”上安装 libyaml-devel

在 C 中使用 libyaml 将 YAML 解析为值

找不到 libyaml-cpp.s.0.2

使用 libyaml 解析树状结构

使用 0.5 libyaml-cpp-dev 构建失败并出现 boost 错误