Skip to content

Commit 9c1e883

Browse files
keesherbertx
authored andcommitted
crypto: x86 - Regularize glue function prototypes
The crypto glue performed function prototype casting via macros to make indirect calls to assembly routines. Instead of performing casts at the call sites (which trips Control Flow Integrity prototype checking), switch each prototype to a common standard set of arguments which allows the removal of the existing macros. In order to keep pointer math unchanged, internal casting between u128 pointers and u8 pointers is added. Co-developed-by: João Moreira <joao.moreira@intel.com> Signed-off-by: João Moreira <joao.moreira@intel.com> Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7278fa2 commit 9c1e883

22 files changed

Lines changed: 374 additions & 413 deletions

‎arch/x86/crypto/aesni-intel_asm.S‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,7 @@ SYM_FUNC_START(aesni_set_key)
19421942
SYM_FUNC_END(aesni_set_key)
19431943

19441944
/*
1945-
* void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
1945+
* void aesni_enc(const void *ctx, u8 *dst, const u8 *src)
19461946
*/
19471947
SYM_FUNC_START(aesni_enc)
19481948
FRAME_BEGIN
@@ -2131,7 +2131,7 @@ SYM_FUNC_START_LOCAL(_aesni_enc4)
21312131
SYM_FUNC_END(_aesni_enc4)
21322132

21332133
/*
2134-
* void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
2134+
* void aesni_dec (const void *ctx, u8 *dst, const u8 *src)
21352135
*/
21362136
SYM_FUNC_START(aesni_dec)
21372137
FRAME_BEGIN
@@ -2716,8 +2716,8 @@ SYM_FUNC_END(aesni_ctr_enc)
27162716
pxor CTR, IV;
27172717

27182718
/*
2719-
* void aesni_xts_crypt8(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
2720-
* bool enc, u8 *iv)
2719+
* void aesni_xts_crypt8(const struct crypto_aes_ctx *ctx, u8 *dst,
2720+
* const u8 *src, bool enc, le128 *iv)
27212721
*/
27222722
SYM_FUNC_START(aesni_xts_crypt8)
27232723
FRAME_BEGIN

