Re: Rust kernel policy

From: Theodore Ts'o
Date: Fri Feb 21 2025 - 13:12:38 EST


On Fri, Feb 21, 2025 at 12:48:11PM +0300, Dan Carpenter wrote:
> On Thu, Feb 20, 2025 at 04:40:02PM +0100, Martin Uecker wrote:
> > I mean "memory safe" in the sense that you can not have an OOB access
> > or use-after-free or any other UB. The idea would be to mark certain
> > code regions as safe, e.g.
> >
> > #pragma MEMORY_SAFETY STATIC
>
> Could we tie this type of thing to a scope instead? Maybe there
> would be a compiler parameter to default on/off and then functions
> and scopes could be on/off if we need more fine control.
>
> This kind of #pragma is basically banned in the kernel. It's used
> in drivers/gpu/drm but it disables the Sparse static checker.

I'm not sure what you mean by "This kind of #pragma"? There are quite
a lot of pragma's in the kernel sources today; surely it's only a
specific #pragma directive that disables sparse?

Not a global, general rule: if sparse sees a #pragma, it exits, stage left?

- Ted