Re: [PATCH 5/5] types: Add standard __ob_trap and __ob_wrap scalar types
From: Justin Stitt
Date: Tue Mar 31 2026 - 17:53:01 EST
Hi,
On Tue, Mar 31, 2026 at 2:05 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 31 Mar 2026 at 13:31, Kees Cook <kees@xxxxxxxxxx> wrote:
> >
> > (Isn't this just an implicit "try"?)
>
> Yes. And I think that's ok.
>
> I think try/catch is broken for a few reasons, but the fact that catch
> and try are tied together so closely is the main one. You can't "try"
> inside a scope without having the "catch" inside the same scope.
>
> So then the solution is to just move the try to the outermost layer,
> and I think that's pretty much what everybody does.
>
> But at that point, why not just move it *all* the way out, and make it
> implicit and invisible?
How do we feel about type-defined labels? We can specify sane default
handlers where we define the types:
typedef int __attribute__((overflow_behavior(trap, __handle_me)));
... and define specialized handlers later on
int func()
{
...
u8 __attribute__((overflow_behavior(trap, __BOOOOM))) product = 5;
...
product = a * b; // if store is truncated, goto __overflow
...
return product;
__BOOOOM:
pr_info("%u\n", product); // shows "5"
return -1;
}
We would then probably want a kernel shorthand to avoid long type definitions.
#define __TRAP(handler) __attribute__((overflow_behavior(trap,
handler)))
At least this way the label is always defined somewhere in-source
rather than by a magic -fhandle-my-overflow-at=__overflow
>
> Which is kind of exactly what your suggestion is all about, and that's
> why I like it so much.
>
> It *literally* fixes try/catch. It makes the only really valid usage
> model just work better.
>
> (There are other reasons I dislike try/catch too, the whole
> "exceptions across function boundaries" being another one that your
> model avoids).
>
> Linus
Justin