summaryrefslogtreecommitdiff
path: root/include/crypto
diff options
context:
space:
mode:
authorJonathan Cameron <Jonathan.Cameron@huawei.com>2017-12-19 10:27:24 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-03-03 10:24:29 +0100
commit36d0a678fb25a7bce5bf9b2828c0d9395fa9a990 (patch)
treeed500363a67889db4305e94fb294bc653cfe472b /include/crypto
parent99b329b4611a17df15e7122fdf4bbfb8a1245d67 (diff)
crypto: af_alg - Fix race around ctx->rcvused by making it atomic_t
[ Upstream commit af955bf15d2c27496b0269b1f05c26f758c68314 ] This variable was increased and decreased without any protection. Result was an occasional misscount and negative wrap around resulting in false resource allocation failures. Fixes: 7d2c3f54e6f6 ("crypto: af_alg - remove locking in async callback") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/crypto')
-rw-r--r--include/crypto/if_alg.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h
index aeec003a566b..ac0eae8372ab 100644
--- a/include/crypto/if_alg.h
+++ b/include/crypto/if_alg.h
@@ -18,6 +18,7 @@
#include <linux/if_alg.h>
#include <linux/scatterlist.h>
#include <linux/types.h>
+#include <linux/atomic.h>
#include <net/sock.h>
#include <crypto/aead.h>
@@ -155,7 +156,7 @@ struct af_alg_ctx {
struct af_alg_completion completion;
size_t used;
- size_t rcvused;
+ atomic_t rcvused;
bool more;
bool merge;
@@ -228,7 +229,7 @@ static inline int af_alg_rcvbuf(struct sock *sk)
struct af_alg_ctx *ctx = ask->private;
return max_t(int, max_t(int, sk->sk_rcvbuf & PAGE_MASK, PAGE_SIZE) -
- ctx->rcvused, 0);
+ atomic_read(&ctx->rcvused), 0);
}
/**