<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Stefan Heule&apos;s Blog</title>
    <description>Personal blog of Stefan Heule.  Topics include programming language research, computers and life in general.  Expect anything and nothing.
</description>
    <link>https://stefanheule.com/blog/</link>
    <atom:link href="https://stefanheule.com/blog/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Fri, 05 Jun 2026 11:39:55 -0700</pubDate>
    <lastBuildDate>Fri, 05 Jun 2026 11:39:55 -0700</lastBuildDate>
    <generator>Jekyll v4.3.2</generator>
    
      
      
      
      
      <item>
        <title>On the Importance of Safe Interfaces</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/safe-interfaces/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;The recent Amazon S3 outage is a good reminder that humans make errors, and sometimes issue commands that they didn&apos;t mean to issue.  On February 28th, Amazon&apos;s cloud offering S3 was partially offline for over four hours, because &lt;a href=&quot;https://aws.amazon.com/message/41926/&quot;&gt;a human ran a routine command and got some of the arguments wrong&lt;/a&gt;.  It&apos;s important to realize that it&apos;s not the human that is to blame, but rather the tool that did not sufficiently check the human&apos;s arguments.  &quot;Be more careful&quot; is not a viable strategy to ensure that a software system works reliably, as humans will always eventually make errors.  Instead, we need to design software with &lt;em&gt;safe interfaces&lt;/em&gt; that check for bad arguments.  In this post, I&apos;ll show another example of a badly designed interface, and how to fix it.&lt;/p&gt;

&lt;h3 id=&quot;safe-interface&quot;&gt;Safe Interface&lt;/h3&gt;

&lt;p&gt;I don&apos;t have a bullet-proof definition of what safe interfaces look like and it depends a lot on the context.  But some guiding principles might be:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;User inputs are validated, and invalid ones rejected.  For valid inputs that are uncommon, the user might be asked to confirm.&lt;/li&gt;
  &lt;li&gt;Actions that have big effects have to be confirmed, and the expected effects are shown to the user.  For instance, if a command takes &lt;em&gt;all&lt;/em&gt; of your data center offline, then asking for confirmation is the least that should be required.&lt;/li&gt;
  &lt;li&gt;Whenever possible, actions can be undone, so that errors can be easily recovered from.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;deleting-files-on-the-command-line&quot;&gt;Deleting Files on the Command Line&lt;/h3&gt;

&lt;p&gt;Another example of a tool without a safe interface is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt;.  It is an ancient tool on Unix systems to delete files, and programmers and system administrators often use it on a daily basis.  However, files deleted this way are not meant to be recovered&lt;sup id=&quot;fnref:recovery&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:recovery&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;, but instead deleted permanently.  This leaves the door wide open for data loss if the arguments to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; are ever entered incorrectly.  Unsurprisingly, the internet is &lt;a href=&quot;http://superuser.com/questions/553973/i-just-ran-rm-accidentally-any-fix&quot;&gt;full&lt;/a&gt; &lt;a href=&quot;http://stackoverflow.com/questions/474547/can-i-recover-a-file-in-linux-which-i-accidentally-did-an-rm-on&quot;&gt;of&lt;/a&gt; &lt;a href=&quot;http://serverfault.com/questions/206259/accidentally-rm-rf-usr-as-root-what-now&quot;&gt;people&lt;/a&gt; &lt;a href=&quot;http://unix.stackexchange.com/questions/156295/accidentally-rm-r-the-wrong-etc-folder-help/156299&quot;&gt;asking&lt;/a&gt; &lt;a href=&quot;http://www.linuxquestions.org/questions/linux-newbie-8/accidentally-rm-fr-in-root-directory-116510/&quot;&gt;how&lt;/a&gt; &lt;a href=&quot;https://ubuntuforums.org/showthread.php?t=1027065&quot;&gt;to&lt;/a&gt; &lt;a href=&quot;http://askubuntu.com/questions/625991/accidentally-run-command-rm-r-in-amazon-ec2-unable-to-login&quot;&gt;recover&lt;/a&gt; &lt;a href=&quot;https://www.reddit.com/r/linuxquestions/comments/1tqltj/accidentally_removed_a_very_important_file_using/&quot;&gt;files&lt;/a&gt; inadvertently deleted this way.  I don&apos;t blame any of these people, as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; is poorly designed to be used on a regular basis;  its operation is permanent, and there are no safeguards against deleting even the most important files.  Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm -rf /&lt;/code&gt;, you can even delete &lt;em&gt;everything&lt;/em&gt; on your computer (including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;So, we need a better alternative, and &lt;a href=&quot;https://github.com/andreafrancia/trash-cli&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;trash-cli&lt;/code&gt;&lt;/a&gt; is just that.  It provides the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;trash-put&lt;/code&gt; with roughly the same interface as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt;, but moves files to the trashcan rather than permanently deleting them.  This allows inadvertently deleted files to be easily restored.  To avoid having to remember not to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt;, we can instead create an alias by adding the following line to our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.bashrc&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.zshrc&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;alias rm=&apos;trash-put&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Possibly an even better solution is to use a new name, and override &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; to remind you not to use it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;alias rm=&apos;echo &quot;use d instead to avoid losing files.&quot;; false&apos;
alias d=&apos;trash-put&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If for some reason we really need to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;trash-put&lt;/code&gt;, we can still do so via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\rm&lt;/code&gt; to bypass our alias.  But doing so should only be done in very rare cases and after carefully checking the command.  And because the alias only shadows the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; binary in the shell, we can still run scripts that rely on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No more lost files, as they can be easily restored with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;trash-restore&lt;/code&gt;.  While this solution still leaves room for further improvement (e.g., checking against deleting files that aren&apos;t meant to be deleted, such as system files), it&apos;s a big step towards a safe interface to deleting files.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:recovery&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Sometimes, files can still be recovered with specialized recovery tools, though this is unreliable and only works well if the error is detected relatively quickly, before the deleted files get overwritten. &lt;a href=&quot;#fnref:recovery&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

        </description>
        <pubDate>Sun, 05 Mar 2017 00:00:00 -0800</pubDate>
        <link>https://stefanheule.com/blog/safe-interfaces/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/safe-interfaces/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>Weather Information for Obsidian</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/weather-information-for-obsidian/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;&lt;em&gt;See &lt;a href=&quot;/blog/obsidian-a-usable-and-elegant-analog-watchface-for-the-pebble-time/&quot;&gt;the original blog post&lt;/a&gt; if you want to learn about Obsidian in general.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;By far the most requested feature for  Obsidian, my watch face for the Pebble smartwatch, was to add weather information.  Over the last few days, I&apos;ve implemented this feature.  It&apos;s fully configurable and the weather information moves out of the way of watch hands so that it is never obstructed.&lt;/p&gt;

&lt;p&gt;Here are a few screenshots of what the weather information looks like on the Pebble Time&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/weather.png&quot; alt=&quot;Weather information&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;and on the Pebble Time Round&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/chalk/weather.png&quot; alt=&quot;Weather information&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;The source of the weather information can be configured to be &lt;a href=&quot;http://openweathermap.org/&quot;&gt;openweathermap.org&lt;/a&gt; or &lt;a href=&quot;http://forecast.io/&quot;&gt;forecast.io&lt;/a&gt;, the temperature can be displayed in Celsius or Fahrenheit, and the color can be fully customized.  By default Obsidian will display the current weather conditions, but this can be changed to today&apos;s conditions.  One interesting feature that I haven&apos;t seen in other watch faces is that Obsidian allows for a mix between current conditions and today&apos;s weather in the following way:  In the first part of the day, Obsidian will display today&apos;s weather, and then at 2pm it will switch to the current conditions.  That allows the user to get a sense of today&apos;s weather in the morning with the day&apos;s maximum temperature (e.g., to decide what to wear), and then around the time of the highest temperature, the watch will switch to current conditions as today&apos;s high is no longer useful information.  Finally, weather information is displayed for the current location by default, but it is possible to set a fixed location.&lt;/p&gt;