‎arch/x86/crypto/aesni-intel_glue.c‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ struct gcm_context_data {
8383

8484
asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
8585
unsigned int key_len);
86-
asmlinkage void aesni_enc(struct crypto_aes_ctx *ctx, u8 *out,
87-
const u8 *in);
88-
asmlinkage void aesni_dec(struct crypto_aes_ctx *ctx, u8 *out,
89-
const u8 *in);
86+
asmlinkage void aesni_enc(const void *ctx, u8 *out, const u8 *in);
87+
asmlinkage void aesni_dec(const void *ctx, u8 *out, const u8 *in);
9088
asmlinkage void aesni_ecb_enc(struct crypto_aes_ctx *ctx, u8 *out,
9189
const u8 *in, unsigned int len);
9290
asmlinkage void aesni_ecb_dec(struct crypto_aes_ctx *ctx, u8 *out,
@@ -106,8 +104,8 @@ static void (*aesni_ctr_enc_tfm)(struct crypto_aes_ctx *ctx, u8 *out,
106104
asmlinkage void aesni_ctr_enc(struct crypto_aes_ctx *ctx, u8 *out,
107105
const u8 *in, unsigned int len, u8 *iv);
108106

109-
asmlinkage void aesni_xts_crypt8(struct crypto_aes_ctx *ctx, u8 *out,
110-
const u8 *in, bool enc, u8 *iv);
107+
asmlinkage void aesni_xts_crypt8(const struct crypto_aes_ctx *ctx, u8 *out,
108+
const u8 *in, bool enc, le128 *iv);
111109

112110
/* asmlinkage void aesni_gcm_enc()
113111
* void *ctx, AES Key schedule. Starts on a 16 byte boundary.
@@ -550,29 +548,24 @@ static int xts_aesni_setkey(struct crypto_skcipher *tfm, const u8 *key,
550548
}
551549

552550

553-
static void aesni_xts_tweak(void *ctx, u8 *out, const u8 *in)
551+
static void aesni_xts_enc(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
554552
{
555-
aesni_enc(ctx, out, in);
553+
glue_xts_crypt_128bit_one(ctx, dst, src, iv, aesni_enc);
556554
}
557555

558-
static void aesni_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv)
556+
static void aesni_xts_dec(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
559557
{
560-
glue_xts_crypt_128bit_one(ctx, dst, src, iv, GLUE_FUNC_CAST(aesni_enc));
558+
glue_xts_crypt_128bit_one(ctx, dst, src, iv, aesni_dec);
561559
}
562560

563-
static void aesni_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv)
561+
static void aesni_xts_enc8(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
564562
{
565-
glue_xts_crypt_128bit_one(ctx, dst, src, iv, GLUE_FUNC_CAST(aesni_dec));
563+
aesni_xts_crypt8(ctx, dst, src, true, iv);
566564
}
567565

568-
static void aesni_xts_enc8(void *ctx, u128 *dst, const u128 *src, le128 *iv)
566+
static void aesni_xts_dec8(const void *ctx, u8 *dst, const u8 *src, le128 *iv)
569567
{
570-
aesni_xts_crypt8(ctx, (u8 *)dst, (const u8 *)src, true, (u8 *)iv);
571-
}
572-
573-
static void aesni_xts_dec8(void *ctx, u128 *dst, const u128 *src, le128 *iv)
574-
{
575-
aesni_xts_crypt8(ctx, (u8 *)dst, (const u8 *)src, false, (u8 *)iv);
568+
aesni_xts_crypt8(ctx, dst, src, false, iv);
576569
}
577570

578571
static const struct common_glue_ctx aesni_enc_xts = {
@@ -581,10 +574,10 @@ static const struct common_glue_ctx aesni_enc_xts = {
581574

582575
.funcs = { {
583576
.num_blocks = 8,
584-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_enc8) }
577+
.fn_u = { .xts = aesni_xts_enc8 }
585578
}, {
586579
.num_blocks = 1,
587-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_enc) }
580+
.fn_u = { .xts = aesni_xts_enc }
588581
} }
589582
};
590583

@@ -594,10 +587,10 @@ static const struct common_glue_ctx aesni_dec_xts = {
594587

595588
.funcs = { {
596589
.num_blocks = 8,
597-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_dec8) }
590+
.fn_u = { .xts = aesni_xts_dec8 }
598591
}, {
599592
.num_blocks = 1,
600-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(aesni_xts_dec) }
593+
.fn_u = { .xts = aesni_xts_dec }
601594
} }
602595
};
603596

@@ -606,8 +599,7 @@ static int xts_encrypt(struct skcipher_request *req)
606599
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
607600
struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
608601

609-
return glue_xts_req_128bit(&aesni_enc_xts, req,
610-
XTS_TWEAK_CAST(aesni_xts_tweak),
602+
return glue_xts_req_128bit(&aesni_enc_xts, req, aesni_enc,
611603
aes_ctx(ctx->raw_tweak_ctx),
612604
aes_ctx(ctx->raw_crypt_ctx),
613605
false);
@@ -618,8 +610,7 @@ static int xts_decrypt(struct skcipher_request *req)
618610
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
619611
struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
620612

621-
return glue_xts_req_128bit(&aesni_dec_xts, req,
622-
XTS_TWEAK_CAST(aesni_xts_tweak),
613+
return glue_xts_req_128bit(&aesni_dec_xts, req, aesni_enc,
623614
aes_ctx(ctx->raw_tweak_ctx),
624615
aes_ctx(ctx->raw_crypt_ctx),
625616
true);

‎arch/x86/crypto/camellia_aesni_avx2_glue.c‎

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,34 @@
1919
#define CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS 32
2020

2121
/* 32-way AVX2/AES-NI parallel cipher functions */
22-
asmlinkage void camellia_ecb_enc_32way(struct camellia_ctx *ctx, u8 *dst,
23-
const u8 *src);
24-
asmlinkage void camellia_ecb_dec_32way(struct camellia_ctx *ctx, u8 *dst,
25-
const u8 *src);
22+
asmlinkage void camellia_ecb_enc_32way(const void *ctx, u8 *dst, const u8 *src);
23+
asmlinkage void camellia_ecb_dec_32way(const void *ctx, u8 *dst, const u8 *src);
2624

27-
asmlinkage void camellia_cbc_dec_32way(struct camellia_ctx *ctx, u8 *dst,
28-
const u8 *src);
29-
asmlinkage void camellia_ctr_32way(struct camellia_ctx *ctx, u8 *dst,
30-
const u8 *src, le128 *iv);
25+
asmlinkage void camellia_cbc_dec_32way(const void *ctx, u8 *dst, const u8 *src);
26+
asmlinkage void camellia_ctr_32way(const void *ctx, u8 *dst, const u8 *src,
27+
le128 *iv);
3128

32-
asmlinkage void camellia_xts_enc_32way(struct camellia_ctx *ctx, u8 *dst,
33-
const u8 *src, le128 *iv);
34-
asmlinkage void camellia_xts_dec_32way(struct camellia_ctx *ctx, u8 *dst,
35-
const u8 *src, le128 *iv);
29+
asmlinkage void camellia_xts_enc_32way(const void *ctx, u8 *dst, const u8 *src,
30+
le128 *iv);
31+
asmlinkage void camellia_xts_dec_32way(const void *ctx, u8 *dst, const u8 *src,
32+
le128 *iv);
3633

3734
static const struct common_glue_ctx camellia_enc = {
3835
.num_funcs = 4,
3936
.fpu_blocks_limit = CAMELLIA_AESNI_PARALLEL_BLOCKS,
4037

4138
.funcs = { {
4239
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
43-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_32way) }
40+
.fn_u = { .ecb = camellia_ecb_enc_32way }
4441
}, {
4542
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
46-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_16way) }
43+
.fn_u = { .ecb = camellia_ecb_enc_16way }
4744
}, {
4845
.num_blocks = 2,
49-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk_2way) }
46+
.fn_u = { .ecb = camellia_enc_blk_2way }
5047
}, {
5148
.num_blocks = 1,
52-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) }
49+
.fn_u = { .ecb = camellia_enc_blk }
5350
} }
5451
};
5552

