<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Karthik's Blog</title><link>http://kvcache.cc/</link><description>Recent content on Karthik's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 19 Jan 2024 00:00:00 +0000</lastBuildDate><atom:link href="http://kvcache.cc/index.xml" rel="self" type="application/rss+xml"/><item><title>About Me</title><link>http://kvcache.cc/about/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/about/</guid><description>&lt;p>Hello, I am Karthik, a Computer Science PhD student at Stony Brook University. My current research is in Kernel Security, Static Analysis, Fuzzing, LLVM, ARM TrustZone.&lt;/p>
&lt;p>Checkout &lt;a href="http://kvcache.cc/posts/dev-setup/">my development setup&lt;/a>&lt;/p>
&lt;h2 id="handles">Handles&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://github.com/karthikbhata97">GitHub&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.linkedin.com/in/karthikbhata/">LinkedIn&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Early Detection of Configuration Errors to Reduce Failure Damage</title><link>http://kvcache.cc/posts/config-errors/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/posts/config-errors/</guid><description>&lt;blockquote>
&lt;p>Paper: &lt;a href="https://www.usenix.org/system/files/conference/osdi16/osdi16-xu.pdf">Early Detection of Configuration Errors to Reduce Failure Damage&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;ul>
&lt;li>Defines &lt;code>Latent Configuration (LC) Errors&lt;/code> which are caused due to insufficient validations on the configuration, later until the configuration is actually used
&lt;ul>
&lt;li>There might be a large time between loading this configuration, generally in the initialization phase, to actually using it (thus latent).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>When such configurations are related to reachability, availability or serviceability, LC errors can lead to downtime.&lt;/li>
&lt;li>Two main issues with such configs
&lt;ul>
&lt;li>The values are not checked at all. eg: check if file exists&lt;/li>
&lt;li>The values are not checked according to the usage. eg: value is used in open(config_value, WRITE)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Paper implements a checker based on the static analysis and instrumentation&lt;/li>
&lt;li>Static analysis:
&lt;ul>
&lt;li>Taint analysis to go from the configuration to the actual usage along the data flow path. Control flow is ignored in most cases to avoid over tainting&lt;/li>
&lt;li>Along with these instruction, the dependent values are also extracted. Eg: open(config_value, permission) &amp;lt;- here permission is dependent value&lt;/li>
&lt;li>Any value that cannot be determined are skipped. Eg: a dependent value read from network&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Instrumentation:
&lt;ul>
&lt;li>Code is generated to perform same check as that in the actual usage, but in a &amp;ldquo;sandboxed&amp;rdquo; manner&lt;/li>
&lt;li>Here any side effect on the program is avoided. Eg: a local copy of global value is used instead of the actual global value.&lt;/li>
&lt;li>Utilities are written to check the actions performed by some library and system calls.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>This generated code is run right after the initialization phase of the program
&lt;ul>
&lt;li>Developer need to annotate two things
&lt;ul>
&lt;li>The interface of how configuration values are fetched&lt;/li>
&lt;li>The place where program moves from initialization state to execution&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>TOCTOU issues are avoided by adding support to run these checkers regularly in a thread&lt;/li>
&lt;/ul></description></item><item><title>Efficient Scalable Thread-Safety-Violation Detection</title><link>http://kvcache.cc/posts/tsvd/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/posts/tsvd/</guid><description>&lt;blockquote>
&lt;p>Paper: &lt;a href="https://dl.acm.org/doi/pdf/10.1145/3341301.3359638">Efficient Scalable Thread-Safety-Violation Detection&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;ul>
&lt;li>Existing solutions
&lt;ul>
&lt;li>Static or dynamic analysis to identify the potential buggy locations to inject delays.
&lt;ul>
&lt;li>Injects small number of delays but large analysis time&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Inject probabilistic random delays
&lt;ul>
&lt;li>Inject large number of delays but small analysis time&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>TSVD tries to find the middle ground&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>TSVD employs two techniques to select the points to inject delays
&lt;ul>
&lt;li>Near miss tracking&lt;/li>
&lt;li>Happens before relationship identification&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Near miss tracking
&lt;ul>
&lt;li>Identify two operations on a thread-unsafe object, one of which is write and happens close to each other on different threads&lt;/li>
&lt;li>If the time difference falls within the threshold, mark it as dangerous pair&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Happens Before relationship identification
&lt;ul>
&lt;li>If adding a delay at location 1 delays the execution of the location 2.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Delay is injected on all such pairs
&lt;ul>
&lt;li>Delay is decayed if a pair does not trigger error&lt;/li>
&lt;li>Once the probability of delay drops to 0, the pair is removed from dangerous pair list&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Built to support .NET projects
&lt;ul>
&lt;li>Instrumentation and Runtime library&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Evaluation
&lt;ul>
&lt;li>Why some bugs were missed?
&lt;ul>
&lt;li>Two operations are close to each other only on some rare executions&lt;/li>
&lt;li>False positive happens before prediction&lt;/li>
&lt;li>Delay injection was not sufficient to capture the bugs&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title>kAFL: Hardware-Assisted Feedback Fuzzing for OS Kernels</title><link>http://kvcache.cc/posts/kafl/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/posts/kafl/</guid><description>&lt;blockquote>
&lt;p>Paper: &lt;a href="https://nyx-fuzz.com/papers/kafl.pdf">kAFL&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;ul>
&lt;li>Feedback fuzzing of closed source kernel mode components&lt;/li>
&lt;li>Feedback using hardware capabilities
&lt;ul>
&lt;li>Intel PT
&lt;ul>
&lt;li>Q: What does it give?&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Challenges with kernel fuzzing
&lt;ul>
&lt;li>Lots of states&lt;/li>
&lt;li>Interrupts and threads&lt;/li>
&lt;li>No straightforward way to &amp;ldquo;invoke&amp;rdquo; the kernel&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Technical details
&lt;ul>
&lt;li>x86-64: Kernel and userspace is split into halves
&lt;ul>
&lt;li>Total virtual address space: 2^48
&lt;ul>
&lt;li>Why?&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Each get 2^47&lt;/li>
&lt;li>Switching from user to kernel on syscalls do not switch page table&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Intel Processor Trace
&lt;ul>
&lt;li>Three types
&lt;ul>
&lt;li>Taken-Not-Taken: For conditional jumps, tell if a branch is taken or not&lt;/li>
&lt;li>Target-IP: Indirect jumps, target IP&lt;/li>
&lt;li>Flow Update Packets: Interrupts and async events.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Filters can be added to these
&lt;ul>
&lt;li>IP range&lt;/li>
&lt;li>Privilege level / ring&lt;/li>
&lt;li>CR3 filter: Only when the cr3 value matches. Helps in filtering per process&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>System Design
&lt;ul>
&lt;li>Components
&lt;ul>
&lt;li>Host user space process: kAFL&lt;/li>
&lt;li>QEMU-PT + KVM-PT for getting the processor trace from guest&lt;/li>
&lt;li>Usermode agent in the target OS&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Setup:
&lt;ul>
&lt;li>Agent performs a hypercall to provide kernel panic handler&lt;/li>
&lt;li>Host patches this to get the feedback on crash
&lt;ul>
&lt;li>Instead of waiting for hte timeout&lt;/li>
&lt;li>Then CR3 is exchanged from agent to host
&lt;ul>
&lt;li>This is used to set the filter&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Then a shared memory address is exchanged where the agent expects the input for fuzzing&lt;/li>
&lt;li>Fuzzing loop starts&lt;/li>
&lt;li>While fuzzing is being performed, the QEMU-PT decodes the trace&lt;/li>
&lt;li>When the agent is done, it sends a hypercall (hc_finished).
&lt;ul>
&lt;li>On this VM-Exit, it stops tracing&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Fuzzing logic
&lt;ul>
&lt;li>This is the core and does similar to AFL&lt;/li>
&lt;li>Also runs fuzzing in parallel
&lt;ul>
&lt;li>Most fuzzing is not CPU bound, so this helps&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>User mode agent
&lt;ul>
&lt;li>Broken into loader and agent&lt;/li>
&lt;li>Agent lets you run arbitrary program, thus making it easier&lt;/li>
&lt;li>Also loader checks if the program crashed and so it can restart&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>KVM-PT
&lt;ul>
&lt;li>This helps in tracing virtual cpu instead of logical&lt;/li>
&lt;li>By enabling on vm-entry and disabling on vm-exit&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>QEMU-PT
&lt;ul>
&lt;li>QEMU-PT also filters the stream of executed addresses—based on previous knowledge of non-deterministic basic blocks—to prevent false-positive fuzzing results, and makes those available to the fuzzing logic as AFL-compatible bitmaps&lt;/li>
&lt;li>???&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Also cache the disassembly results to speed up populating the bitmap&lt;/li>
&lt;li>Stateful and non deterministic
&lt;ul>
&lt;li>Interrupts generate non-deterministic exections&lt;/li>
&lt;li>So the fuzzer runs the program multiple times and identifies such basic blocks&lt;/li>
&lt;li>Adds it to blacklist&lt;/li>
&lt;li>This is ignored when updating the coverage map&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Hypercalls
&lt;ul>
&lt;li>Accessible from ring3&lt;/li>
&lt;li>So add custom hypercalls that can help in fuzzing
&lt;ul>
&lt;li>Eg: crash, ask for input&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>KVM-PT
&lt;ul>
&lt;li>vCPU specific traces
&lt;ul>
&lt;li>MSR autoload feature lets you load MSRs on exit or entry&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Continuous tracing
&lt;ul>
&lt;li>Uses ToPA
&lt;ul>
&lt;li>Table of physical address&lt;/li>
&lt;li>Each address is associated with behavior on overflow
&lt;ul>
&lt;li>First -&amp;gt; interrupt&lt;/li>
&lt;li>Second -&amp;gt; Stop tracing
&lt;ul>
&lt;li>But keep it large enough for this to never happen&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>On overflow it triggers and results in vm switch&lt;/li>
&lt;li>Buffer is cleared and switched back to the VM&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>QEMU-PT
&lt;ul>
&lt;li>Userspace application to interact with KVM-PT&lt;/li>
&lt;li>When to start stop&lt;/li>
&lt;li>Also does the decoding the trace to generate a AFL map&lt;/li>
&lt;li>Our Intel PT software decoder acts like a just-in-time decoder, which means that code sections are only considered if they are executed according to the decoded trace data
&lt;ul>
&lt;li>???&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Discussion
&lt;ul>
&lt;li>OS specific code
&lt;ul>
&lt;li>Not a necessity but improves fuzzing (cr3 value, custom process to test kernel)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Kernel JIT
&lt;ul>
&lt;li>Out of scope&lt;/li>
&lt;li>But very interesting&lt;/li>
&lt;li>Intel PT does not give all the instruction pointers and need the executable to decode
&lt;ul>
&lt;li>Becomes tricky&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title>Rx: Treating Bugs As Allergies— A Safe Method to Survive Software Failures</title><link>http://kvcache.cc/posts/rx/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/posts/rx/</guid><description>&lt;blockquote>
&lt;p>Paper: &lt;a href="https://dl.acm.org/doi/pdf/10.1145/1095810.1095833">Rx: Treating Bugs As Allergies— A Safe Method to Survive Software Failures&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;ul>
&lt;li>Software failure recovery to make the softwares more available&lt;/li>
&lt;li>Makes use of Checkpointing and Rollback to revert to an older state&lt;/li>
&lt;li>Then makes some &lt;em>environmental changes&lt;/em> and continues the execution of the application.
&lt;ul>
&lt;li>If none of the changes work, it goes back one more checkpoint and retries&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Components
&lt;ul>
&lt;li>Proxy: Separates client and server interactions and helps in the saving and replay of requests upon re-execution.&lt;/li>
&lt;li>Sensors: Identifies when there is an error in the application using exceptions, interrupts etc.&lt;/li>
&lt;li>Checkpointing and Rollback
&lt;ul>
&lt;li>Based on: &lt;a href="https://www.usenix.org/legacy/event/usenix04/tech/general/full_papers/srinivasan/srinivasan.pdf">Flashback&lt;/a>&lt;/li>
&lt;li>Deletes oldest checkpoint based on stratergies.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Environmental wrappers: For modifying environment during re-execution
&lt;ul>
&lt;li>Memory allocation wrappers: eg: zero fill, add padding&lt;/li>
&lt;li>Scheduling wrapper to change the unit of time for scheduling&lt;/li>
&lt;li>User request dropping&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Control unit: Coordinates with all the components
&lt;ul>
&lt;li>Also provides useful information for the programmer to diagnose and fix errors.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Tested on Squid, Apache, CVS, MySQL&lt;/li>
&lt;/ul></description></item><item><title>My development setup</title><link>http://kvcache.cc/posts/dev-setup/</link><pubDate>Fri, 19 Jan 2024 00:00:00 +0000</pubDate><guid>http://kvcache.cc/posts/dev-setup/</guid><description>&lt;h2 id="windows">Windows&lt;/h2>
&lt;ul>
&lt;li>Lenovo Legion Y540
&lt;ul>
&lt;li>i7 processor with 8 cores&lt;/li>
&lt;li>24 GB RAM&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Windows 11 Pro&lt;/li>
&lt;li>WSL with Ubuntu 20&lt;/li>
&lt;li>Ubuntu 22 VM running on Hyper-V
&lt;ul>
&lt;li>Mostly accessed using X-Forwarding to WSL&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h2 id="macbook">MacBook&lt;/h2>
&lt;ul>
&lt;li>M3 Air with 16 GB + 512 GB&lt;/li>
&lt;li>This is a new machine&lt;/li>
&lt;/ul>
&lt;h2 id="tools">Tools&lt;/h2>
&lt;ul>
&lt;li>tmux&lt;/li>
&lt;li>VS Code
&lt;ul>
&lt;li>With VIM extension&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>zsh with OH MY ZSH&lt;/li>
&lt;li>Terminal
&lt;ul>
&lt;li>Windows Terminal on Windows&lt;/li>
&lt;li>Default terminal app on Mac&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>tmux&lt;/li>
&lt;/ul>
&lt;h2 id="other-applications">Other applications&lt;/h2>
&lt;ul>
&lt;li>Notability for reading papers and taking notes on iPad&lt;/li>
&lt;li>Obsidian for note taking on laptop
&lt;ul>
&lt;li>Vault on iCloud to sync across devices&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Slack and Discord for messaging&lt;/li>
&lt;li>Microsoft Edge as a browser
&lt;ul>
&lt;li>Google Scholar PDF reader extension for reading papers. Provides good navigation support for links.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>1Password for password management&lt;/li>
&lt;/ul></description></item></channel></rss>