&lt;p&gt;I have borrowed some of the fonts from &lt;a href=&quot;https://github.com/groyoh/minimalin/&quot;&gt;Minimalin&lt;/a&gt;, another great watch face for the Pebble.  Thanks to the people behind Minimalin for making everything available.  The latest version of Obsidian can be downloaded here:   &lt;br /&gt;
&lt;a href=&quot;/download/pebble/obsidian-3.6.pbw&quot;&gt;obsidian-3.6.pbw&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Furthermore, Obsidian is also source, and you can check it out at &lt;a href=&quot;https://github.com/stefanheule/obsidian&quot;&gt;github.com/stefanheule/obsidian&lt;/a&gt;.&lt;/p&gt;

        </description>
        <pubDate>Sat, 18 Jun 2016 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/weather-information-for-obsidian/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/weather-information-for-obsidian/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>How Many x86-64 Instructions Are There Anyway?</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/how-many-x86-64-instructions-are-there-anyway/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;x86 is an enormously popular instruction set that is used on most desktop computers and servers (but usually not on mobile devices like phones).  Given this wide use, it might seem like an easy question to ask how many x86 instructions there are, but it turns out this is more intricate than it looks.&lt;/p&gt;

&lt;h3 id=&quot;background&quot;&gt;Background&lt;/h3&gt;

&lt;p&gt;x86 is the name of a whole family of so-called instruction set architectures (ISA for short).  The ISA defines the available instructions of a CPU, but also the registers, the memory architecture, how interrupts are handled, and much more.  It is different from the microarchitecture, though, which determines how the ISA is implemented.  Different microarchitectures can implement the same ISA, which is what happens with different AMD and Intel microarchitectures implementing essentially the same ISA.
Since the introduction of x86 by Intel in 1978, the architecture has evolved extensively, but with almost full backward compatibility.  Partly for this reason, the instruction set is full of weird corner-cases and historical artifacts.  Here, I will look at the 64-bit variant (sometimes called x86-64) of the ISA and attempt to count the number of instructions.  Specifically, the ISA from the Haswell microarchitecture, one of the latest ISA available at the time of writing.  Due to the backward compatibility, this instruction set still includes most of the instructions from the very first generation of x86, and anything in between.&lt;/p&gt;

&lt;h3 id=&quot;attempts-1-and-2-mnemonics&quot;&gt;Attempts 1 and 2: Mnemonics&lt;/h3&gt;

&lt;p&gt;Machine instructions (the ones and zeros that tell your computer what to do next) have a portion called the &lt;em&gt;opcode&lt;/em&gt; that determines what operation is performed.  A mnemonic is a symbolic name for these opcodes.  For instance, to add one to the &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;eax&lt;/code&gt; register, one could use the instruction &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $1, %eax&lt;/code&gt;.  Here, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl&lt;/code&gt; is the mnemonic, and so we can count the number of unique mnemonics to determine the number of instructions.  I&apos;ve written a small program to do this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./instr-count &lt;span class=&quot;nt&quot;&gt;--mode&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;mnemonic_att&quot;&lt;/span&gt;
1279&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Great, so we are done and there are 1,279 instructions, right?  Actually, the story is more complicated.  Those familiar with assembly will have realized that the &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;l&lt;/code&gt; in &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl&lt;/code&gt; is a suffix that indicates the bit width of the operands.  For instance, to add one to a 16-bit register (instead of the 32-bit register &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;eax&lt;/code&gt;), one would use &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addw $1, %ax&lt;/code&gt;.  Both of these instructions are doing addition, maybe we should not count them separately.  In fact, had we used Intel syntax for the instructions, then the same operation would be written as &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add eax, 1&lt;/code&gt; (note the absence of a width suffix, and the inverted ordering of operands).  Let&apos;s try that:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./instr-count &lt;span class=&quot;nt&quot;&gt;--mode&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;mnemonic_intel&quot;&lt;/span&gt;
981&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;attempt-3-mnemonics-and-operand-types&quot;&gt;Attempt 3: Mnemonics and Operand Types&lt;/h3&gt;

&lt;p&gt;If we look a little closer at mnemonics, we find that the situation is actually not so simple.  Let&apos;s again look at the two instructions to add a constant to a 16 and 32-bit register, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addw $0x1, %ax&lt;/code&gt; and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $0x1, %eax&lt;/code&gt;, respectively&lt;sup id=&quot;fnref:syntax&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:syntax&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.  It turns out, that on 64-bit machines we consider here, they actually have relatively different semantics.  The former just adds one to &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;ax&lt;/code&gt;.
On the other hand, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $0x1, %eax&lt;/code&gt; also does the addition, but additionally zeros out the upper 32 bits of &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;rax&lt;/code&gt;.  Here is an example illustrating this behavior:&lt;/p&gt;

&lt;figure&gt;
  &lt;img style=&quot;width: 32.94117647058823rem&quot; src=&quot;/blog/img/posts/x86-add-32vs64.png&quot; alt=&quot;Example of 32 and 64-bit addition&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;Note that the 32-bit addition on the right zeroes out the upper 32 bits of &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;rax&lt;/code&gt; (marked in red), but the 16-bit addition (as well as the 8-bit addition not shown here) don&apos;t do that.  That doesn&apos;t really seem like the same instruction any longer, even if both have the same (Intel) mnemonic.  For another example why mnemonics can be misleading consider the instruction to perform a 32-bit signed multiplication: &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull&lt;/code&gt;.  There is a variant that multiplies two registers, and there is a variant that multiplies two registers and a constant&lt;sup id=&quot;fnref:imull&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:imull&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.  Again, even though both of these share the same mnemonic, they hardly seem like the same instruction (one multiplies two numbers, the other three numbers).&lt;/p&gt;

&lt;p&gt;Therefore, maybe we should really count all the different combinations of mnemonic as well as the argument types.  For instance, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $1, %eax&lt;/code&gt; would be &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add_imm32_r32&lt;/code&gt;.  This ensures that we correctly identify the examples shown as different instructions, and leaves us with 3,683 instructions:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./instr-count &lt;span class=&quot;nt&quot;&gt;--mode&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;operand_type&quot;&lt;/span&gt;
3683&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;attempt-4-mnemonics-and-operand-widths&quot;&gt;Attempt 4: Mnemonics and Operand Widths&lt;/h3&gt;

&lt;p&gt;Now we have a lot of instructions, and some of them seem like they are not really different instructions.  For instance, the instruction to add a constant to a 32-bit register and the instruction to add a constant to a 32-bit memory location are counted separately, when the &lt;em&gt;operation&lt;/em&gt; they perform could be argued to be identical.  Thus, maybe a better way would be to consider the mnemonic in addition to the operand &lt;em&gt;width&lt;/em&gt;.  Our running example would be &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add_32_32&lt;/code&gt;, regardless of whether the operand is a register, memory location or constant.  This way, we end up with 2,034 instructions:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./instr-count &lt;span class=&quot;nt&quot;&gt;--mode&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;operand_width&quot;&lt;/span&gt;
2034&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;attempt-5-counting-everything-added-2018-08-09&quot;&gt;Attempt 5: Counting everything (added 2018-08-09)&lt;/h3&gt;

