Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1224333

Re: [PATCH] pptp: avoid releasing the sock too early

From Eric Dumazet <eric.dumazet@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] pptp: avoid releasing the sock too early
Date 2015-09-14 18:50 +0200
Message-ID <q8F75-3qM-61@gated-at.bofh.it> (permalink)
References <q8Eb0-25a-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, 2015-09-14 at 11:40 -0400, Sasha Levin wrote:
> Since we're using RCU we can't free the sock structure before RCU lets us,
> otherwise we're risking getting use-after-frees accessing it:

> 
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
>  drivers/net/ppp/pptp.c   |    9 ++++++++-
>  include/linux/if_pppox.h |    1 +
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
> index 686f37d..cb7a029 100644
> --- a/drivers/net/ppp/pptp.c
> +++ b/drivers/net/ppp/pptp.c
> @@ -517,6 +517,13 @@ static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
>  	return 0;
>  }
>  
> +static void pptp_release_cb(struct rcu_head *rcu)
> +{
> +	struct pppox_sock *p = container_of(rcu, struct pppox_sock, rcu);
> +
> +	sock_put(sk_pppox(p));
> +}
> +
>  static int pptp_release(struct socket *sock)
>  {
>  	struct sock *sk = sock->sk;
> @@ -545,7 +552,7 @@ static int pptp_release(struct socket *sock)
>  	sock->sk = NULL;
>  
>  	release_sock(sk);
> -	sock_put(sk);
> +	call_rcu(&po->rcu, pptp_release_cb);
>  
>  	return error;
>  }
> diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
> index b49cf92..ba9c378 100644
> --- a/include/linux/if_pppox.h
> +++ b/include/linux/if_pppox.h
> @@ -55,6 +55,7 @@ struct pppox_sock {
>  		struct pptp_opt  pptp;
>  	} proto;
>  	__be16			num;
> +	struct rcu_head rcu;
>  };
>  #define pppoe_dev	proto.pppoe.dev
>  #define pppoe_ifindex	proto.pppoe.ifindex

Hmm, is the synchronize_rcu() in del_chan() still needed, and why it was
not enough ?

I believe your patch might reduce the race window, but it is not clear
it is the right fix.



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] pptp: avoid releasing the sock too early Sasha Levin <sasha.levin@oracle.com> - 2015-09-14 17:50 +0200
  Re: [PATCH] pptp: avoid releasing the sock too early Eric Dumazet <eric.dumazet@gmail.com> - 2015-09-14 18:50 +0200
    Re: [PATCH] pptp: avoid releasing the sock too early Sasha Levin <sasha.levin@oracle.com> - 2015-09-15 19:40 +0200

csiph-web