@@ -59,16 +56,16 @@ static const struct common_glue_ctx camellia_ctr = {
5956

6057
.funcs = { {
6158
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
62-
.fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_32way) }
59+
.fn_u = { .ctr = camellia_ctr_32way }
6360
}, {
6461
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
65-
.fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_16way) }
62+
.fn_u = { .ctr = camellia_ctr_16way }
6663
}, {
6764
.num_blocks = 2,
68-
.fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr_2way) }
65+
.fn_u = { .ctr = camellia_crypt_ctr_2way }
6966
}, {
7067
.num_blocks = 1,
71-
.fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr) }
68+
.fn_u = { .ctr = camellia_crypt_ctr }
7269
} }
7370
};
7471

@@ -78,13 +75,13 @@ static const struct common_glue_ctx camellia_enc_xts = {
7875

7976
.funcs = { {
8077
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
81-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_32way) }
78+
.fn_u = { .xts = camellia_xts_enc_32way }
8279
}, {
8380
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
84-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_16way) }
81+
.fn_u = { .xts = camellia_xts_enc_16way }
8582
}, {
8683
.num_blocks = 1,
87-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc) }
84+
.fn_u = { .xts = camellia_xts_enc }
8885
} }
8986
};
9087

@@ -94,16 +91,16 @@ static const struct common_glue_ctx camellia_dec = {
9491

9592
.funcs = { {
9693
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
97-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_32way) }
94+
.fn_u = { .ecb = camellia_ecb_dec_32way }
9895
}, {
9996
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
100-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_16way) }
97+
.fn_u = { .ecb = camellia_ecb_dec_16way }
10198
}, {
10299
.num_blocks = 2,
103-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk_2way) }
100+
.fn_u = { .ecb = camellia_dec_blk_2way }
104101
}, {
105102
.num_blocks = 1,
106-
.fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk) }
103+
.fn_u = { .ecb = camellia_dec_blk }
107104
} }
108105
};
109106

@@ -113,16 +110,16 @@ static const struct common_glue_ctx camellia_dec_cbc = {
113110

114111
.funcs = { {
115112
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
116-
.fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_32way) }
113+
.fn_u = { .cbc = camellia_cbc_dec_32way }
117114
}, {
118115
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
119-
.fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_16way) }
116+
.fn_u = { .cbc = camellia_cbc_dec_16way }
120117
}, {
121118
.num_blocks = 2,
122-
.fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_decrypt_cbc_2way) }
119+
.fn_u = { .cbc = camellia_decrypt_cbc_2way }
123120
}, {
124121
.num_blocks = 1,
125-
.fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_dec_blk) }
122+
.fn_u = { .cbc = camellia_dec_blk }
126123
} }
127124
};
128125

@@ -132,13 +129,13 @@ static const struct common_glue_ctx camellia_dec_xts = {
132129

133130
.funcs = { {
134131
.num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS,
135-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_32way) }
132+
.fn_u = { .xts = camellia_xts_dec_32way }
136133
}, {
137134
.num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS,
138-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_16way) }
135+
.fn_u = { .xts = camellia_xts_dec_16way }
139136
}, {
140137
.num_blocks = 1,
141-
.fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec) }
138+
.fn_u = { .xts = camellia_xts_dec }
142139
} }
143140
};
144141

@@ -161,8 +158,7 @@ static int ecb_decrypt(struct skcipher_request *req)
161158

162159
static int cbc_encrypt(struct skcipher_request *req)
163160
{
164-
return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk),
165-
req);
161+
return glue_cbc_encrypt_req_128bit(camellia_enc_blk, req);
166162
}
167163

168164
static int cbc_decrypt(struct skcipher_request *req)
@@ -180,8 +176,7 @@ static int xts_encrypt(struct skcipher_request *req)
180176
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
181177
struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
182178

183-
return glue_xts_req_128bit(&camellia_enc_xts, req,
184-
XTS_TWEAK_CAST(camellia_enc_blk),
179+
return glue_xts_req_128bit(&camellia_enc_xts, req, camellia_enc_blk,
185180
&ctx->tweak_ctx, &ctx->crypt_ctx, false);
186181
}
187182

@@ -190,8 +185,7 @@ static int xts_decrypt(struct skcipher_request *req)
190185
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
191186
struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
192187

193-
return glue_xts_req_128bit(&camellia_dec_xts, req,
194-
XTS_TWEAK_CAST(camellia_enc_blk),
188+
return glue_xts_req_128bit(&camellia_dec_xts, req, camellia_enc_blk,
195189
&ctx->tweak_ctx, &ctx->crypt_ctx, true);
196190
}
197191

0 commit comments

Comments
 (0)