&lt;p&gt;All the attempts so far assume that we actually know what instructions a given CPU has, and that there is a textual representation for these instructions.
However, these assumptions might be less well-founded than it seems, as people have discovered hidden and undocumented instructions in modern CPUs.
The most thorough examination of the space of all instructions has been done by Christopher Domas with &lt;a href=&quot;https://github.com/xoreaxeaxeax/sandsifter&quot;&gt;sandsifter&lt;/a&gt;,
where he systematically explores the space of bit-level encoded instructions.  Through clever tricks he is able to tell which bit
sequences make up valid instructions, and which don&apos;t.  This has the advantage of making very few assumptions and in principle allows
us to count all bit sequences that denote valid instructions.  Note that this will
count &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $1, %eax&lt;/code&gt; and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl $2, %eax&lt;/code&gt; as separate
instructions, because assembled as bits they are &lt;code class=&quot;highlight language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;mh&quot;&gt;0x83&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xC0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x01&lt;/span&gt;&lt;/code&gt; and &lt;code class=&quot;highlight language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;mh&quot;&gt;0x83&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xC0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x02&lt;/span&gt;&lt;/code&gt;,
respectively.  And there is another problem: there are actually too many instructions to count them all this way.  On x86-64, instructions can be up to 15 bytes long, making far to many to efficiently count them.&lt;/p&gt;

&lt;p&gt;But even if we don&apos;t get an actual number here, it is another interesting way to (at least in principle if not in practice) count instructions.  &lt;a href=&quot;https://github.com/xoreaxeaxeax/sandsifter/blob/master/references/domas_breaking_the_x86_isa_wp.pdf&quot;&gt;Christophers whitepaper&lt;/a&gt; is worth a read for much more details on his approach and findings.&lt;/p&gt;

&lt;h3 id=&quot;its-all-wrong&quot;&gt;It&apos;s All Wrong&lt;/h3&gt;

&lt;p&gt;Unfortunately, there are even more weird corner cases and historical artifacts in x86 that make counting instructions hard.  For instance, we used mnemonics to group the same &quot;mathematical operation&quot; regardless of the operands, but it turns out that doing a bitwise &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;xor&lt;/code&gt; operation is done using &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;xor&lt;/code&gt; (in Intel syntax), but also &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;pxor&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;vpxor&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;vxorpd&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;vxorps&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;xorpd&lt;/code&gt;, and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;xorps&lt;/code&gt; depending on the operand size and other things (and even more in AT&amp;amp;T syntax)&lt;sup id=&quot;fnref:xor&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:xor&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;.  So if attempt 2 tries to group the same operation regardless of the operation, then that count is actually too high.&lt;/p&gt;

&lt;p&gt;And on the other end of the spectrum, we tried to count every different operation separately in attempt 3.  However, it turns out there are instructions that really are a family of instructions.  For instance, consider &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;cmpsd&lt;/code&gt; that compares two floating point numbers.  A third operand, an 8-bit constant, determines if the comparison is for equality, inequality, if the first number is larger, and 5 more variants.  These clearly seem like different instructions, yet we have counted them as a single one.&lt;/p&gt;

&lt;p&gt;Unfortunately, I can&apos;t think of an easy automatic way of counting such nuances, so I will leave it at the numbers I have.&lt;/p&gt;

&lt;p&gt;Even more to the extreme we could go with attempt 5, where I suggested counting every valid bit sequeence and point to some work that has attempted to move in that directly.  Unfortunately there are too many to actually get a count, but it is an interesting way to think about the problem nonetheless.&lt;/p&gt;

&lt;h3 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;As I have hopefully convinced you by now, this innocent looking question is more difficult to answer than it might seem.  It depends on your notion of what an instruction is, and is complicated by the many intricacies of the complex x86-64 instruction set.  Here is an overview of possible answers:&lt;/p&gt;

