Commit c4eb62da authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Revert: "crypto: af_alg - Disallow bind/setkey/... after accept(2)"

This reverts commit 06b41945 which is
commit c840ac6a upstream.

It's been widely reported that this patch breaks existing userspace
applications when backported to the stable kernel releases.  As no fix
seems to be forthcoming, just revert it to let systems work again.
Reported-by: default avatar"J. Paul Reed" <preed@sigkill.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 952b0e42
...@@ -125,23 +125,6 @@ int af_alg_release(struct socket *sock) ...@@ -125,23 +125,6 @@ int af_alg_release(struct socket *sock)
} }
EXPORT_SYMBOL_GPL(af_alg_release); EXPORT_SYMBOL_GPL(af_alg_release);
void af_alg_release_parent(struct sock *sk)
{
struct alg_sock *ask = alg_sk(sk);
bool last;
sk = ask->parent;
ask = alg_sk(sk);
lock_sock(sk);
last = !--ask->refcnt;
release_sock(sk);
if (last)
sock_put(sk);
}
EXPORT_SYMBOL_GPL(af_alg_release_parent);
static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -149,7 +132,6 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -149,7 +132,6 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
struct sockaddr_alg *sa = (void *)uaddr; struct sockaddr_alg *sa = (void *)uaddr;
const struct af_alg_type *type; const struct af_alg_type *type;
void *private; void *private;
int err;
if (sock->state == SS_CONNECTED) if (sock->state == SS_CONNECTED)
return -EINVAL; return -EINVAL;
...@@ -175,22 +157,16 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -175,22 +157,16 @@ static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
return PTR_ERR(private); return PTR_ERR(private);
} }
err = -EBUSY;
lock_sock(sk); lock_sock(sk);
if (ask->refcnt)
goto unlock;
swap(ask->type, type); swap(ask->type, type);
swap(ask->private, private); swap(ask->private, private);
err = 0;
unlock:
release_sock(sk); release_sock(sk);
alg_do_release(type, private); alg_do_release(type, private);
return err; return 0;
} }
static int alg_setkey(struct sock *sk, char __user *ukey, static int alg_setkey(struct sock *sk, char __user *ukey,
...@@ -223,15 +199,11 @@ static int alg_setsockopt(struct socket *sock, int level, int optname, ...@@ -223,15 +199,11 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk); struct alg_sock *ask = alg_sk(sk);
const struct af_alg_type *type; const struct af_alg_type *type;
int err = -EBUSY; int err = -ENOPROTOOPT;
lock_sock(sk); lock_sock(sk);
if (ask->refcnt)
goto unlock;
type = ask->type; type = ask->type;
err = -ENOPROTOOPT;
if (level != SOL_ALG || !type) if (level != SOL_ALG || !type)
goto unlock; goto unlock;
...@@ -280,8 +252,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock) ...@@ -280,8 +252,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock)
sk2->sk_family = PF_ALG; sk2->sk_family = PF_ALG;
if (!ask->refcnt++) sock_hold(sk);
sock_hold(sk);
alg_sk(sk2)->parent = sk; alg_sk(sk2)->parent = sk;
alg_sk(sk2)->type = type; alg_sk(sk2)->type = type;
......
...@@ -30,8 +30,6 @@ struct alg_sock { ...@@ -30,8 +30,6 @@ struct alg_sock {
struct sock *parent; struct sock *parent;
unsigned int refcnt;
const struct af_alg_type *type; const struct af_alg_type *type;
void *private; void *private;
}; };
...@@ -66,7 +64,6 @@ int af_alg_register_type(const struct af_alg_type *type); ...@@ -66,7 +64,6 @@ int af_alg_register_type(const struct af_alg_type *type);
int af_alg_unregister_type(const struct af_alg_type *type); int af_alg_unregister_type(const struct af_alg_type *type);
int af_alg_release(struct socket *sock); int af_alg_release(struct socket *sock);
void af_alg_release_parent(struct sock *sk);
int af_alg_accept(struct sock *sk, struct socket *newsock); int af_alg_accept(struct sock *sk, struct socket *newsock);
int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len, int af_alg_make_sg(struct af_alg_sgl *sgl, void __user *addr, int len,
...@@ -83,6 +80,11 @@ static inline struct alg_sock *alg_sk(struct sock *sk) ...@@ -83,6 +80,11 @@ static inline struct alg_sock *alg_sk(struct sock *sk)
return (struct alg_sock *)sk; return (struct alg_sock *)sk;
} }
static inline void af_alg_release_parent(struct sock *sk)
{
sock_put(alg_sk(sk)->parent);
}
static inline void af_alg_init_completion(struct af_alg_completion *completion) static inline void af_alg_init_completion(struct af_alg_completion *completion)
{ {
init_completion(&completion->completion); init_completion(&completion->completion);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment