Re: [PATCH] crypto: af_alg - Fix incorrect boolean values in af_alg_ctx

From: Eric Biggers
Date: Wed Sep 24 2025 - 16:14:01 EST


On Wed, Sep 24, 2025 at 12:40:29PM -0700, Linus Torvalds wrote:
> On Wed, 24 Sept 2025 at 12:27, Eric Biggers <ebiggers@xxxxxxxxxx> wrote:
> >
> > - u32 more:1,
> > - merge:1,
> > - enc:1,
> > - write:1,
> > - init:1;
> > + bool more;
> > + bool merge;
> > + bool enc;
> > + bool write;
> > + bool init;
>
> This actually packs horribly, since a 'bool' will take up a byte for
> each, so now those five bits take up 8 bytes of storage (because the
> five bytes will then cause the next field to have to be aligned too).
>
> You could just keep the bitfield format, but change the 'u32' to
> 'bool' and get the best of both worlds, ie just do something like
>
> - u32 more:1,
> + bool more:1,
>
> and now you get the bit packing _and_ the automatic bool behavior.

Sure, I'll send out v2 with your suggestion.

I do think the idea of trying to re-pack the structure as part of a bug
fix is a bit misguided, though. It's what caused this additional bug in
the first place, and it's not like it actually matters here. (AF_ALG is
rarely used, and when it is, the sockets tend not to be kept open for
very long. And the entire concept of AF_ALG is a mistake anyway.)

- Eric