Linux Kernel Ksmbd Use-After-Free Remote Code Execution Vulnerability
zerodayinitiative.com
zerodayinitiative.com
https://arstechnica.com/information-technology/2022/12/criti...
> Initially, he had started trying to replace the ksmbd server, but that turned out to not be an ideal project.
if only he perservered...
WASM started to become equivalent of "just rewrite it in Rust" here...
Also "good" depends on the audience. Ability to cheaply hire a bunch of devs to whip up CRUD app is "good" quality of PHP/JS even if it might not make the language "good" from engineering perspective.
I was referring to the part explaining the 2028-2040 METAL system where "we" gained 4% execution speed because we stuffed all things into a asm.js VM in kernel that can skip syscall overhead. But it's a joke video anyway.
Linux being monolithic and all, I don't think there is a good answer. Hope Microkernels make a comeback.
https://samba.plus/blog/detail/ksmbd-a-new-in-kernel-smb-ser...
The main reason to use ksmbd is if you can't use GPLv3 Samba. Most PC SMB servers will still be using Samba instead of ksmbd for this reason. Ksmbd is mostly used on NAS boxes.
My use case is shipping minimal Linux kernels + initramfs that can be run with QEMU. I need file sharing and SMB is the most universal protocol. I can ship the entire kernel (~5MB) and QEMU (~15MB) in less space than Samba. I would love a minimal build.
That's a fine reason. Does it have to be in the kernel to be small though? From what I can see ksmpd is small because it delivers only a minimal SMB3, not because it's in-kernel. Why would a user space SMB3 be appreciably larger?
Also, the performance hopes for ksmbd don't appear valid either. By adopting io_uring and splice(2) Samba now outperforms[1] ksmbd by a wide margin. Those results are a year old and may be out of date, but still, I suspect we're getting so close to the limits of hardware that it doesn't matter.
Another argument for in-kernel is SMB Direct: SMB over RDMA. Yet here[2] we see io_uring is receiving the bits needed for that as well.
Finally, the license issue: I can't think of a reason a GPL2/Berkeley licensed SMB3 couldn't be in user space.
Where am I wrong? Is there a valid reason for this to be in kernel? I don't see one.
[1] https://samba.plus/blog/detail/ksmbd-a-new-in-kernel-smb-ser... [2] https://lwn.net/Articles/879724/
Edit: looks like the ksmbd SMB Direct work predates the io_uring RDMA capability by a few years, so at that time SMB Direct was a legitimate reason. On the other hand send(..., MSG_ZEROCOPY) predates ksmbd...
Enjoy the CVEs I guess.
If that’s the case, why did they have to put it in the Kernel? Couldn’t it have just been userland?
Is it even? It was mainlined only last year, I don't think any embedded vendor have had time to ship it in a product.
NFS has been in the kernel for ages and works roughly the same way, kernel driver with a userland component.
NFS has the advantage of having been in the kernel longer with most low hanging fruit security bugs fixed. ksmbd is brand new. Quite the expectation to have it be completely bug free.
edit: wait a minute, this was fixed with kernel 5.15.61
That's at least 20 releases ago.
Yes, new features will have problems. They remain disabled in build configs of most distros at this point. Over time, more stability will encourage more consumers to enable it too.
This is not new for the Linux community. They will deal with this one like they have with other new features in the past.
Sure, it could be, but there are shades of gray. Arguing that adding a full fat SMB server to the kernel is not the same thing as suggesting that file systems should be 100% in user space. You and I both know that the threat posed by introducing a large amount of remotely reachable code is not at all the same as that posed by a new kernel filesystem.
The last few decades of arguing about micro vs monolithic have surely convinced everyone that there is a time and a place for both. Yes, embedding the server in the kernel gives us lower latency by eliding a context switch (a few hundred cycles) but this comes at a pretty high cost that we're going to be paying for years to come.
Call me overly dramatic, but ever since the NSO group stuff went public I've been a lot more risk averse when it comes to introducing remote attack surface because we know that these bugs are being used to kill people. Making kernel compromise harder means possibly saving someone's life. Do I think someone is going to die over a ksmbd bug? Probably not. Would I want to be the one that checked in a huge remotely accessible blob of code? No, so I think carefully about what code I put where to minimize the risk.
The other point I'll make is that other kernel features scare me far more than this SMB server. Think io_uring, eBPF, or similar systems. Their attack surfaces are far larger, and yet they have become mainstream. Unfortunately, the horse has already left the barn. We need to find better ways to secure our systems. Arguing for fewer features has been tried for decades, and hasn't helped. Not here in the kernel, not in the browser, not anywhere.
I wish the world was easier to secure, but it's not.
Not only you have service where (if not firewalled) anything can connect and try the luck sending shit to it, it is often integrated with many other systems inside the kernel so it increases effort to rewrite any of that. Protocol clients in kernel have far less problems, for one you only connect to defined endpoint so attacker just to start would need to MITM you, and it is usually smaller codebase than the server
It is also usually stuff where you want to add new features relatively often and "upgrade kernel to use this new server feature" is not thing people like very much.
Providing interfaces to make userspace implementations faster have far better payoff, generic "make disk access and shoving stuff between disk and network fast" will help any file serving demon, not just SMB (point which original Samba proves, as with new improvements it is currently faster than ksmbd)
This is the worst possible take on this.
> Building an SMB server in the kernel because "well, NFS was secure eventually" overlooks the fact that NFS shouldn't be in the kernel either.
The way Linux works, NFS unfortunately has to be in the kernel to achieve reasonable performance.
It's easier to limit client attack space because to just start attacking client you'd need to MITM the client-server traffic
Anyway the way Ceph does that is replication, just like those other solutions. There may be 4 nodes with filesystems that contain that data, and Ceph is the veneer that lets you not have to worry about the implementation-detail of where it lives.
https://nvd.nist.gov/vuln/detail/CVE-2021-27363
4300 affected kernel versions has to be a record of sorts.
It is amazing how many old bugs have survived to the present day. :/
That's because there is no OpenSolaris anymore....
Monolithic UNIX clones are an anachronism we are well past the time to get rid of.
Unloading modules is generally possible, but I'm not quite following what shutting it down has to do with checking memory use?
If not then the problem is more insidious but I've found plenty of use-after-free bugs that way.
https://www.phoronix.com/news/Netflix-NUMA-FreeBSD-Optimized
https://2019.eurobsdcon.org/slides/NUMA%20Optimizations%20in...
Not only we have QNX, most Android drivers since Android 8 are userspace, macOS is incremently moving to userspace drivers killing kernel drivers for anyone else other than Apple, most newer Windows drivers since Vista are userspace, Fuschia is microkernel based and already has some production deployments,...
And guess what, they perform just fine.
https://arstechnica.com/gadgets/2022/08/googles-fuchsia-os-l...
With Google Nest speaker on the horizon,
https://9to5google.com/2022/12/07/google-nest-audio-fuchsia-...
Context switching can be as expensive as you want, or almost as cheap as you want depending on the limitations of the hardware. Back in 1992 on by todays' standards very anemic hardware you could do 200K slices per second, today likely orders of magnitude more than that.
I suspect that lots of people - not necessarily you - that have very clear opinions on micro kernels and their capabilities have never actually used them.
I would love to see this implementation succeed (Samba is too big and not portable enough for my use case), but there have definitely been challenges.
But SMB in general is complicated mess that only gets more complicated for backward compatibility sake. Comprehensive implementation almost by definition have to be complex.
Small "local users only" implementation would certainly be welcome but I don't see the benefits of keeping it in kernel.
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -2044,6 +2044,7 @@ int smb2_tree_disconnect(struct ksmbd_wo
ksmbd_close_tree_conn_fds(work);
ksmbd_tree_conn_disconnect(sess, tcon);
+ work->tcon = NULL;
return 0;
}Even in Linux 6.1 it is marked experimental.
Also: unless you have very specific requirements there are probably easier languages+tools to write proven-correct programs in.
For context Samba and NFS had historically been buggy or exploitable since the 90s.
Cool then let's put it into the kernel, another buggy software? -> right into the kernel, webserver? -> Kernel...oh wait we had that. Database? -> Kernel
It's definitely been a bit of a challenge to make ksmbd happen. I want to be able to acknowledge problems, validate the fear people have had. But also, ksmbd feels like such a textbook example of what Steve Yeggie's thesis in Notes from the Mystery Magic Bus:
> Software engineering has its own political axis, ranging from conservative to liberal.
Starting from some definitions:
> So we'll start with an operational definition of conservatism, from Jost et al.: "We regard political conservatism as an ideological belief system that is significantly (but not completely) related to motivational concerns having to do with the psychological management of uncertainty and fear."
Today we see some validation of fear. There are problems. It's certainly an inconvenience for those relying on public shares functioning securely. Thusfar it's unclear how many people have been attacked via this, or what harm has been done: the scope of damage is unknown. But the conservative view is justified, in that there have been problems, ksmbd is causing those relying on it to have to update, or risk being attacked.
Reciprocally though, I want to highlight how great this effort is. This is a novel new implementation of a complex protocol, that sits right at the hub of how systems can work together. There's a progressive, can do-ism here that is absolutely cherisable & excellent. That there are problems along the road is absolutely too something we should factor in, is a concern. It's up to everyone to take score, and to decide their alignment, what to go for & what not to. Even though today is a "bad" day for this enhancement, even though the road forward for it hasn't been without difficulty, I don't feel like it dooms the whole enterprise. Trying, to me, feels so worthwhile. The scope of impact, the actual harm of trying, seems so mild, and the doomsaying & fearmongering seems so overblown, to me.
Great the exploit cannot pown the host, it can nevertheless trigger damaging behaviours.
And of course obligatory XKCD: https://xkcd.com/1200/
I'm happy most HN users don't make anything security-important...