All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guillaume Nault <gnault@redhat.com>
To: Tom Parkin <tparkin@katalix.com>
Cc: netdev@vger.kernel.org, jchapman@katalix.com
Subject: Re: [PATCH v3 net-next 1/2] ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls
Date: Mon, 7 Dec 2020 17:22:28 +0100	[thread overview]
Message-ID: <20201207162228.GA28888@linux.home> (raw)
In-Reply-To: <20201204163656.1623-2-tparkin@katalix.com>

On Fri, Dec 04, 2020 at 04:36:55PM +0000, Tom Parkin wrote:
> +static int ppp_unbridge_channels(struct channel *pch)
> +{
> +	struct channel *pchb, *pchbb;
> +
> +	write_lock_bh(&pch->upl);
> +	pchb = rcu_dereference_protected(pch->bridge, lockdep_is_held(&pch->upl));
> +	if (!pchb) {
> +		write_unlock_bh(&pch->upl);
> +		return -EINVAL;
> +	}
> +	RCU_INIT_POINTER(pch->bridge, NULL);
> +	write_unlock_bh(&pch->upl);
> +
> +	write_lock_bh(&pchb->upl);
> +	pchbb = rcu_dereference_protected(pchb->bridge, lockdep_is_held(&pchb->upl));
> +	if (pchbb == pch)
> +		RCU_INIT_POINTER(pchb->bridge, NULL);
> +	write_unlock_bh(&pchb->upl);
> +
> +	synchronize_rcu();
> +
> +	if (pchbb == pch)
> +		if (refcount_dec_and_test(&pch->file.refcnt))
> +			ppp_destroy_channel(pch);

Since a respin is needed (see below), maybe add a comment explaining
why we need to verify that pchbb == pch.

> +	if (refcount_dec_and_test(&pchb->file.refcnt))
> +		ppp_destroy_channel(pchb);
> +
> +	return 0;
> +}
> +
>  static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  {
>  	struct ppp_file *pf;
> @@ -641,8 +714,9 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  	}
>  
>  	if (pf->kind == CHANNEL) {
> -		struct channel *pch;
> +		struct channel *pch, *pchb;
>  		struct ppp_channel *chan;
> +		struct ppp_net *pn;
>  
>  		pch = PF_TO_CHANNEL(pf);
>  
> @@ -657,6 +731,29 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  			err = ppp_disconnect_channel(pch);
>  			break;
>  
> +		case PPPIOCBRIDGECHAN:
> +			if (get_user(unit, p))
> +				break;
> +			err = -ENXIO;
> +			pn = ppp_pernet(current->nsproxy->net_ns);
> +			spin_lock_bh(&pn->all_channels_lock);
> +			pchb = ppp_find_channel(pn, unit);
> +			/* Hold a reference to prevent pchb being freed while
> +			 * we establish the bridge.
> +			 */
> +			if (pchb)
> +				refcount_inc(&pchb->file.refcnt);

The !pchb case isn't handled. With this code, if ppp_find_channel()
returns NULL, ppp_bridge_channels() will crash when trying to lock
pchb->upl.

> +			spin_unlock_bh(&pn->all_channels_lock);
> +			err = ppp_bridge_channels(pch, pchb);
> +			/* Drop earlier refcount now bridge establishment is complete */
> +			if (refcount_dec_and_test(&pchb->file.refcnt))
> +				ppp_destroy_channel(pchb);
> +			break;
> +

The rest looks good to me.


  reply	other threads:[~2020-12-07 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04 16:36 [PATCH v3 net-next 0/2] add ppp_generic ioctl(s) to bridge channels Tom Parkin
2020-12-04 16:36 ` [PATCH v3 net-next 1/2] ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls Tom Parkin
2020-12-07 16:22   ` Guillaume Nault [this message]
2020-12-10 14:46     ` Tom Parkin
2020-12-10 15:05       ` Guillaume Nault
2020-12-04 16:36 ` [PATCH v3 net-next 2/2] docs: update ppp_generic.rst to document new ioctls Tom Parkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207162228.GA28888@linux.home \
    --to=gnault@redhat.com \
    --cc=jchapman@katalix.com \
    --cc=netdev@vger.kernel.org \
    --cc=tparkin@katalix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.