History

crypto: algif_aead - fix uninitialized ctx->init

In skcipher_accept_parent_nokey() the whole af_alg_ctx structure is cleared by memset() after allocation, so add such memset() also to aead_accept_parent_nokey() so that the new "init" field is also initialized to zero. Without that the initial ctx->init checks might randomly return true and cause errors. While there, also remove the redundant zero assignments in both functions. Found via libkcapi testsuite.

Ondrej Mosnacek committed 6 years ago

Commit 21dfbcd1 parent 3cbfe802 files · +1 −12Browse files

Unified · Split

2 files
  1. crypto/algif_aead.c +0 −6
  2. crypto/algif_skcipher.c +1 −6
crypto/algif_aead.c+0−6
@@ -558,12 +558,6 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk) · 557 unmodified lines
558558
559559 INIT_LIST_HEAD(&ctx->tsgl_list);
560560 ctx->len = len;
561− ctx->used = 0;
562− atomic_set(&ctx->rcvused, 0);
563− ctx->more = 0;
564− ctx->merge = 0;
565− ctx->enc = 0;
566− ctx->aead_assoclen = 0;
567561 crypto_init_wait(&ctx->wait);
568562
569563 ask->private = ctx;
crypto/algif_skcipher.c+1−6
@@ -333,6 +333,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) · 332 unmodified lines
333333 ctx = sock_kmalloc(sk, len, GFP_KERNEL);
334334 if (!ctx)
335335 return -ENOMEM;
336+ memset(ctx, 0, len);
336337
337338 ctx->iv = sock_kmalloc(sk, crypto_skcipher_ivsize(tfm),
338339 GFP_KERNEL);
@@ -340,16 +341,10 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) · 1 unmodified line
340341 sock_kfree_s(sk, ctx, len);
341342 return -ENOMEM;
342343 }
343−
344344 memset(ctx->iv, 0, crypto_skcipher_ivsize(tfm));
345345
346346 INIT_LIST_HEAD(&ctx->tsgl_list);
347347 ctx->len = len;
348− ctx->used = 0;
349− atomic_set(&ctx->rcvused, 0);
350− ctx->more = 0;
351− ctx->merge = 0;
352− ctx->enc = 0;
353348 crypto_init_wait(&ctx->wait);
354349
355350 ask->private = ctx;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t