[PATCH] AF_ALG: Initialize sg_num_bytes in error code path

From: Stephan Mueller
Date: Sun Apr 08 2018 - 13:53:59 EST


The RX SGL in processing is already registered with the RX SGL tracking
list to support proper cleanup. The cleanup code path uses the
sg_num_bytes variable which must therefore be always initialized, even
in the error code path.

Signed-off-by: Stephan Mueller <smueller@xxxxxxxxxx>
Reported-by: syzbot+9c251bdd09f83b92ba95@xxxxxxxxxxxxxxxxxxxxxxxxx
---
crypto/af_alg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index c49766b03165..0d555c072669 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -1156,8 +1156,10 @@ int af_alg_get_rsgl(struct sock *sk, struct msghdr *msg, int flags,

/* make one iovec available as scatterlist */
err = af_alg_make_sg(&rsgl->sgl, &msg->msg_iter, seglen);
- if (err < 0)
+ if (err < 0) {
+ rsgl->sg_num_bytes = 0;
return err;
+ }

/* chain the new scatterlist with previous one */
if (areq->last_rsgl)
--
2.14.3