Modifying the Linux Kernel – New Syscalls
codingkaiser.blog
codingkaiser.blog
So TL;DR only implement custom syscalls if you intend to maintain for all of its consequences in the future.
Here's the tweet on Synology - https://twitter.com/RichFelker/status/1357733309737021444
It's misleading, I'll give you that, but let's be pedantic (lawyers are)!
They can probably provide the missing bits in dead tree letter format upon written formal request received at their post address.
It does look like Synology are not abiding by the GPL here, but a minor nitpick: GPL v2 has no such requirement to distribute the source with the binaries. But if you don't, you do have to tell people they can get it and provide it in "machine-readable" format on request.
See https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html section 3b
What you're describing would likely not pass as being a reasonable interpretation of the license.
Though it probably is a violation, because they probably don't do that.
One suggestion, though: Choose higher syscall numbers. The syscall numbers that this guide uses (334) is already taken in a recent kernel update. Syscalls are added to almost every kernel version, so if you choose, say, syscall #400, in a decade or so you'll have to make a choice between your syscall and the new "official" one.
Sure but is that not because the tweet concerns a NAS and the ioctls would relate to an actual device(the storage devices)?
Would 'device local ioctls' work in the blog post scenario where it's just a general purpose process attribute?:
> ..we will assign every process a weight
You could also register a name under /proc. There is really no reason to have custom system calls.
Given the name IO..ctl, is this unintended or unavoidable behaviour?
This is apparently how audio works on Linux. The kernel abstracts over sound devices, and provides a sort of "virtual device" at /proc/asound (https://www.kernel.org/doc/html/latest/sound/designs/procfil...)
Great writeup, thats going straight to bookmarks.
EDIT: it is true however that someone has shown me the steps, I would have wasted a lot of time without their guidance.
But I also had almost zero help when I first took on Linux, except manpages.
It's difficult for me to judge the usefulness of this guide because I'm familiar with those steps, but I'm wondering if it might have been better to define a more narrow scope for this tutorial with certain prerequisites, and going into detail about the ramifications of adding a new syscall? Especially since I feel the guide barely mentions a few interesting details:
1. Only arch/x86/entry/syscalls/syscall_64.tbl is modified in this tutorial, glossing over the fact that that file only affects x86_64 syscalls (disclaimer: I'm 90% sure on this one, but don't quote me on this). Of course I wouldn't expect the tutorial to explain how to modify all the architecture-specific files, but I'd say this fact is worth noting.
2. The user-space story: The post doesn't mention how to actually use this syscall - even though that's one of the critical parts of a syscall. Essentially, if you call open() in a C program, you're not actually issuing any syscall directly. Rather the C library (e.g. glibc) implements an open() function that internally performs the syscall. This is primarily because many syscalls don't map 1:1 to C library functions, in addition to some differences between platforms and architectures. So if you'd want to use the syscall you'd have to implement a syscall wrapper yourself or use the low-level syscall(2) [1] function that allows you to access system calls not provided by glibc.
There is also some political drama attached to this, essentially the glibc maintainers don't want to implement/provide functions for certain Linux syscalls because of certain reasons (IIRC it's mostly about portability concerns, but I think there are some syscalls that the glibc maintainers just don't like for whatever reason).
3. The "What if you really wanted to add a syscall to Linux?" story, which boils down to: The Linux maintainers don't want to add any new syscalls except in very few cases (because syscalls generally can't be changed once they're introduced). Instead, you're supposed to use more flexible kernel interfaces, such as sysfs or debugfs (or previously, ioctl and procfs, but they're frowned upon nowadays and only used in certain areas). See the Linux documentation on adding syscalls [2].
[1] https://man7.org/linux/man-pages/man2/syscall.2.html
[2] https://www.kernel.org/doc/html/v5.14/process/adding-syscall...
If I'm reading the kernel source[3] correctly, the syscall interface itself accepts a 32-bit unsigned integer for the call number, but only the lowest 16 bits can be used because the upper 16 bits are used to represent the version. That would still mean that something like 80% of the effective ID space is unused at present.
[1] http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x... [2] http://asm.sourceforge.net/syscall.html [3] https://github.com/torvalds/linux/blob/master/ipc/syscall.c
lol. of course.
Suggestion numero two. A dedicated syscall for additional syscalls that has a dedicated parameter for a GUID. We can add a third level in 2050 or so.