WebGPU 2.1. Security

The security requirements for WebGPU are the same as ever for the web, and are likewise non-negotiable. The general approach is strictly validating all the commands before they reach GPU, ensuring that a page can only work with its own data.

WebGPU的安全要求与web的安全要求一样,同样是不可妥协的。一般的方法是在所有命令到达GPU之前严格验证它们,确保页面只能使用自己的数据。

2.1.1. CPU-based undefined behavior

A WebGPU implementation translates the workloads issued by the user into API commands specific to the target platform. Native APIs specify the valid usage for the commands (for example, see vkCreateDescriptorSetLayout) and generally don’t guarantee any outcome if the valid usage rules are not followed. This is called “undefined behavior”, and it can be exploited by an attacker to access memory they don’t own, or force the driver to execute arbitrary code.

WebGPU实现将用户发出的工作请求转换为目标平台的特定API命令。本机API指定命令的有效用法(例如,请参见vkCreateDescriptorSetLayout),如果不遵循有效用法规则,通常不保证任何结果。这被称为“未定义行为”,攻击者可以利用它来访问他们不可访问的内存,或强制驱动程序执行任意代码。

In order to disallow insecure usage, the range of allowed WebGPU behaviors is defined for any input. An implementation has to validate all the input from the user and only reach the driver with the valid workloads. This document specifies all the error conditions and handling semantics. For example, specifying the same buffer with intersecting ranges in both “source” and “destination” of copyBufferToBuffer() results in GPUCommandEncoder generating an error, and no other operation occurring.

为了禁止不安全的使用,WebGPU为任何输入定义了允许的行为范围。一个实现必须验证来自用户的所有输入,并且只使用有效的工作负载到达驱动程序。本文档指定了所有错误条件和处理语义。例如,在copyBufferToBuffer()的“源”和“目标”中指定具有相交范围的相同缓冲区会导致GPUCommandendCoder生成错误,并且不会发生其他操作。

See § 20 Errors & Debugging for more information about error handling.

§ 20 Errors & Debugging,了解有关错误处理的更多信息。