Skip to content

Commit 962ddc5

Browse files
Eric Biggersherbertx
authored andcommitted
crypto: acomp - Fix CFI failure due to type punning
To avoid a crash when control flow integrity is enabled, make the workspace ("stream") free function use a consistent type, and call it through a function pointer that has that same type. Fixes: 42d9f6c ("crypto: acomp - Move scomp stream allocation code into acomp") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3d9eb18 commit 962ddc5

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

crypto/deflate.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ static void *deflate_alloc_stream(void)
4848
return ctx;
4949
}
5050

51+
static void deflate_free_stream(void *ctx)
52+
{
53+
kvfree(ctx);
54+
}
55+
5156
static struct crypto_acomp_streams deflate_streams = {
5257
.alloc_ctx = deflate_alloc_stream,
53-
.cfree_ctx = kvfree,
58+
.free_ctx = deflate_free_stream,
5459
};
5560

5661
static int deflate_compress_one(struct acomp_req *req,

crypto/zstd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ static void *zstd_alloc_stream(void)
5454
return ctx;
5555
}
5656

57+
static void zstd_free_stream(void *ctx)
58+
{
59+
kvfree(ctx);
60+
}
61+
5762
static struct crypto_acomp_streams zstd_streams = {
5863
.alloc_ctx = zstd_alloc_stream,
59-
.cfree_ctx = kvfree,
64+
.free_ctx = zstd_free_stream,
6065
};
6166

6267
static int zstd_init(struct crypto_acomp *acomp_tfm)

include/crypto/internal/acompress.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ struct crypto_acomp_stream {
6363
struct crypto_acomp_streams {
6464
/* These must come first because of struct scomp_alg. */
6565
void *(*alloc_ctx)(void);
66-
union {
67-
void (*free_ctx)(void *);
68-
void (*cfree_ctx)(const void *);
69-
};
66+
void (*free_ctx)(void *);
7067

7168
struct crypto_acomp_stream __percpu *streams;
7269
struct work_struct stream_work;

0 commit comments

Comments
 (0)