r/GraphicsProgramming • u/Noxmore • Jul 18 '26
Question Sending SPIR-V over the net, is it obviously dangerous or perfectly fine?
I'm making a multiplayer game with Vulkan, and when a client joins a server, I'd like to be able to send arbitrary custom SPIR-V shaders to the client. My initial thought was "It's a shader, no syscalls or anything. Worst thing it could do is lag a bunch or maybe crash the game."
But I don't know enough about SPIR-V to know if that's correct, and doing a quick search isn't giving me any results on the subject, so I'm asking first.
Some notes:
- I'm already planning to use spirv-val to help avoid crashes, if that helps safety any.
- I cannot send over the shader source; all my shaders are pre-compiled for a bunch of reasons not relevant for this post.
Edit: To clarify, this is for modding purposes. Users will be able to create the shaders and send them from servers they host.
20
u/OkidoShigeru Jul 18 '26
What’s the use case? Is this a modding/user generated content thing? I’ve worked on games before where yeah, we exposed a limited set of shader authoring tools that users could use to jazz up custom materials, but those were just bespoke assets that called a set of pre-defined functions and some parameters. I’ve never seen a use case for distributing actual shader IR between client/server before.
41
u/HildartheDorf Jul 18 '26 edited Jul 18 '26
A malicious-but-valid spir-v shader can trivially crash, with typical results being the application dying or a driver TDR.
A more complex attacker could use a malicious shader to read and write to out of bounds memory. Robustness features would help somewhat, but I don't think they are sufficient in the face of completely unrestricted, attacker controlled spir-v.
Vulkan spec explicitly forbids "bypassing OS security", but other processes of the same user are not considered a security boundry by desktop operating systems. So in theory a hostile shader could e.g. perform an out of bounds read and obtain the contents of a users web browser. In practice implementations provide stronger guarantees than the specification here.
Ignoring all of the above, a custom shader could just output an image containing NSFW imagery or text saying "your account has been hacked, please visit malicious.example.com and send 10btc to a migerian prince"; bad idea.
6
u/rygosix Jul 18 '26
It can crash the game. Or perhaps the entire graphics driver.
Which if your on Windows means everything goes black for 5 seconds and then comes back with any other GPU accelerated application needing a restart.
Or on Linux kills Wayland and boots you back out to the login manager. Or forces the computer to reboot depending on which driver you are using.
Or the shader could try reading/writing to arbitrary parts of GPU VRAM. Could corrupt other parts of VRAM or if on an UMA system parts of the system memory. Probably result in a hard crash. Vulkan has extensions called 'Robust Buffer Access' to enforce limits on buffer access to prevent that.
In short. No it can't permanently harm anything on the system disk. But it can easily freeze or force a hard crash on the whole system.
You can test how bad a crashing shader is with this:
Add that to your fragment shader and make sure it actually uses the 'outColor' otherwise the compiler will optimize the whole thing out.
You can take that code snippet to even shadertoy right now, wire it up so outColor is what the fragment returns, then crash the whole browser and graphics driver to see what happens.
1
u/IntQuant Jul 18 '26
Maybe take a look at what WebGPU's security considerations are?
Most important part seems to be zeroing-out memory buffers before passing them to shaders, as well as making sure they don't do out-of-bound access, which is done either by enabling robustBufferAccess feature or instrumenting shader code.
2
u/tobyclh Jul 18 '26
Why can't you send the shader source? Is it to prevent reverse engineering?
2
u/_wil_ Jul 18 '26
OP you need to clarify if:
Second version has risks, first version is fine.
2
u/emmowo_dev Jul 18 '26
I would never allow arbitrary code to be sent in any form tbh, it's just wayyy too unsafe, and time and time again even regular behavior leads to ACE
1
u/wen_mars Jul 18 '26
You need to control the contents of the shaders. If users can create their own shaders and share them with others that's a big problem. The most obvious issue is that a shader can have an infinite or very long loop that freezes the game. It also lets users exploit security vulnerabilities in the gpu drivers which you have no control over.
If you control the contents of the shaders then sending them over the net is no problem at all, just make sure the connection is encrypted and/or the shaders are checksummed with a checksum that is sent over an encrypted connection.
-4
u/Holance Jul 18 '26
Do proper encryption, then should be fine.
0
u/[deleted] Jul 18 '26
[deleted] — view deleted comment