TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A more robust raw OpenBSD syscall demo

74 pointsby signa112 months ago

6 comments

oguz-ismail2 months ago
Why involve C at all? This is much cleaner in assembly<p><pre><code> .global _start .data what: .string &quot;hello\n&quot; .set len, .-what - 1 .text _start: mov w0, 1 adr x1, what mov w2, len mov w8, 4 99: svc 0 dsb nsh isb mov w8, 1 98: svc 0 .section .openbsd.syscalls, &quot;&quot; .long 99b, 4 .long 98b, 1 .section .note.openbsd.ident, &quot;a&quot; .long 8, 4, 1 .string &quot;OpenBSD&quot; .long 0</code></pre>
评论 #43341391 未加载
评论 #43343618 未加载
评论 #43341780 未加载
fwsgonzo2 months ago
The inline assembly is not idiomatic. Today you should be using register asm. Here is a RISC-V example:<p><pre><code> register long a0 asm(&quot;a0&quot;) = arg0; register long syscall_id asm(&quot;a7&quot;) = n; asm volatile (&quot;ecall&quot; : &quot;+r&quot;(a0) : &quot;r&quot;(syscall_id)); return a0; </code></pre> This is an example where a0 is an in&#x2F;out integer. For memory, change long a0 to a pointer to some struct and add a &quot;m&quot; input or &quot;+m&quot; in&#x2F;out. It&#x27;s even easier in other languages like Rust and Zig.
评论 #43343450 未加载
评论 #43342615 未加载
评论 #43342765 未加载
评论 #43347139 未加载
评论 #43343581 未加载
debatem12 months ago
Seems like an interesting if maybe not practical protection to implement in eBPF for programs that never make a naked syscall.<p>Step one would be to ensure that every syscall has a wrapper. Place a uprobe at the start of that wrapper which, when hit, sets a per-thread permission bit and a per-thread-per-syscall permission bit in an eBPF map. Place a corresponding uretprobe that clears the per-thread-per-syscall bit. For each syscall place a kprobe which checks the per-thread table to make sure the thread is one which has enabled the feature, and which then checks to make sure the per-thread-per-syscall bit is set for that syscall. If not, sigkill.<p>Performance would probably suck but it seems like it would protect the syscall entrypoints enough to do some potentially interesting attack surface reduction. The question is really why you would do that there instead of by attaching to, say, the LSM hooks where you have stronger guarantees vis a vis userspace.
评论 #43343602 未加载
rollcat2 months ago
I like how Go provides the &quot;syscall&quot; package in the standard library. It&#x27;s OS&#x2F;ARCH specific, and takes every precaution to call the raw thing safely - notably syscall.ForkExec on UNIX platforms (digging thru the source made me really appreciate the scope of their work).<p>It &quot;feels&quot; very low-level in an otherwise very high-level language, but provides enough power to implement an entire userland from initrd up, libc- and asm-free (check out Gokrazy and u-root).<p>OpenBSD and Go have always been at odds here. Go really wants to produce static executables whenever possible, and do syscalls directly; OpenBSD really wants to prevent user programs from accidentally creating gadgets. I guess they&#x27;ve settled on dynamically linking ld.so?
评论 #43341764 未加载
sim7c002 months ago
maybe to make it more concise binary you can do something like nostdinc nostdlib or freestanding and add own linker file to be more explicit about how binary is build and what to &#x2F;discard&#x2F;. also max page size and other linker flags can impact. its sometimes a bit trial and error to get it to spit out a small binary with only the code u really wrote.<p>own linker file and manual linking step imo is key. (i use gcc&#x2F;ld). if u let gcc spit linker file for modern platform, u can see its full of clutter... most of it unneeded. u can also strip that one down, but i am sure u know what elf sections to put and omit, and you found all the bsd specific ones.<p>in the linker step u can also add symbols &#x2F; calculate offsets.<p>in gcc u can also in the c code use attribute section(&#x27;bla&#x27;). not sure if its handy in this case but maybe it&#x27;ll ease somewhat these things or bring it back more into C :).<p>cool example :) remebering struggle tirleesly tryin to find out how to run a raw syscall on openbsd. a lot of man pages, readelfs and headaches i was so happy to get my exit code hahah
INTPenis2 months ago
I&#x27;m sorry but I got stuck on the first sentence &quot;Ted Unangst published dude, where are your syscalls? on flak yesterday&quot; and as a long time fediverse operator I got insanely curious about &quot;flak&quot;.<p>So I ended up on the flak tag of this blog[1], but I still can&#x27;t figure out what it is. I can find no links to any source code, or any service description. Even though the blogger mentions flak being their &quot;signature service&quot;.<p>I&#x27;m guessing it&#x27;s a blogging platform, with ActivityPub support, but I can&#x27;t find any info about how it&#x27;s used.<p>1. <a href="https:&#x2F;&#x2F;flak.tedunangst.com&#x2F;t&#x2F;flak" rel="nofollow">https:&#x2F;&#x2F;flak.tedunangst.com&#x2F;t&#x2F;flak</a>
评论 #43340974 未加载
评论 #43341222 未加载
评论 #43340908 未加载