← 返回日报
精读 预计 1 分钟

The pandemic of incomplete OpenSSL error handling

摘要

作者指出 APT 等项目在使用 FIPS 系统时因 TLS 操作出错而报告 MD5 错误,引发讨论是否在 TLS 操作前调用 ERR_clear_error ()。作者反对因一个组件错误就全局丢弃错误,强调程序应较早失败或在确定安全时处理错误。文章揭示多年来该方法已成为代码库中的常见实践,上游甚至推荐此做法。这构成严重的系统性问题:不能随意丢弃不相关错误,必须修复导致错误的原因代码。同样存在第二种反模式:调用 OpenSSL 操作后仅检查顶级错误,若「不算太差」则丢弃全部错误。作者鼓励检查代码库中的 ERR_clear_error () 调用是否安全或属于上述反模式,并推荐使用 ERR_set_mark 来为多个 OpenSSL 操作创建和管理错误上下文标记。结尾向 OpenSSL 作者建议停止鼓励破坏信任的安全实践,并强调需要改进。

荐读理由

用 ERR_set_mark 推弹错误上下文,避免在多步 OpenSSL 操作前就 ERR_clear_error 导致无关错误被悄无声息丢弃。

原文

Recently a person reported a bug in APT saying that TLS is failing on FIPS systems with MD5 errors, and suggested we call ERR_clear_error() around TLS operations.

Like any serious software engineer would do, I said No. Just because one component failed to handle its errors does not mean I can go around and discard all errors in another place - the program should have failed earlier (or discarded the error when it was determined to be safe).

Little did I know that people have for years been using this approach as a best practice: Codebases everywhere are littered with calls to ERR_clear_error() before performing TLS, and upstream themselves suggest to do just that.

This is a major, systemic, pandemic of incomplete error handling. We cannot just discard unrelated errors if they become inconvenient. The code that caused the error needs to be fixed to handle it.

This isn’t all. It seems many authors are not familiar with libraries using a stack of errors, and there is a second anti-pattern:

Call an OpenSSL operation, check the top-level error, and then discard all errors if deemed “not too bad”. This has the same problem: Unrelated errors get silently discarded.

I would strongly encourage everyone to inspect their code bases for any calls to ERR_clear_error() and whether they are safe or one of the bad patterns above (or maybe you find a new pattern). You may want to use error stack functionality ofERR_set_mark (https://docs.openssl.org/3.4/man3/ERR_set_mark/) to essentially “push” and “pop” an error context of your own as a guard around multiple OpenSSL operations.

To the OpenSSL authors, I would suggest not encouraging devastating security practices that fundamentally break any trust in software.

We need to do better than this.

Lobsters · 2 赞 · 0 评 讨论 → 阅读原文 →

这条对你有帮助吗?