[PATCH v2] crypto: reduce minimum alignment of on-stack structures

Ard Biesheuvel ardb at kernel.org
Fri Jan 8 17:49:32 EST 2021


On Fri, 8 Jan 2021 at 22:16, Eric Biggers <ebiggers at kernel.org> wrote:
>
> On Fri, Jan 08, 2021 at 06:17:06PM +0100, Ard Biesheuvel wrote:
> > diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
> > index 6a733b171a5d..aa133dc3bf39 100644
> > --- a/include/crypto/skcipher.h
> > +++ b/include/crypto/skcipher.h
> > @@ -128,7 +128,7 @@ struct skcipher_alg {
> >                            MAX_SYNC_SKCIPHER_REQSIZE + \
> >                            (!(sizeof((struct crypto_sync_skcipher *)1 == \
> >                                      (typeof(tfm))1))) \
> > -                         ] CRYPTO_MINALIGN_ATTR; \
> > +                         ] __aligned(ARCH_SLAB_MINALIGN); \
> >       struct skcipher_request *name = (void *)__##name##_desc
> >
>
> Are you sure this is okay?  __alignof__(struct skcipher_request) will still be
> CRYPTO_MINALIGN_ATTR, since it contains a field with that alignment.  So
> technically isn't the full alignment still needed, as the compiler can assume
> that struct skcipher_request is CRYPTO_MINALIGN_ATTR-aligned?
>

The assumption is that ARCH_SLAB_MINALIGN should be sufficient for any
POD type, But I guess that in order to be fully correct, the actual
alignment of the struct type should be ARCH_SLAB_MINALIGN, and __ctx
should just be padded out so it appears at an offset that is a
multiple of ARCH_KMALLOC_ALIGN.



More information about the linux-arm-kernel mailing list