openbsds-philosophy.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><meta name="keywords" content="GNU, Emacs, Libre Software, Hurd, Guile, Guix" /><meta name="description" content="GNUcode.me is a website focusing on libre software projects, especially the GNU project." /><link type="application/atom+xml" rel="alternate" title="GNUcode.me -- Feed" href="/feed.xml" /><a rel="me" href="https://fosstodon.org/@thegnuguy"></a><link type="text/css" href="css/footer.min.css" rel="stylesheet"></link><link type="text/css" href="css/header.min.css" rel="stylesheet"></link><link type="text/css" href="css/main.min.css" rel="stylesheet"></link><title>OpenBSD's Philosophy — GNUcode.me</title></head><body><header><nav><ul><li><a href="index.html">GNUcode.me</a></li><li><a href="services.html">Services</a></li><li><a href="about.html">About</a></li><li><a href="business-ideas.html">Business-ideas</a></li></ul></nav></header><h1>OpenBSD's Philosophy</h1><main><section class="basic-section-padding"><article><h3>by Joshua Branson — April 17, 2024</h3><div><p>I have talked about OpenBSD before in this blog, and I recently
  2. watched a talk by OpenBSD's leader Theo de Raadt about <code>pledge ()</code> and
  3. <code>arc4random()</code>. He described OpenBSD's design philosophy so well, that
  4. I wanted to write it down. You should definitely take some time to
  5. hear Theo speak. He's entertaining, and his talks are super awesome!</p><p>So a long time ago (early 90s ?), a cracker (1) broke into Theo's
  6. OpenBSD's syslog. This got Theo to examine OpenBSD's source code to
  7. fix any lingering bugs, and he found a lot. He realized that trying
  8. to constantly examine source code to prevent bugs is a never ending
  9. process. He wanted to ensure code quality got better over time. He
  10. envision an operating system that that enforced code correctness like
  11. the below ASCII art shows.</p><pre><code>__________________________
  12. | Poorly written programs |
  13. | crash on OpenBSD. |
  14. | ---------------------- |
  15. | | Correctly written | |
  16. | | programs run well | |
  17. | | on OpenBSD. | |
  18. | ---------------------- |
  19. ---------------------------</code></pre><p>He wondered if he could create features to slightly narrow the things
  20. that applications could do. When poorly written programs run on
  21. OpenBSD, they crash in deterministic ways, but correct programs work
  22. just fine. Theo also made sure that &quot;mitigations&quot;, or checks to ensure
  23. a program's correctness, <em>cannot</em> be turned off on OpenBSD. If a user
  24. or a project manager has a problem with an application not working on
  25. OpenBSD due to a toggleable security feature, then the user or project
  26. manager will just turn off the feature. So to ensure that programs
  27. abide by the mitigations, OpenBSD enforces their security policies.</p><p>OpenBSD also makes it easy to use their security features. If they
  28. introduce a policy that is manatory, they try to make the API easy to
  29. use. If you create a security policy that is hard for the programmer
  30. to use, then the security policy won't be used.</p><p>When OpenBSD creates a new mitigation, their application porters port
  31. 3rd party software packages to OpenBSD. Typically these changes find
  32. their way into the upstream packages. What's awesome is that usually
  33. other operating systems start to use OpenBSD mitigations on their
  34. systems 5 years after OpenBSD introduced them. Windows, Mac, and
  35. Linux applications all benefit from the strict standards that OpenBSD
  36. creates. Theo's talks gave two examples for this: <code>pledge ()</code> and
  37. <code>arc4random ()</code>.</p><p>Here's a question for you. How do you get random data? Well you read
  38. <code>/dev/random</code> of course. Simple. Easy. Done. That used to be how
  39. things were handled. Apparently reading from <code>/dev/random</code> has some
  40. limitations that Theo mentioned. Can you read from <code>/dev/random</code>
  41. inside the kernel? Inside a library? In your libc? Reading from
  42. <code>/dev/random</code> is not perfect. Theo wanted to make something better.</p><p>OpenBSD created <code>arc4random ()</code> as a better source of entropy. It is
  43. a C function that almost any application can call (even the kernel),
  44. most of the time. This lets many applications, libraries, etc. easily
  45. use random numbers. What's surprizing to me is that many operating
  46. systems use <code>arc4random ()</code> or a function like it, so that more
  47. applictions can easily request random data. This function (or one
  48. like it) exists on your Android phone, iPhone, iMac, and sort of on
  49. Linux thanks to OpenBSD.</p><p>What's <code>pledge ()</code> ? Oh ho, let me tell you! Let's take a look at a
  50. typical program.</p><pre><code class="language-C">int main () {
  51. initialize_stuff();
  52. for (;;) {
  53. ;; let's run the program
  54. }
  55. }</code></pre><p>Most programs have an initialization phase followed by a loop, in
  56. which the application runs. The OpenBSD team realized that the
  57. initialize phase uses most of the system calls. After the initialize
  58. phase, the program typically needs less system calls. OpenBSD's
  59. <code>pledge ()</code> was created in response to this pattern present in most
  60. programs.</p><p><code>pledge ()</code> is a security call, by which an application tells the
  61. kernel, &quot;I pledge to only do these things and no other.&quot; For example,
  62. &quot;I pledge to only output text&quot;. Or &quot;I pledge to only access the
  63. internet and output text.&quot; If the application tries to do something
  64. that it has pledged not to do, then OpenBSD kills the application.</p><p>A really interesting blog post that talks about this is at
  65. <a href="https://justine.lol/pledge/">justine's blog</a>.</p><p>After watching two of Theo's talks, I am fairly convinced that his
  66. design goals are slowly working to make all POSIX operating systems
  67. more correct and secure. I used to dual boot Guix System and OpenBSD,
  68. but unfortunately my spare SSD busted. So for now I am only using
  69. Guix System. I personally prefer to use Guix System for my linode
  70. server (that powers this blog), because Guix makes it easy to manage
  71. servers.</p><p>I wish that the Guix developers could one day create Guix OpenBSD
  72. System, but I have been told that Guix System assumes your libc is
  73. <code>glibc</code> and that OpenBSD cannot currently make isolated build
  74. environments as well as Linux can. Also fun fact OpenBSD is not
  75. currently working on reproducible builds. :)</p><p>My two only minor complaints with OpenBSD currently are:</p><ul><li>I wish OpenBSD supported Wayland. This may happen in 6 months to a
  76. year. Fingers crossed.</li><li>A better filesystem: OpenBSD's FFS (fast file system) works, but it
  77. is possible to lose data in a crash. Filesystems are <em>really</em> hard
  78. to get right. Kent Overstreet has been working on bcachefs for
  79. almost a decade now, and it might soon become one of Linux's best
  80. filesystems (my opinion), so I don't blame OpenBSD for not trying to
  81. create a new next generational filesystem. Anybody want to spend 10
  82. years of their life creating an awesome filesystem that will
  83. probably only work well on OpenBSD? One might be able to port
  84. HammerFS to OpenBSD, and a basic read-only port does exist.</li></ul><p>If you want to try OpenBSD, give it a shot! It works really well on
  85. most lenovo laptops and most desktop machines.</p><ol><li>Nerdy computer people like me use the word &quot;hacker&quot; to mean someone
  86. who builds computer programs, and a &quot;cracker&quot; is someone who breaks
  87. into computer systems.</li></ol></div></article></section></main><footer><p>© 2020 Joshua Branson. The text on this site is free culture under the Creative Commons Attribution Share-Alike 4.0 International license.</p><p>This website is build with Haunt, a static site generator written in Guile Scheme. Source code is <a href="https://notabug.org/jbranso/gnucode.me">available.</a></p><p>The color theme of this website is based off of the famous <a href="#3f3f3f" target="_blank">zenburn</a> theme.</p></footer></body>