x86/crypto: Fix function prototypes
Subsystems (2)
cover x86/crypto: Fix function prototypes
It is possible to indirectly invoke functions with prototypes that do not match those of the respectively used function pointers by using void types. This feature is frequently used as a way of relaxing function invocation, making it possible that different data structures are passed to different functions through the same pointer.
Despite the benefits, this can lead to a situation where functions with a given prototype are invoked by pointers with a different prototype, what is undesirable as it may prevent the use of heuristics such as prototype matching-based Control-Flow Integrity, which can be used to prevent ROP-based attacks.
One way of fixing this situation is through converting the function prototypes to the one used in the pointer declaration, what means converting function arguments from a given '<type> *' to a 'void *', and later casting its uses accordingly throughout the function scope.
Given the above, the current efforts to improve the Linux security, and the upcoming kernel support to compilers with CFI features, fix prototypes in x86/crypto algorithms: camellia, cast6, serpent, and twofish.
This patch does not introduce semantic changes to the cryptographic algorithms, yet, if someone finds relevant, the affected algorithms were tested with the help of tcrypt.ko without any visible harm.
Joao Moreira (4):
x86/crypto: camellia: Fix function prototypes
x86/crypto: cast6: Fix function prototypes
x86/crypto: serpent: Fix function prototypes
x86/crypto: twofish: Fix function prototypes
arch/x86/crypto/camellia_aesni_avx2_glue.c | 25 ++++++++--------- arch/x86/crypto/camellia_aesni_avx_glue.c | 21 +++++++-------- arch/x86/crypto/camellia_glue.c | 6 ++--- arch/x86/crypto/cast6_avx_glue.c | 22 ++++++--------- arch/x86/crypto/serpent_avx2_glue.c | 14 +++++----- arch/x86/crypto/serpent_avx_glue.c | 19 ++++++------- arch/x86/crypto/twofish_avx_glue.c | 30 +++++++++------------ arch/x86/crypto/twofish_glue.c | 7 +++-- arch/x86/crypto/twofish_glue_3way.c | 10 +++---- arch/x86/include/asm/crypto/camellia.h | 43 +++++++++++++----------------- arch/x86/include/asm/crypto/serpent-avx.h | 25 ++++++++--------- arch/x86/include/asm/crypto/serpent-sse2.h | 30 +++++++++------------ arch/x86/include/asm/crypto/twofish.h | 9 +++---- 13 files changed, 108 insertions(+), 153 deletions(-)
Signature · 1 line
2.12.0
PATCH 1/4 x86/crypto: camellia: Fix function prototypes
Convert the use of 'struct camellia_ctx *' to 'void *' in prototypes of functions which are referenced through 'struct common_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.
Whenever needed, cast 'void *' to 'struct camellia_ctx *'.
--- arch/x86/crypto/camellia_aesni_avx2_glue.c | 25 ++++++++--------- arch/x86/crypto/camellia_aesni_avx_glue.c | 21 +++++++-------- arch/x86/crypto/camellia_glue.c | 6 ++--- arch/x86/include/asm/crypto/camellia.h | 43 +++++++++++++----------------- 4 files changed, 40 insertions(+), 55 deletions(-)
arch/x86/crypto/camellia_aesni_avx2_glue.c +11 -14
@@ -27,20 +27,17 @@#define CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS 32/* 32-way AVX2/AES-NI parallel cipher functions */ -asmlinkage void camellia_ecb_enc_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void camellia_ecb_dec_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); - -asmlinkage void camellia_cbc_dec_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void camellia_ctr_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); - -asmlinkage void camellia_xts_enc_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); -asmlinkage void camellia_xts_dec_32way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void camellia_ecb_enc_32way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void camellia_ecb_dec_32way(void *ctx, u8 *dst, const u8 *src); + +asmlinkage void camellia_cbc_dec_32way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void camellia_ctr_32way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); + +asmlinkage void camellia_xts_enc_32way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); +asmlinkage void camellia_xts_dec_32way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);static const struct common_glue_ctx camellia_enc = { .num_funcs =4 ,
arch/x86/crypto/camellia_aesni_avx_glue.c +9 -12
@@ -26,28 +26,25 @@#define CAMELLIA_AESNI_PARALLEL_BLOCKS 16/* 16-way parallel cipher functions (avx/aes-ni) */ -asmlinkage void camellia_ecb_enc_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void camellia_ecb_enc_16way(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (camellia_ecb_enc_16way); -asmlinkage void camellia_ecb_dec_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void camellia_ecb_dec_16way(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (camellia_ecb_dec_16way); -asmlinkage void camellia_cbc_dec_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void camellia_cbc_dec_16way(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (camellia_cbc_dec_16way); -asmlinkage void camellia_ctr_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void camellia_ctr_16way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);EXPORT_SYMBOL_GPL (camellia_ctr_16way); -asmlinkage void camellia_xts_enc_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void camellia_xts_enc_16way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);EXPORT_SYMBOL_GPL (camellia_xts_enc_16way); -asmlinkage void camellia_xts_dec_16way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void camellia_xts_dec_16way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);EXPORT_SYMBOL_GPL (camellia_xts_dec_16way);void camellia_xts_enc (void *ctx,u128 *dst,const u128 *src,le128 *iv)
arch/x86/crypto/camellia_glue.c +2 -4
@@ -39,16 +39,14 @@ asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst,const u8 *src,bool xor);EXPORT_SYMBOL_GPL (__camellia_enc_blk); -asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void camellia_dec_blk(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (camellia_dec_blk);/* 2-way parallel cipher functions */ asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst,const u8 *src,bool xor);EXPORT_SYMBOL_GPL (__camellia_enc_blk_2way); -asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void camellia_dec_blk_2way(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (camellia_dec_blk_2way);static void camellia_encrypt (struct crypto_tfm *tfm,u8 *dst,const u8 *src)
arch/x86/include/asm/crypto/camellia.h +18 -25
63 lines not on this page · raw message
Signature · 1 line
2.12.0
Re: [PATCH 1/4] x86/crypto: camellia: Fix function prototypes
arch/x86/include/asm/crypto/camellia.h extern int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, · line 66
Quoted 12 lines · Joao Moreira
Convert the use of 'struct
camellia_ctx*' to 'void *' in prototypes of functions which are referenced through 'structcommon_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.Whenever needed, cast 'void *' to 'struct
camellia_ctx*'.arch/x86/include/asm/crypto/camellia.h +2
-1+static inline void camellia_enc_blk (void *ctx,u8 *dst,const u8 *src) { -__camellia_enc_blk (ctx, dst, src, false); +__camellia_enc_blk ((struct camellia_ctx *) ctx, dst, src, false); }
I don't see how this is an improvement: instead of having a proper type there's now an opaque type and an ugly (and dangerous) type cast.
What does "compatible with CFI requirements" mean?
Thanks,
Ingo
Re: [PATCH 1/4] x86/crypto: camellia: Fix function prototypes
Quoted 11 lines
arch/x86/include/asm/crypto/camellia.h extern int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, · line 66
Quoted 6 lines
arch/x86/include/asm/crypto/camellia.h +2
-1+static inline void camellia_enc_blk (void *ctx,u8 *dst,const u8 *src) { -__camellia_enc_blk (ctx, dst, src, false); +__camellia_enc_blk ((struct camellia_ctx *) ctx, dst, src, false); }I don't see how this is an improvement: instead of having a proper type there's now an opaque type and an ugly (and dangerous) type cast.
What does "compatible with CFI requirements" mean?
For "compatible with CFI requirements", I meant: given a set of functions that are invoked through a given set of pointers, all functions and pointers in these sets have the same prototype. I added a note about this CFI heuristic in the cover letter, but I guess I should have been clearer there and added something more substantial to the commit message.
Regarding the changes, this was the most straight-forward way I found to make the sources compliant with the above, not requiring deeper semantic changes to the underneath invoking code. On the other hand, I agree that there is a collateral damage and that an ideal fix would be the other way around -- removing the opaque type from the pointer instead of adding it to the functions.
I'll try to think of another way and send if I come to something.
Tks,
João.
Re: [PATCH 1/4] x86/crypto: camellia: Fix function prototypes
In reply to Ingo MolnarQuoted 10 lines · Ingo Molnar
Quoted 6 lines · Joao Moreira
Convert the use of 'struct
camellia_ctx*' to 'void *' in prototypes of functions which are referenced through 'structcommon_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.Whenever needed, cast 'void *' to 'struct
camellia_ctx*'.
Quoted 8 lines
arch/x86/include/asm/crypto/camellia.h extern int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, · line 66
Quoted 5 lines
arch/x86/include/asm/crypto/camellia.h +2
-1+static inline void camellia_enc_blk (void *ctx,u8 *dst,const u8 *src) { -__camellia_enc_blk (ctx, dst, src, false); +__camellia_enc_blk ((struct camellia_ctx *) ctx, dst, src, false); }I don't see how this is an improvement: instead of having a proper type there's now an opaque type and an ugly (and dangerous) type cast.
I agree with your instinct, as the existing best-practice in the kernel is to always use correct types and avoid casts to let the compiler check things, avoid nasty surprises, etc, but for callbacks with context pointers, we're already just hiding the casts in various places. For example, even without this patch:
typedef void (*common_glue_func_t)(void *ctx, u8 *dst, const u8 *src);
#define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn))
static const struct common_glue_ctx camellia_enc = {
...
.funcs = { {
...
.num_blocks = 1,
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) }
} }
};While it is nicely wrapped up in macros, this is actually casting away the _entire_ function prototype, not just the first argument. The "camellia_enc_blk" function could point to anything (even "void (*func)(void)") and the compiler wouldn't complain. And this was done just to mask the ctx argument.
Quoted 1 line
What does "compatible with CFI requirements" mean?
As Joao mentioned, he wrote this up pretty well in his 0/n patch:
https://lkml.kernel.org/r/[email protected]
To further clarify, fine-grained function-prototype-checking CFI makes sure that indirect function call sites only call functions with a matching expected prototype (to protect against having function pointers rewritten during an attack, etc). In this case, callers of .fn_u.ecb() expect the target function to have the prototype "void (*func)(void *ctx, u8 *dst, const u8 *src)" (as defined by struct common_glue_ctx), however, camellia_enc_blk() is "void (*func)(struct camellia_ctx *ctx, u8 *dst, const u8 *src)" and will trip the CFI check.
If we rearrange our macro magic to defining the callbacks rather than defining the function pointers, I think we'll gain several things:
- we will cast only the ctx argument instead of the entire function prototype
- we'll retain (and improve) source-code robustness against generally miscasting
- CFI will be happy
So, instead of the original series, how about something like this:
Switch function pointers to not use the function cast, and define a new GLUE_FUNC macro that kinda looks like the tricks used for syscalls:
static const struct common_glue_ctx camellia_enc = {
...
.funcs = { {
...
.num_blocks = 1,
.fn_u = { .ecb = camellia_enc_blk }
} }
};#define GLUE_FUNC(func, context) \
static inline void func(void *ctx, u8 *dst, const u8 *src) \
{ __##func((context)ctx, dst, src); } \
__##func(context ctx, u8 *dst, const u8 *src)
GLUE_FUNC(camellia_enc_blk, struct camellia_ctx *) {
...original function...
}
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Re: [PATCH 1/4] x86/crypto: camellia: Fix function prototypes
Quoted 20 lines · Kees Cook
So, instead of the original series, how about something like this:
Switch function pointers to not use the function cast, and define a new
GLUE_FUNCmacro that kinda looks like the tricks used for syscalls:static const struct
common_glue_ctxcamellia_enc= {
....funcs = { { ... .num_blocks = 1, .fn_u = { .ecb = camellia_enc_blk } } } };#define
GLUE_FUNC(func, context)\
static inline voidfunc(void *ctx, u8 *dst, const u8 *src)\
{ __##func((context)ctx, dst, src); } \
__##func(context ctx, u8 *dst, const u8 *src)
Quoted 4 lines
GLUE_FUNC(camellia_enc_blk, struct camellia_ctx *){
...original function...
}
I was about to suggest this before I read to the end of the mail. Yes, that is much more palatable.
Thanks,
tglx
PATCH 2/4 x86/crypto: cast6: Fix function prototypes
In reply to Joao MoreiraConvert the use of 'struct cast6_ctx *' to 'void *' in prototypes of functions which are referenced through 'struct common_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.
--- arch/x86/crypto/cast6_avx_glue.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
arch/x86/crypto/cast6_avx_glue.c +10 -14
@@ -41,20 +41,16 @@#define CAST6_PARALLEL_BLOCKS 8 -asmlinkage void cast6_ecb_enc_8way(struct cast6_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void cast6_ecb_dec_8way(struct cast6_ctx *ctx, u8 *dst, -const u8 *src); - -asmlinkage void cast6_cbc_dec_8way(struct cast6_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void cast6_ctr_8way(struct cast6_ctx *ctx, u8 *dst, const u8 *src, -le128 *iv); - -asmlinkage void cast6_xts_enc_8way(struct cast6_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); -asmlinkage void cast6_xts_dec_8way(struct cast6_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void cast6_ecb_enc_8way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void cast6_ecb_dec_8way(void *ctx, u8 *dst, const u8 *src); + +asmlinkage void cast6_cbc_dec_8way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void cast6_ctr_8way(void *ctx, u8 *dst, const u8 *src, le128 *iv); + +asmlinkage void cast6_xts_enc_8way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); +asmlinkage void cast6_xts_dec_8way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);static void cast6_xts_enc (void *ctx,u128 *dst,const u128 *src,le128 *iv) {
Signature · 1 line
2.12.0
PATCH 3/4 x86/crypto: serpent: Fix function prototypes
In reply to Joao MoreiraConvert the use of 'struct serpent_ctx *' to 'void *' in prototypes of functions which are referenced through 'struct common_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.
Whenever needed, cast 'void *' to 'struct serpent_ctx *'.
--- arch/x86/crypto/serpent_avx2_glue.c | 14 ++++++-------- arch/x86/crypto/serpent_avx_glue.c | 19 ++++++++----------- arch/x86/include/asm/crypto/serpent-avx.h | 25 +++++++++++-------------- arch/x86/include/asm/crypto/serpent-sse2.h | 30 ++++++++++++------------------ 4 files changed, 37 insertions(+), 51 deletions(-)
arch/x86/crypto/serpent_avx2_glue.c +6 -8
@@ -27,18 +27,16 @@#define SERPENT_AVX2_PARALLEL_BLOCKS 16/* 16-way AVX2 parallel cipher functions */ -asmlinkage void serpent_ecb_enc_16way(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void serpent_ecb_dec_16way(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void serpent_ecb_enc_16way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void serpent_ecb_dec_16way(void *ctx, u8 *dst, const u8 *src); asmlinkage void serpent_cbc_dec_16way(void *ctx, u128 *dst, const u128 *src); asmlinkage void serpent_ctr_16way(void *ctx, u128 *dst, const u128 *src,le128 *iv); -asmlinkage void serpent_xts_enc_16way(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); -asmlinkage void serpent_xts_dec_16way(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void serpent_xts_enc_16way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); +asmlinkage void serpent_xts_dec_16way(void *ctx, u8 *dst, const u8 *src, +le128 *iv);static const struct common_glue_ctx serpent_enc = { .num_funcs =3 ,
arch/x86/crypto/serpent_avx_glue.c +8 -11
@@ -41,28 +41,25 @@#include <asm/crypto/glue_helper.h> /* 8-way parallel cipher functions */ -asmlinkage void serpent_ecb_enc_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void serpent_ecb_enc_8way_avx(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (serpent_ecb_enc_8way_avx); -asmlinkage void serpent_ecb_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void serpent_ecb_dec_8way_avx(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (serpent_ecb_dec_8way_avx); -asmlinkage void serpent_cbc_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void serpent_cbc_dec_8way_avx(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (serpent_cbc_dec_8way_avx); -asmlinkage void serpent_ctr_8way_avx(struct serpent_ctx *ctx, u8 *dst, +asmlinkage void serpent_ctr_8way_avx(void *ctx, u8 *dst,const u8 *src,le128 *iv);EXPORT_SYMBOL_GPL (serpent_ctr_8way_avx); -asmlinkage void serpent_xts_enc_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void serpent_xts_enc_8way_avx(void *ctx, u8 *dst, const u8 *src, +le128 *iv);EXPORT_SYMBOL_GPL (serpent_xts_enc_8way_avx); -asmlinkage void serpent_xts_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void serpent_xts_dec_8way_avx(void *ctx, u8 *dst, const u8 *src, +le128 *iv);EXPORT_SYMBOL_GPL (serpent_xts_dec_8way_avx);void __serpent_crypt_ctr (void *ctx,u128 *dst,const u128 *src,le128 *iv)
arch/x86/include/asm/crypto/serpent-avx.h +11 -14
@@ -17,20 +17,17 @@ struct serpent_xts_ctx {struct serpent_ctx crypt_ctx; }; -asmlinkage void serpent_ecb_enc_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void serpent_ecb_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); - -asmlinkage void serpent_cbc_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void serpent_ctr_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); - -asmlinkage void serpent_xts_enc_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); -asmlinkage void serpent_xts_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); +asmlinkage void serpent_ecb_enc_8way_avx(void *ctx, u8 *dst, const u8 *src); +asmlinkage void serpent_ecb_dec_8way_avx(void *ctx, u8 *dst, const u8 *src); + +asmlinkage void serpent_cbc_dec_8way_avx(void *ctx, u8 *dst, const u8 *src); +asmlinkage void serpent_ctr_8way_avx(void *ctx, u8 *dst, const u8 *src, +le128 *iv); + +asmlinkage void serpent_xts_enc_8way_avx(void *ctx, u8 *dst, const u8 *src, +le128 *iv); +asmlinkage void serpent_xts_dec_8way_avx(void *ctx, u8 *dst, const u8 *src, +le128 *iv);extern void __serpent_crypt_ctr (void *ctx,u128 *dst,const u128 *src,le128 *iv);
arch/x86/include/asm/crypto/serpent-sse2.h +12 -18
@@ -14,22 +14,19 @@ asmlinkage void __serpent_enc_blk_4way(struct serpent_ctx *ctx, u8 *dst, asmlinkage void serpent_dec_blk_4way(struct serpent_ctx *ctx, u8 *dst,const u8 *src); -static inline void serpent_enc_blk_xway (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_enc_blk_xway (void *ctx,u8 *dst,const u8 *src) { -__serpent_enc_blk_4way (ctx, dst, src, false); +__serpent_enc_blk_4way ((struct serpent_ctx *) ctx, dst, src, false); } -static inline void serpent_enc_blk_xway_xor (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_enc_blk_xway_xor (void *ctx,u8 *dst,const u8 *src) { -__serpent_enc_blk_4way (ctx, dst, src, true); +__serpent_enc_blk_4way ((struct serpent_ctx *) ctx, dst, src, true); } -static inline void serpent_dec_blk_xway (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_dec_blk_xway (void *ctx,u8 *dst,const u8 *src) { -serpent_dec_blk_4way (ctx, dst, src); +serpent_dec_blk_4way ((struct serpent_ctx *) ctx, dst, src); }#else
@@ -41,22 +38,19 @@ asmlinkage void __serpent_enc_blk_8way(struct serpent_ctx *ctx, u8 *dst, asmlinkage void serpent_dec_blk_8way(struct serpent_ctx *ctx, u8 *dst,const u8 *src); -static inline void serpent_enc_blk_xway (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_enc_blk_xway (void *ctx,u8 *dst,const u8 *src) { -__serpent_enc_blk_8way (ctx, dst, src, false); +__serpent_enc_blk_8way ((struct serpent_ctx *) ctx, dst, src, false); } -static inline void serpent_enc_blk_xway_xor (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_enc_blk_xway_xor (void *ctx,u8 *dst,const u8 *src) { -__serpent_enc_blk_8way (ctx, dst, src, true); +__serpent_enc_blk_8way ((struct serpent_ctx *) ctx, dst, src, true); } -static inline void serpent_dec_blk_xway (struct serpent_ctx *ctx,u8 *dst, -const u8 *src) +static inline void serpent_dec_blk_xway (void *ctx,u8 *dst,const u8 *src) { -serpent_dec_blk_8way (ctx, dst, src); +serpent_dec_blk_8way ((struct serpent_ctx *) ctx, dst, src); }#endif
Signature · 1 line
2.12.0
PATCH 4/4 x86/crypto: twofish: Fix function prototypes
In reply to Joao MoreiraConvert the use of 'struct twofish_ctx *' to 'void *' in prototypes of functions which are referenced through 'struct common_glue_func_entry', making their prototypes match those of this struct and, consequently, turning them compatible with CFI requirements.
Whenever needed, cast 'void *' to 'struct twofish_ctx *'.
--- arch/x86/crypto/twofish_avx_glue.c | 30 +++++++++++++----------------- arch/x86/crypto/twofish_glue.c | 7 +++---- arch/x86/crypto/twofish_glue_3way.c | 10 ++++------ arch/x86/include/asm/crypto/twofish.h | 9 +++------ 4 files changed, 23 insertions(+), 33 deletions(-)
arch/x86/crypto/twofish_avx_glue.c +13 -17
@@ -46,25 +46,21 @@#define TWOFISH_PARALLEL_BLOCKS 8/* 8-way parallel cipher functions */ -asmlinkage void twofish_ecb_enc_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void twofish_ecb_dec_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); - -asmlinkage void twofish_cbc_dec_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void twofish_ctr_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); - -asmlinkage void twofish_xts_enc_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); -asmlinkage void twofish_xts_dec_8way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src,le128 *iv); - -static inline void twofish_enc_blk_3way (struct twofish_ctx *ctx,u8 *dst, +asmlinkage void twofish_ecb_enc_8way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void twofish_ecb_dec_8way(void *ctx, u8 *dst, const u8 *src); + +asmlinkage void twofish_cbc_dec_8way(void *ctx, u8 *dst, const u8 *src); +asmlinkage void twofish_ctr_8way(void *ctx, u8 *dst, const u8 *src, le128 *iv); + +asmlinkage void twofish_xts_enc_8way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); +asmlinkage void twofish_xts_dec_8way(void *ctx, u8 *dst, const u8 *src, +le128 *iv); + +static inline void twofish_enc_blk_3way (void *ctx,u8 *dst,const u8 *src) { -__twofish_enc_blk_3way (ctx, dst, src, false); +__twofish_enc_blk_3way ((struct twofish_ctx *) ctx, dst, src, false); }static void twofish_xts_enc (void *ctx,u128 *dst,const u128 *src,le128 *iv)
arch/x86/crypto/twofish_glue.c +3 -4
@@ -44,11 +44,10 @@#include <linux/module.h> #include <linux/types.h> -asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void twofish_enc_blk(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (twofish_enc_blk); -asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); + +asmlinkage void twofish_dec_blk(void *ctx, u8 *dst, const u8 *src);EXPORT_SYMBOL_GPL (twofish_dec_blk);static void twofish_encrypt (struct crypto_tfm *tfm,u8 *dst,const u8 *src)
arch/x86/crypto/twofish_glue_3way.c +4 -6
@@ -36,16 +36,14 @@EXPORT_SYMBOL_GPL (__twofish_enc_blk_3way);EXPORT_SYMBOL_GPL (twofish_dec_blk_3way); -static inline void twofish_enc_blk_3way (struct twofish_ctx *ctx,u8 *dst, -const u8 *src) +static inline void twofish_enc_blk_3way (void *ctx,u8 *dst,const u8 *src) { -__twofish_enc_blk_3way (ctx, dst, src, false); +__twofish_enc_blk_3way ((struct twofish_ctx *) ctx, dst, src, false); } -static inline void twofish_enc_blk_xor_3way (struct twofish_ctx *ctx,u8 *dst, -const u8 *src) +static inline void twofish_enc_blk_xor_3way (void *ctx,u8 *dst,const u8 *src) { -__twofish_enc_blk_3way (ctx, dst, src, true); +__twofish_enc_blk_3way ((struct twofish_ctx *) ctx, dst, src, true); }void twofish_dec_blk_cbc_3way (void *ctx,u128 *dst,const u128 *src)
arch/x86/include/asm/crypto/twofish.h +3 -6
@@ -18,16 +18,13 @@ struct twofish_xts_ctx { };/* regular block cipher functions from twofish_x86_64 module */ -asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); -asmlinkage void twofish_dec_blk(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void twofish_enc_blk(void *ctx, u8 *dst, const u8 *src); +asmlinkage void twofish_dec_blk(void *ctx, u8 *dst, const u8 *src);/* 3-way parallel cipher functions */ asmlinkage void __twofish_enc_blk_3way(struct twofish_ctx *ctx, u8 *dst,const u8 *src,bool xor); -asmlinkage void twofish_dec_blk_3way(struct twofish_ctx *ctx, u8 *dst, -const u8 *src); +asmlinkage void twofish_dec_blk_3way(void *ctx, u8 *dst, const u8 *src);/* helpers from twofish_x86_64-3way module */ extern void twofish_dec_blk_cbc_3way (void *ctx,u128 *dst,const u128 *src);
Signature · 1 line
2.12.0