&lt;style&gt;
table:nth-of-type(1) th:nth-of-type(1) {
    width: 30%;
}
&lt;/style&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Measure&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Count&lt;/th&gt;
      &lt;th&gt;Comment&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;AT&amp;amp;T mnemonic &lt;br /&gt; (e.g., &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl&lt;/code&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;1,279&lt;/td&gt;
      &lt;td&gt;Counts the number of unique mnemonics in AT&amp;amp;T syntax.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Intel mnemonic &lt;br /&gt; (e.g., &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add&lt;/code&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;981&lt;/td&gt;
      &lt;td&gt;This is a rough estimate of the number of different kinds of operations the x86 instruction set can perform, ignoring the operand type and size.  There are various caveats as described earlier, such as some operations having multiple different mnemonics.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mnemonic and operand types &lt;br /&gt; (e.g., &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add_r32_imm32&lt;/code&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;3,683&lt;/td&gt;
      &lt;td&gt;Distinguishes instructions in every way possible and is thus a sort of upper bound on the number of instructions.  If you are looking for a very fine-grained notion of instruction, this is a good measure.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Mnemonic and operand width &lt;br /&gt; (e.g., &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;add_32_32&lt;/code&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;2,034&lt;/td&gt;
      &lt;td&gt;This is an estimate of the number of different kinds of instructions, if an operation on 8 bits is considered to be different from the same operation on 16 bits (because sometimes, these actually have different semantics, as shown with the zeroing of the upper 32 bits for the &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;addl&lt;/code&gt; instruction).  Does not distinguish instructions that operate on registers vs. constants vs. memory locations.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Every valid bit sequence &lt;br /&gt; (e.g., &lt;code class=&quot;highlight language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;mh&quot;&gt;0x83&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xC0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x01&lt;/span&gt;&lt;/code&gt;)&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;?&lt;/td&gt;
      &lt;td&gt;Counts every bit seqeuence that makes a valid x86 instruction.  Unfortunately there are too many to count.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Personally, the 4th attempt seems to capture my intuitive understanding of what an instruction is the closest.  So, if I ever have to cross the &lt;a href=&quot;https://www.youtube.com/watch?v=Wpx6XnankZ8&quot;&gt;bridge of death&lt;/a&gt; and get asked how many x86-64 instructions there are, I shall answer 2,034.&lt;/p&gt;

&lt;p&gt;All the numbers in this blog post (except for attempt 5) have been obtained through a small program making use of our &lt;a href=&quot;https://github.com/StanfordPL/x64asm&quot;&gt;awesome C++11 library for working with x86-64 assembly&lt;/a&gt;.  Just like the library, my program is &lt;a href=&quot;https://github.com/stefanheule/x86_64-instruction-count&quot;&gt;available as open source on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:syntax&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;From here on I will use AT&amp;amp;T syntax because that&apos;s what I&apos;m used to.  It will not have any effect on the numbers. &lt;a href=&quot;#fnref:syntax&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:imull&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Actually, the situation is even more complicated for &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull&lt;/code&gt; (no surprise at this point).  There are seven different variants:  The first one, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32&lt;/code&gt;, just takes a single register and uses &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;eax&lt;/code&gt; as an implicit input, and stores 64 bits of output.  Next, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_r32&lt;/code&gt; and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_r32&lt;/code&gt; multiply two 32-bit numbers and store 32 bits of output, and finally &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_m32_imm8&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_r32_imm8&lt;/code&gt;, &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_r32_imm32&lt;/code&gt;, and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;imull_r32_m32_imm32&lt;/code&gt; multiply two registers (or memory locations) as well as a constant (8 or 32 bits) and result in 32 output bits. &lt;a href=&quot;#fnref:imull&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:xor&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Some of these different mnemonics to perform a bitwise exclusive or operation are due to the operand size.  It turns out that for newer instructions that work on the &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;xmm&lt;/code&gt; and &lt;code class=&quot;highlight language-asm&quot; data-lang=&quot;asm&quot;&gt;ymm&lt;/code&gt; vector registers, different mnemonics depending on the operand size, both in AT&amp;amp;T as well as in Intel syntax.  For the bitwise operations, there are also different mnemonics depending on the type of data (integer, single precision floating point or double precision floating point), even though the operation is on the bit level and, therefore, the same for all types (yes, different mnemonics perform semantically exactly the same operation).  This is because internally, processors may have several pipelines for different data types for efficiency reasons, and thus using a bitwise mnemonics of the wrong type will compute the result correctly, but may be slower because the data has to be moved from one pipeline to another. &lt;a href=&quot;#fnref:xor&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

        </description>
        <pubDate>Mon, 07 Mar 2016 00:00:00 -0800</pubDate>
        <link>https://stefanheule.com/blog/how-many-x86-64-instructions-are-there-anyway/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/how-many-x86-64-instructions-are-there-anyway/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>Obsidian: A Usable and Elegant Analog Watch Face for the Pebble Time</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/obsidian-a-usable-and-elegant-analog-watchface-for-the-pebble-time/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;&lt;em&gt;Update (2018-08-09): I have been informed that the Pebble app store is no longer accessible.
Thus, I&apos;m making the watchface available directly from this site, see &lt;a href=&quot;#downloading-obsidian&quot;&gt;below for instructions&lt;/a&gt; on how to install.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update (2016-06-18): Obsidian now also supports weather information, see &lt;a href=&quot;/blog/weather-information-for-obsidian/&quot;&gt;the corresponding blog post about it&lt;/a&gt;.  All screenshots here have been updated to include weather information.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update (2015-11-30): Obsidian now supports the original Pebble and the new Pebble Time Round.  See the end of this post for more.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I have written a watch face application for the Pebble Time that I call Obsidian and I&apos;d like to introduce it here.  The main goal behind Obsidian is to put utility and practicality above all else, and only attempt to improve aesthetics if it does not interfere with that goal.  Some of the main features are simplicity, high contrast colors and a date display that is never obstructed by the watch hands.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/overview.png&quot; alt=&quot;Obsidian watch face&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;In fact, the reason I wrote the watch face in the first place was my frustration when I used other analog watch faces and wasn&apos;t able to tell today&apos;s date, just because it was 3:14 pm (this caused the watch hands to cover the date display as it would on traditional watches).  Instead, I&apos;ve chosen to move the date a little if necessary in Obsidian&lt;sup id=&quot;fnref:name&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:name&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;, so that it is visible no matter the position of the watch hands.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/date.png&quot; alt=&quot;The date is always visible on the Obsidian watch face&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;Another important aspect for a smartwatch is to warn the user if the connection to the phone is lost (or regained).  Obsidian does this through two short vibrations, followed by a message on screen that is shown for five seconds.  After that, the message disappears and only a small icon remains to keep the watch fully usable even without a smartphone connected&lt;sup id=&quot;fnref:icon&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:icon&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/bluetooth.png&quot; alt=&quot;Bluetooth indicator and message popups&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;The Pebble Time has a surprisingly long battery life compared to other smartwatches, but at some point it will need to be re-charged, too.  To not miss that point, Obsidian has a small battery icon in the top right corner, and turns the background yellow, orange and finally red as the battery level reaches 30%, 20%, and 10%, respectively.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/battery.png&quot; alt=&quot;Low battery warnings&quot; /&gt;
  
&lt;/figure&gt;

&lt;h3 id=&quot;configurability&quot;&gt;Configurability&lt;/h3&gt;

&lt;p&gt;I like the default settings, but I acknowledge that not everybody has the same preferences as I have, which is why I made most aspects of the watch face configurable.  It&apos;s possible to change any color, hide the battery or Bluetooth icons and not vibrate upon losing the phone connection.  Here are a few examples of the possibilities:&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/basalt/theme-overview-1.png&quot; alt=&quot;Different appearance settings&quot; /&gt;
  
&lt;/figure&gt;

&lt;h3 id=&quot;downloading-obsidian&quot;&gt;Downloading Obsidian&lt;/h3&gt;

&lt;p&gt;Pebble&apos;s app store is no longer functional after the company shut down.  Instead, download the installation file here:
&lt;a href=&quot;/download/pebble/obsidian-3.6.pbw&quot;&gt;obsidian-3.6.pbw&lt;/a&gt;, then
install the file on your smartphone.&lt;/p&gt;

&lt;p&gt;Furthermore, it is &lt;a href=&quot;https://github.com/stefanheule/obsidian&quot;&gt;open source and available on Github&lt;/a&gt;, where you can also see more screenshots as well as an overview of all available settings.  Feel free to give it a try, and let me know what you think!&lt;/p&gt;

&lt;h3 id=&quot;updating-obsidian-for-aplite-and-chalk&quot;&gt;Updating Obsidian for Aplite and Chalk&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;(added on 2015-11-30)&lt;/em&gt; Pebble offers smartwatches of three different hardware platform.  They started with the original Pebble (&lt;em&gt;aplite&lt;/em&gt; platform),
which was slightly larger and black-and-white only.  They then
added the Pebble Time (&lt;em&gt;basalt&lt;/em&gt; platform), for which Obsidian was originally written.
Recently the Pebble Time Round (&lt;em&gt;chalk&lt;/em&gt; platform) got added to the collection, which is a round smartwatch that is thinner and lighter.
Since writing this blog post, I&apos;ve added support for all three platforms to Obsidian.
Because Obsidian is an analog watch face, it looks great on Chalk:&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://github.com/stefanheule/obsidian/raw/master/screenshots/chalk/overview.png&quot; alt=&quot;Obsidian watch face on Chalk&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;On Aplite, Obsidian looks a bit boring, because only two colors are available.  Additionally, the drawing APIs are more limited
and don&apos;t support anti-aliasing, making edges look a bit rough.&lt;/p&gt;

&lt;p&gt;Obsidian remains fully configurable on all platforms.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:name&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;The name &lt;em&gt;Obsidian&lt;/em&gt; is a type of rock and thus a play on Pebble. &lt;a href=&quot;#fnref:name&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:icon&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Of course, the Bluetooth icon also cannot be covered by the watch hands, in case you wondered. &lt;a href=&quot;#fnref:icon&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

        </description>
        <pubDate>Wed, 09 Sep 2015 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/obsidian-a-usable-and-elegant-analog-watchface-for-the-pebble-time/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/obsidian-a-usable-and-elegant-analog-watchface-for-the-pebble-time/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>The Surprising Reasons I Like the Pebble Time and Smartwatches in General</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/the-surprising-reasons-i-like-the-pebble-time-and-smartwatches-in-general/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;I was skeptical about smartwatches and wasn&apos;t sure whether they are useful enough to offset the annoyance of having yet another expensive device that requires charging.  Especially the thought of owning a smartwatch that doesn&apos;t even do the &lt;em&gt;watch&lt;/em&gt; part well sounded terrible; I don&apos;t want to have to press a button first to turn on the screen, or turn my wrist in just the right way so that the sensors pick it up and turn on the screen.  Luckily, I found the Pebble Time, a smartwatch that features an always-on e-ink display which solves at least the watch problem.  Furthermore, I actually like my Pebble Time more than I thought I would, and I found many of the reasons unexpected.  In this post, I&apos;d like to highlight some of these.  Some are obvious in hindsight, but maybe there are other people out there who equally don&apos;t have a good sense of the usefulness of smartwatches.  In essence, this is the article that I would have wanted to read when I was deciding if I should get a smartwatch.&lt;/p&gt;

&lt;p&gt;However, this is not a Pebble Time review;  and, in fact, many of the reasons (but not all) are not specific to the Pebble Time, but apply to smartwatches in general.  There are enough articles that describe its great features like the always-on display and the very long battery life, and that talk about the not-so-great aspects like the low resolution of the display or the lack of a GPS or heart-rate sensors.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/blog/img/posts/pebble.jpg&quot; alt=&quot;Pebble Time&quot; /&gt;
  
&lt;/figure&gt;

&lt;h3 id=&quot;silent-and-noticeable-notifications&quot;&gt;Silent and Noticeable Notifications&lt;/h3&gt;

&lt;p&gt;The Pebble Time allows you to show (some or all) notifications from your smartphone on your watch and allows some interactions with them.  For instance, it can show arriving emails and you can archive them, or dismiss the notification.  The built-in microphone even allows you to respond, though to me that seems more of a gimmick&lt;sup id=&quot;fnref:mic&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:mic&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.  Having some of the notifications from your phone on your wrist is great, but I find another aspect even better.  But let&apos;s first look at why notifications on phones are annoying:&lt;/p&gt;

&lt;p&gt;Smartphones are surprisingly bad at notifying the user about incoming emails, texts, calls or other things;  they either are too loud, or not noticeable enough.  We can choose to use a ringtone and risk having the phone go off at inconvenient times like during a meeting or a presentation.  Alternatively we can turn the phone silent, and miss possibly important notifications.  Neither is great, and even the vibrate-only option doesn&apos;t work well;  it&apos;s still common to miss notifications, even if the phone is carried on person, and yet the vibration can be clearly audible depending on the background noise level and the exact position of the phone (if it touches, say, a chair through my pocket in just the right way, the vibration is seemingly louder than even a ringtone?!).&lt;/p&gt;

&lt;p&gt;With smartwatches like the Pebble Time, notifications are finally silent &lt;em&gt;and&lt;/em&gt; noticeable.  Because the watch touches the skin directly, the vibration can be soft yet clearly noticeable to the user (and only the user, as opposed to other people in close proximity).  No more missed notifications and no more embarrassing moments when notifications are heard by others at inappropriate times.&lt;/p&gt;

&lt;h3 id=&quot;notifications-everywhere&quot;&gt;Notifications Everywhere&lt;/h3&gt;

&lt;p&gt;Another source of missed notifications used to be when I&apos;m close to my phone, but not actually carry it on me.  Maybe I&apos;m in my office and the phone sits on the desk, or I&apos;m at home cooking dinner, and the phone is in my room charging.  With the Pebble Time, I have the freedom to move around without my phone and not miss notifications.&lt;/p&gt;

&lt;h3 id=&quot;never-forget-your-phone&quot;&gt;Never Forget Your Phone&lt;/h3&gt;

&lt;p&gt;Like most smartwatches, the Pebble Time is connected to your phone via Bluetooth.  If that connection is lost, then the watch can notify you by vibrating and showing a short notification on the display.  This turns your watch into a great ally to prevent forgetting your phone:  If you ever accidentally leave your phone behind, the watch will remind you as soon as you step outside the Bluetooth range, which is typically around 10 meters.&lt;/p&gt;

&lt;h3 id=&quot;fitness-and-sleep-tracking-on-your-terms&quot;&gt;Fitness and Sleep Tracking on your Terms&lt;/h3&gt;

&lt;p&gt;Fitness trackers like the devices from FitBit are getting a lot of attention lately, and thanks to the accelerometer the Pebble Time can track your steps, too.  It&apos;s nice to be able to collect information like this and also fully be in control of where that data is stored and with whom it is shared.  Unlike FitBit, which stores all the information on their servers, you can choose a fitness tracking app and therefore decide what happens with your data.
The same applies for tracking your sleep; you pick the app, and you own the data.&lt;/p&gt;

&lt;h3 id=&quot;silent-alarm&quot;&gt;Silent Alarm&lt;/h3&gt;

&lt;p&gt;The vibration function of the Pebble Time can also be used as a silent alarm clock.  This is convenient if you need to get up before somebody sleeping in the same room, but I&apos;m now using it even if I&apos;m by myself.  I like waking up to a gentle vibration on the wrist rather than a blaring alarm clock.&lt;/p&gt;

&lt;h3 id=&quot;water-resistance&quot;&gt;Water Resistance&lt;/h3&gt;

&lt;p&gt;Most smartwatches are water resistant&lt;sup id=&quot;fnref:resistance&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:resistance&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.  For instance, the Apple Watch or the Moto 360 are rated as water resistant according to the &lt;a href=&quot;https://en.wikipedia.org/wiki/IP_Code&quot;&gt;IPX7 standard&lt;/a&gt;, which should allow these devices to stay submerged for 30 minutes at up to 1m in fresh water.  However, this essentially only protects the device from light splashes and the like.  In fact &lt;a href=&quot;https://manuals.info.apple.com/MANUALS/1000/MA1708/en_US/apple_watch_user_guide.pdf&quot;&gt;Apple specifically tells users&lt;/a&gt; to avoid submerging the watch for long times, swimming and showering.  In particular showering is a bad idea, because the water hits the watch at a velocity that IPX7 is not meant to protect from.  The Pebble Time on the other hand is rated as water resistant at up to 30m (according to &lt;a href=&quot;https://en.wikipedia.org/wiki/Water_Resistant_mark&quot;&gt;ISO 22810&lt;/a&gt;), and can be worn while showering or swimming.  This turns out to be super convenient, as I can keep the watch on for essentially everything I do.  I wouldn&apos;t take it diving, but that&apos;s not something I do daily.&lt;/p&gt;

&lt;h3 id=&quot;automatic-timezone&quot;&gt;Automatic Timezone&lt;/h3&gt;

&lt;p&gt;One thing that smartphones are good at is getting the correct local time from the network automatically, no matter what timezone you are in.  Since smartwatches connect to the phone, your watch will also always show the correct local time, just as it should.  This is in contrast to most regular wrist watches.&lt;/p&gt;

&lt;h3 id=&quot;programmable-in-c&quot;&gt;Programmable in C&lt;/h3&gt;

&lt;p&gt;Pebble watches are programmable in C&lt;sup id=&quot;fnref:jspebble&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:jspebble&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;, and this may not excite most people, but I found it quite fun to play with.  There is something exciting about programming an embedded device with restricted resources in a low-level programming language like C, and even non-experts can write a useful app.  I wrote an analog watch face that I now use daily.  You can &lt;a href=&quot;/blog/obsidian-a-usable-and-elegant-analog-watchface-for-the-pebble-time/&quot;&gt;find out more about it here&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;wrapping-up&quot;&gt;Wrapping Up&lt;/h3&gt;

&lt;p&gt;For me, there is no single killer application (though the silent yet noticeable notifications come close), but rather it&apos;s the combination of all the small nice features that makes the Pebble Time smartwatch great.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:mic&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Answering via voice works but feels slow and cumbersome.  Also, due to the device size, the only way to fix an error in the voice recognition is to repeat the whole message. &lt;a href=&quot;#fnref:mic&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:resistance&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Note that no watch is water-proof.  If you submerge any watch deep enough, it will stop working.  The proper term is water resistance, in addition to a measure of how resistant it is (e.g., how deep it can be submerged, or for how long). &lt;a href=&quot;#fnref:resistance&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:jspebble&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;It is actually also possible to write simple apps in JavaScript, but they are fairly limited. &lt;a href=&quot;#fnref:jspebble&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

        </description>
        <pubDate>Mon, 31 Aug 2015 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/the-surprising-reasons-i-like-the-pebble-time-and-smartwatches-in-general/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/the-surprising-reasons-i-like-the-pebble-time-and-smartwatches-in-general/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>Installing Missing Packages the Easy Way on Linux</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/posts/2015-07-30/installing-missing-packages-the-easy-way-on-linux/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;This is a quick tip to making the installation of missing packages in certain Linux flavors easier.&lt;/p&gt;

&lt;p&gt;Many Linux distributions come with a program called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;command-not-found&lt;/code&gt; pre-installed (e.g., &lt;a href=&quot;https://apps.ubuntu.com/cat/applications/command-not-found/&quot;&gt;Ubuntu&lt;/a&gt; or &lt;a href=&quot;https://packages.debian.org/sid/command-not-found&quot;&gt;Debian&lt;/a&gt;), that helps to discover missing packages.  Say you just freshly installed Linux and type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hg status&lt;/code&gt; in a shell.  Because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hg&lt;/code&gt; is not installed yet, you instead see the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;hg status
The program &lt;span class=&quot;s1&quot;&gt;&apos;hg&apos;&lt;/span&gt; is currently not installed. You can &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;it by typing:
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;mercurial&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now this very useful, especially when the package has a different name from the command you are trying to run (like with mercurial).  But why do I have to type (or copy) that message if I want to install the package?  Turns out, there is an environment variable which when set, asks to install the package directly, like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;hg status
The program &lt;span class=&quot;s1&quot;&gt;&apos;hg&apos;&lt;/span&gt; is currently not installed. You can &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;it by typing:
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;mercurial
Do you want to &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;it? &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;N/y&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Entering &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt; will install the package.  Very convenient.  To enable this feature, add the following line to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.bashrc&lt;/code&gt; (or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.zshrc&lt;/code&gt;, or wherever your shell initialization is):&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;COMMAND_NOT_FOUND_INSTALL_PROMPT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Life just got so much better!&lt;/p&gt;

        </description>
        <pubDate>Thu, 30 Jul 2015 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/posts/2015-07-30/installing-missing-packages-the-easy-way-on-linux/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/posts/2015-07-30/installing-missing-packages-the-easy-way-on-linux/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>The Most Dangerous Code in the Web Browser</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/posts/2015-06-28/the-most-dangerous-code-in-the-web-browser/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;Did you know that the web browser extension you installed a long time ago (say, AdBlock), can probably see all your passwords, look at any website you visit using your credentials and could trivially send all that information to an arbitrary web server?  That&apos;s pretty scary, and in this blog post I will explain how security for extensions currently works.  I will also outline research towards a better extension security model for browsers that protects your sensitive information.&lt;/p&gt;

&lt;h3 id=&quot;background&quot;&gt;Background&lt;/h3&gt;

&lt;p&gt;Web applications are ubiquitous and many tasks that traditionally have been achieved using dedicated desktop applications are carried out in web browsers today.  Furthermore, these applications increasingly handle sensitive data such as banking information, passwords or medical data.  This poses security challenges to protect this data from malicious entities, and luckily the web platform and, as part of this, web browsers have evolved to achieve this.  For instance, the &lt;a href=&quot;http://en.wikipedia.org/wiki/Same-origin_policy&quot;&gt;same-origin policy&lt;/a&gt; (or &lt;abbr title=&quot;Same-origin policy&quot;&gt;SOP&lt;/abbr&gt; for short) roughly ensures that information from one website (say, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bank.com&lt;/code&gt;) cannot be accessed by a malicious site like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;evil.com&lt;/code&gt;, because they have different &lt;em&gt;origins&lt;/em&gt;&lt;sup id=&quot;fnref:origin&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:origin&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;Mechanisms like the &lt;abbr title=&quot;Same-origin policy&quot;&gt;SOP&lt;/abbr&gt; have worked relatively well in protecting user data in web browsers&lt;sup id=&quot;fnref:server_security&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:server_security&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.  However, users often want to extend web browser functionality by installing extensions, e.g., to block advertisements or to extend the functionality of certain websites.  Unfortunately, the security story for extensions is less rosy.&lt;/p&gt;

&lt;h3 id=&quot;extension-security&quot;&gt;Extension Security&lt;/h3&gt;

&lt;p&gt;Let&apos;s look at Google Chrome, the most popular browser and the one with the most sophisticated security model for extensions:  Unlike websites, extensions need access to more sensitive &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; to implement their functionality, such as access to the list of open tabs, the browsing history, or the cookies.  At the same time, extensions also need to deeply interact with the websites code, so that they can change their behavior or looks.  Since such &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; give access to rather sensitive data, Chrome uses two main mechanisms to try and ensure the information remains private.  Firstly, extensions are split into a content script and a core script, and only the core gets access to these &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; (like your browsing history), but cannot directly interact with any web pages.  In contrast, the content script can interact with web pages, and, for instance, access and change what is displayed (by accessing the so-called &lt;abbr title=&quot;Document Object Model&quot;&gt;DOM&lt;/abbr&gt;).  Message passing is then used between the content script and the extension core to try and prevent malicious websites from getting access to the sensitive browser &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt;, even in the presence of badly written or buggy extensions.  This is important because the sensitive &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; are not governed by, say, the &lt;abbr title=&quot;Same-origin policy&quot;&gt;SOP&lt;/abbr&gt;.  Secondly, extensions need to declare a list of permissions, and extensions only get access to the &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; allowed by the declared permissions.&lt;/p&gt;

&lt;figure&gt;
  &lt;img style=&quot;width: 23.529411764705884rem&quot; src=&quot;/blog/img/posts/chrome-extension-model.png&quot; alt=&quot;Chrome Extension Model&quot; title=&quot;In the Chrome security model, every extension is split into a content script that has access to the website (via it&apos;s DOM), and the core, which has access to the sensitive browser APIs.  The two parts communicate via message passing.&quot; /&gt;
  &lt;p class=&quot;figcaption figcaption-right&quot;&gt;In the Chrome security model, every extension is split into a content script that has access to the website (via it&apos;s DOM), and the core, which has access to the sensitive browser APIs.  The two parts communicate via message passing.&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;At this point, you might be able to guess what the problem is:  The sensitive &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; are protected from malicious websites, but what about malicious extensions?  The only protection of the sensitive &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; is through the permissions, which are declared by the extension.  The user can either grant all requested permissions at install time, or not install the extension.  We have looked at the top 500 extensions by number of users in the &lt;a href=&quot;https://chrome.google.com/webstore&quot;&gt;Chrome Web Store&lt;/a&gt; to get a sense of what permissions are being requested.  We found that more than 71% of extensions require permission to &quot;&lt;em&gt;read and change all your data on the websites you visit&lt;/em&gt;&quot;.  And it only gets worse if we look at the top 100 (with 82%) or top 50 of extensions, where a staggering 88% of extension require this permission.  And these extensions are widely used, too, with the most popular having more than 10 million users (how many exactly we don&apos;t know, as Google caps the reported number at 10 million), and even the extension in place 500 still has more than 70,000 users.  Clearly, users are willing to give these very broad permissions, and most extensions do require powerful permissions.&lt;/p&gt;

&lt;figure&gt;
  &lt;img style=&quot;width: 35.294117647058826rem&quot; src=&quot;/blog/img/posts/extension-permissions.png&quot; alt=&quot;A full view of what percentage of the most popular extensions require permission to &amp;lt;i&amp;gt;read and change all your data on the websites you visit&amp;lt;/i&amp;gt;.  At the left, we consider the top 500 most popular extensions (by number of users), and we restrict it to the more popular extensions as we go to the right.  For instance, all of the top 7 most popular extension show this message on installation.&quot; title=&quot;A full view of what percentage of the most popular extensions require permission to &amp;lt;i&amp;gt;read and change all your data on the websites you visit&amp;lt;/i&amp;gt;.  At the left, we consider the top 500 most popular extensions (by number of users), and we restrict it to the more popular extensions as we go to the right.  For instance, all of the top 7 most popular extension show this message on installation.&quot; /&gt;
  &lt;p class=&quot;figcaption&quot;&gt;A full view of what percentage of the most popular extensions require permission to &lt;i&gt;read and change all your data on the websites you visit&lt;/i&gt;.  At the left, we consider the top 500 most popular extensions (by number of users), and we restrict it to the more popular extensions as we go to the right.  For instance, all of the top 7 most popular extension show this message on installation.&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This means that most of these popular extensions can interact with web pages, and for instance learn the password entered by the user, or see the bank statement.  At the same time, they can send all that data to wherever they choose, clearly putting the user&apos;s privacy at risk.&lt;/p&gt;

&lt;p&gt;This is a highly unsatisfactory situation, and while Google is trying to remove malicious extensions from their online store&lt;sup id=&quot;fnref:google-removal&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:google-removal&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;, this inevitably is an arms race that cannot guarantee the safety of all users.  Thus, in the remainder of this blog post, I will outline a possible solution to the problem of extensions needing access to sensitive information to implement their functionality, yet ensuring the user&apos;s privacy is not at risk.&lt;/p&gt;

&lt;h3 id=&quot;towards-a-solution&quot;&gt;Towards a Solution&lt;/h3&gt;

&lt;p&gt;The key to a solution is the insight that extensions which deal with sensitive information are perfectly safe as long as they do not disseminate this sensitive information arbitrarily, for instance by sending it to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;evil.com&lt;/code&gt;. Let&apos;s look at an example:  The extension &lt;a href=&quot;https://chrome.google.com/webstore/detail/google-mail-checker/mihcahmgecmbnbcchbopgniflfhgnkff?hl=en&quot;&gt;Google Mail Checker&lt;/a&gt; gives the user an icon with the number of unread emails in Gmail.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/blog/img/posts/google-mail-checker.png&quot; alt=&quot;Google Mail Checker&quot; /&gt;
  
&lt;/figure&gt;

&lt;p&gt;To implement this functionality, the extension requires permission to look at any information from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;google.com&lt;/code&gt; sites.  Clearly, this is potentially dangerous to the user&apos;s privacy.  In fact, there is nothing stopping the extension from leaking all emails, or stealing the user&apos;s Google password (it probably isn&apos;t, but how do you know?)&lt;sup id=&quot;fnref:google-only&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:google-only&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;But as we observed earlier, the user&apos;s data would be safe if the extension can access the emails, but not leak them arbitrarily.  This idea is pervasive in &lt;a href=&quot;http://en.wikipedia.org/wiki/Mandatory_access_control&quot;&gt;mandatory access control&lt;/a&gt; (&lt;abbr title=&quot;Mandatory access control&quot;&gt;MAC&lt;/abbr&gt;) based confinement systems, where it is not just limited who can access information, but also how that information can be further shared.&lt;/p&gt;

&lt;p&gt;We can implement this idea by tracking where data originates from by using a &lt;em&gt;label&lt;/em&gt;.  The labels correspond to origins, and in our example the extension would be &lt;em&gt;tainted&lt;/em&gt; with the label &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mail.google.com&lt;/code&gt; after it accessed the unread count.  This label is then used to limit with whom the extension can communicate.  In particular, in the example, the extension is now limited to communicate with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mail.google.com&lt;/code&gt;, and couldn&apos;t leak the user&apos;s email to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;evil.com&lt;/code&gt;&lt;sup id=&quot;fnref:get-vs-post&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:get-vs-post&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;.  With this, even if it reads all your email or looks at your password, the extension has no way of sending the information anywhere.  However, it can still perform its main feature of displaying the unread count as an icon to the user (which can always be done, regardless of the label).  And most importantly, it is possible to do this without requiring a permission at all!  Accessing sensitive information does not require permission if the information cannot be leaked.&lt;/p&gt;

&lt;p&gt;Of course not all extensions are this simple, and so we need more sophisticated &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;APIs&lt;/abbr&gt; to allow more complex extensions to be safe.  A common problem in &lt;abbr title=&quot;Mandatory access control&quot;&gt;MAC&lt;/abbr&gt;-based confinement systems is that sometimes information that is sensitive (with regard to a particular label) is actually okay to be leaked to another origin.  For instance, extensions like the &lt;a href=&quot;https://evernote.com/webclipper/&quot;&gt;Evernote Web Clipper&lt;/a&gt; allow its users to save parts of a web page (that might contain sensitive information) to the popular note-taking app at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;evernote.com&lt;/code&gt;.
Formally, this problem is known as declassification;  conceptually the label needs to be removed of a piece of data before it can be sent to the destination origin.  Clearly extensions cannot be trusted to make these declassification decisions, as that would allow them to just arbitrary leak sensitive information again.  However, for extensions we can leverage &lt;em&gt;user intent&lt;/em&gt;:  Already in current extensions the user clicks a context menu entry to share the information with the extension.  Thus, if we provide a sharing &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;API&lt;/abbr&gt;, then extensions can register such a context menu in a trusted UI, and every time the user shares information explicitly, this corresponds to a declassification (by the user) in our system.  The user is in full control of what information gets leaked, again without having to use any permissions.&lt;/p&gt;

&lt;p&gt;Another application enabled by our approach is a secure password storage in the cloud.  This is not a new idea and services like &lt;a href=&quot;https://lastpass.com/&quot;&gt;LastPass&lt;/a&gt; allow users to only remember a single master password, and have all other passwords be stored in the cloud.  This functionality is great, but allows anybody with access to LastPass servers to read all the user&apos;s password hashes.  Unfortunately it&apos;s not enough to trust LastPass to not peak them:  If somebody manages to hack into their systems, then that person might gain access to user&apos;s password hashes&lt;sup id=&quot;fnref:lastpass-hack&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:lastpass-hack&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;6&lt;/a&gt;&lt;/sup&gt;.  So, how can we help?  If an extension reads the password on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;accounts.google.com&lt;/code&gt; page when you log into your Google account, then that password is labeled with the Google origin and couldn&apos;t be sent to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lastpass.com&lt;/code&gt;.  We wouldn&apos;t want to declassify the password, as that reveals the password to LastPass and has all the aforementioned problems.  Instead, we can take advantage of cryptography:  In our system, we allow extensions to conceptually remove a label from a piece of data (like the password) by &lt;em&gt;encrypting&lt;/em&gt; it through a browser &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;API&lt;/abbr&gt;.  With this, an extension can access the password, encrypt it and then hold the encrypted string without being tainted at all.  This allows the extension to share the encrypted password with, say, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lastpass.com&lt;/code&gt;.  While the password is encrypted, the extension isn&apos;t tainted, but it also cannot see or use the password (e.g., to log the user in with previously saved credentials).  There is a second &lt;abbr title=&quot;Application programming interface, a way for different parts of a program to communicate&quot;&gt;API&lt;/abbr&gt; call that decrypts the information and allows the extension to see the password.  However, the decryption now taints the extension with the corresponding label.  In our example, the extension would be tainted with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;accounts.google.com&lt;/code&gt; and couldn&apos;t share the password arbitrarily any longer, but can perform it&apos;s legitimate function of filling in the login form.  Essentially, this mechanism allows extensions to trade taint with encryption.&lt;/p&gt;

&lt;h3 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;These are just a few of the ideas from a &lt;a href=&quot;/publications/hotos15-extsec/&quot;&gt;research paper&lt;/a&gt; I have written with Devon Rifkin and Deian Stefan.  The paper contains more technical details and has been presented at the &lt;a href=&quot;https://www.usenix.org/conference/hotos15&quot;&gt;Workshop for Hot Topics in Operating Systems&lt;/a&gt;.  While we have not yet implemented such a secure extension system and only outlined a solution, we do believe this to be promising direction towards a practical solution.  We hope that this encourages browser vendors to rethink extension systems and raise awareness in users who may not be aware of the capabilities of even simple browser extensions.&lt;/p&gt;

&lt;p&gt;For now, the best recommendation for users is to be careful what extensions you install and only do so through trustworthy sources.&lt;/p&gt;

&lt;h3 id=&quot;press&quot;&gt;Press&lt;/h3&gt;

&lt;p&gt;This blog post has been discussed on &lt;a href=&quot;https://news.ycombinator.com/item?id=9999411&quot;&gt;Hacker News&lt;/a&gt;.  Furthermore, &lt;a href=&quot;http://www.popularmechanics.com/author/12733/eric-limer/&quot;&gt;Eric Limer&lt;/a&gt; from &lt;a href=&quot;http://www.popularmechanics.com/&quot;&gt;Popular Mechanics&lt;/a&gt; has written an article with the title &lt;a href=&quot;http://www.popularmechanics.com/technology/security/a16741/browser-extension-security/&quot;&gt;Reminder: Your Browser Extensions Have Absurd Access To Everything You Do Online&lt;/a&gt; about this work.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:origin&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Technically, an origin is defined as an URI scheme, a hostname, and a port number.  For simplicity, I only use the domain in my examples. &lt;a href=&quot;#fnref:origin&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:server_security&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Here we are only looking at client side security, i.e., protecting user data when it is in the web browser.  Security on the server is a separate problem, and a lot of reports about privacy breaches are about servers getting hacked. &lt;a href=&quot;#fnref:server_security&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:google-removal&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;For example, &lt;a href=&quot;http://arstechnica.com/security/2015/04/google-kills-200-ad-injecting-chrome-extensions-says-many-are-malware/&quot;&gt;Google recently removed almost 200 extensions&lt;/a&gt; that affected a large number of users.  The extensions range from injecting ads to outright stealing private information such as passwords. &lt;a href=&quot;#fnref:google-removal&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:google-only&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;This particular extension is actually better than most extensions, and only requires permission to all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;google.com&lt;/code&gt; sites (but more than just &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mail.google.com&lt;/code&gt;).  For this reason, it couldn&apos;t directly leak the information to, say, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;evil.com&lt;/code&gt;.  However, it could send it via the user&apos;s Gmail account, and then delete the incriminating email. &lt;a href=&quot;#fnref:google-only&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:get-vs-post&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;By default, only GET requests are possible, which only allow reading a website.  Changing information on a website or sending an email requires a POST request, which prevents the extension from sending the users information via Gmail (the attack outlined earlier). &lt;a href=&quot;#fnref:get-vs-post&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:lastpass-hack&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;In fact, &lt;a href=&quot;https://blog.lastpass.com/2015/06/lastpass-security-notice.html/&quot;&gt;LastPass did get hacked recently&lt;/a&gt;, though the saved passwords for other sites have not been compromised according to their analysis. &lt;a href=&quot;#fnref:lastpass-hack&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

        </description>
        <pubDate>Sun, 28 Jun 2015 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/posts/2015-06-28/the-most-dangerous-code-in-the-web-browser/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/posts/2015-06-28/the-most-dangerous-code-in-the-web-browser/</guid>
        
        
      </item>
      
      
    
      
      
      
      
      <item>
        <title>smartless: a better pager for small and large inputs</title>
        <description>
            &lt;p style=&quot;color: #999&quot;&gt;&lt;em&gt;Some features like footnotes work best when reading this post at &lt;a href=&quot;https://stefanheule.com/blog/posts/2015-06-07/smartless-a-better-pager-for-small-and-large-inputs/&quot;&gt;stefanheule.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
            &lt;p&gt;A &lt;a href=&quot;http://en.wikipedia.org/wiki/Terminal_pager&quot;&gt;pager&lt;/a&gt; is a computer program that makes viewing long output or long files on the terminal more pleasant.  Instead of dumping all the output at once, a pager shows the text one page at a time, allowing the user to scroll up and down, or search through the text.  For instance, viewing a large diff with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git&lt;/code&gt; is much more pleasant with a pager.  The most common pager on Unix systems is probably &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt;, and while it works great in many cases, viewing only very short output in a pager is a bit silly.  If all of the text is only a few lines long and fits on the screen, then no pager is required in the first place.&lt;/p&gt;

&lt;p&gt;However, it is often hard to know upfront whether a pager will be necessary, and so it would be more convenient to always use a pager and have the pager return immediately if the text is short, and just print it instead.&lt;/p&gt;

&lt;p&gt;The pager &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt; has a command line option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-F&lt;/code&gt; that does exactly this.  Unfortunately, it comes at a price: scrolling is no longer possible.  For this reason, I have built my own pager I call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smartless&lt;/code&gt;, that avoids exactly this problem.  For small output, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smartless&lt;/code&gt; will just print the text directly and exit.&lt;/p&gt;

&lt;p&gt;For larger output (more than 15 lines by default, but this is configurable), the pager &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt; is invoked.  Note that the first 15 lines are still printed directly, before &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt; is called.  This is a feature and not a bug, as it gives a little bit of information about the output, even after exiting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt;.  Here&apos;s a little demo:&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;/blog/img/posts/smartless.gif&quot; alt=&quot;smartless demo&quot; title=&quot;Quick demo of smartless in action.  (Unfortunately the recording software I used introduced some artifacts and non-smooth transitions.)&quot; /&gt;
  &lt;p class=&quot;figcaption&quot;&gt;Quick demo of smartless in action.  (Unfortunately the recording software I used introduced some artifacts and non-smooth transitions.)&lt;/p&gt;
&lt;/figure&gt;

&lt;p&gt;This works great for me, and I have completely replaced &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smartless&lt;/code&gt; on my system.  For instance, to change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git&lt;/code&gt; to use the new pager, run&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git config &lt;span class=&quot;nt&quot;&gt;--global&lt;/span&gt; core.pager &lt;span class=&quot;s1&quot;&gt;&apos;smartless&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Similarly, I have configured an alias so that I can keep typing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;less&lt;/code&gt;, but actually use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smartless&lt;/code&gt; instead:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;alias &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;/path/to/smartless&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;download&quot;&gt;Download&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;smartless&lt;/code&gt; is a small Bash script, and &lt;a href=&quot;https://github.com/stefanheule/smartless&quot;&gt;available on GitHub&lt;/a&gt;.  Give it a try if it sounds useful, and &lt;a href=&quot;/contact/&quot;&gt;let me know&lt;/a&gt; what you think!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;git clone https://github.com/stefanheule/smartless.git&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Finally, credit where credit is due:  When I originally searched for a solution I found &lt;a href=&quot;http://unix.stackexchange.com/questions/107315/&quot;&gt;this StackExchange post&lt;/a&gt; that my script is based on.&lt;/p&gt;

        </description>
        <pubDate>Sun, 07 Jun 2015 00:00:00 -0700</pubDate>
        <link>https://stefanheule.com/blog/posts/2015-06-07/smartless-a-better-pager-for-small-and-large-inputs/</link>
        <guid isPermaLink="true">https://stefanheule.com/blog/posts/2015-06-07/smartless-a-better-pager-for-small-and-large-inputs/</guid>
        
        
      </item>
      
      
    
  </channel>
</rss>
