Skip to content

Commit 9ae0c92

Browse files
committed
crypto: scomp - Fix wild memory accesses in scomp_free_streams
In order to use scomp_free_streams to free the partially allocted streams in the allocation error path, move the alg->stream assignment to the beginning. Also check for error pointers in scomp_free_streams before freeing the ctx. Finally set alg->stream to NULL to not break subsequent attempts to allocate the streams. Fixes: 3d72ad4 ("crypto: acomp - Move stream management into scomp layer") Reported-by: syzkaller <[email protected]> Co-developed-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Kuniyuki Iwashima <[email protected]> Co-developed-by: Herbert Xu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent b7b39df commit 9ae0c92

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crypto/scompress.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ static void scomp_free_streams(struct scomp_alg *alg)
111111
struct crypto_acomp_stream __percpu *stream = alg->stream;
112112
int i;
113113

114+
alg->stream = NULL;
114115
if (!stream)
115116
return;
116117

117118
for_each_possible_cpu(i) {
118119
struct crypto_acomp_stream *ps = per_cpu_ptr(stream, i);
119120

120-
if (!ps->ctx)
121+
if (IS_ERR_OR_NULL(ps->ctx))
121122
break;
122123

123124
alg->free_ctx(ps->ctx);
@@ -135,6 +136,8 @@ static int scomp_alloc_streams(struct scomp_alg *alg)
135136
if (!stream)
136137
return -ENOMEM;
137138

139+
alg->stream = stream;
140+
138141
for_each_possible_cpu(i) {
139142
struct crypto_acomp_stream *ps = per_cpu_ptr(stream, i);
140143

@@ -146,8 +149,6 @@ static int scomp_alloc_streams(struct scomp_alg *alg)
146149

147150
spin_lock_init(&ps->lock);
148151
}
149-
150-
alg->stream = stream;
151152
return 0;
152153
}
153154

0 commit comments

Comments
 (0)