summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2018-01-02 02:55:25 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-01-12 07:03:05 -0500
commitbb30b8848c85e18ca7e371d0a869e94b3e383bdf (patch)
treee6acf772ef0252bf11c2b5035c02110f30b42ceb /crypto
parentda1729ce4866be266575a114208c7d5350bf310d (diff)
crypto: af_alg - whitelist mask and type
The user space interface allows specifying the type and mask field used to allocate the cipher. Only a subset of the possible flags are intended for user space. Therefore, white-list the allowed flags. In case the user space caller uses at least one non-allowed flag, EINVAL is returned. Reported-by: syzbot <syzkaller@googlegroups.com> Cc: <stable@vger.kernel.org> Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/af_alg.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 35d4dcea381f..5231f421ad00 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -150,7 +150,7 @@ EXPORT_SYMBOL_GPL(af_alg_release_parent);
150 150
151static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) 151static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
152{ 152{
153 const u32 forbidden = CRYPTO_ALG_INTERNAL; 153 const u32 allowed = CRYPTO_ALG_KERN_DRIVER_ONLY;
154 struct sock *sk = sock->sk; 154 struct sock *sk = sock->sk;
155 struct alg_sock *ask = alg_sk(sk); 155 struct alg_sock *ask = alg_sk(sk);
156 struct sockaddr_alg *sa = (void *)uaddr; 156 struct sockaddr_alg *sa = (void *)uaddr;
@@ -158,6 +158,10 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
158 void *private; 158 void *private;
159 int err; 159 int err;
160 160
161 /* If caller uses non-allowed flag, return error. */
162 if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed))
163 return -EINVAL;
164
161 if (sock->state == SS_CONNECTED) 165 if (sock->state == SS_CONNECTED)
162 return -EINVAL; 166 return -EINVAL;
163 167
@@ -176,9 +180,7 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
176 if (IS_ERR(type)) 180 if (IS_ERR(type))
177 return PTR_ERR(type); 181 return PTR_ERR(type);
178 182
179 private = type->bind(sa->salg_name, 183 private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
180 sa->salg_feat & ~forbidden,
181 sa->salg_mask & ~forbidden);
182 if (IS_ERR(private)) { 184 if (IS_ERR(private)) {
183 module_put(type->owner); 185 module_put(type->owner);
184 return PTR_ERR(private); 186 return PTR_ERR(private);