LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>,
	KY Srinivasan <kys@microsoft.com>,
	"devel@linuxdriverproject.org" <devel@linuxdriverproject.org>
Cc: Haiyang Zhang <haiyangz@microsoft.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Jason Wang <jasowang@redhat.com>
Subject: RE: [PATCH 4/4] hyperv: netvsc: improve protection against rescind offer
Date: Wed, 4 Feb 2015 07:29:09 +0000	[thread overview]
Message-ID: <F792CF86EFE20D4AB8064279AFBA51C61F33A63D@HKNPRD3002MB017.064d.mgd.msft.net> (raw)
In-Reply-To: <1422982839-3948-5-git-send-email-vkuznets@redhat.com>

> -----Original Message-----
> From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com]
> Sent: Wednesday, February 4, 2015 1:01 AM
> To: KY Srinivasan; devel@linuxdriverproject.org
> Cc: Haiyang Zhang; linux-kernel@vger.kernel.org; Dexuan Cui; Jason Wang
> Subject: [PATCH 4/4] hyperv: netvsc: improve protection against rescind offer
> 
> The check added in commit c3582a2c4d0b ("hyperv: Add support for vNIC hot
> removal") is incomplete as there is no synchronization between
> vmbus_onoffer_rescind() and netvsc_send(). In case we get the offer after we
> checked out_channel->rescind and before netvsc_send() finishes its job we can
> get a crash as we'll be dealing with already freed channel.
> 
> Make netvsc_send() take additional reference to the channel with newly
> introduced vmbus_get_channel(), this guarantees we won't lose the channel.
> We
> can still get rescind while we're processing but this won't cause a crash.
> 
> Reported-by: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  drivers/net/hyperv/netvsc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> index 9f49c01..d9b13a1 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -763,11 +763,16 @@ int netvsc_send(struct hv_device *device,
>  	out_channel = net_device->chn_table[packet->q_idx];
>  	if (out_channel == NULL)
>  		out_channel = device->channel;
> -	packet->channel = out_channel;
> +	packet->channel = vmbus_get_channel(out_channel);
> 
> -	if (out_channel->rescind)
> +	if (!packet->channel)
>  		return -ENODEV;
> 
> +	if (out_channel->rescind) {
> +		vmbus_put_channel(out_channel);

IMO the patch doesn't resolve the real issue.
At most it prevents the channel from disappearing in netvsc_send() only,
while actually we also need to make sure the channel is not freed before the
driver runs netvsc_remove() -> rndis_filter_device_remove() -> 
	-> netvsc_device_remove() -> vmbus_close().

I suggest we add vmbus_get/put_channel() in vmbus_open/close()?

-- Dexuan

> +		return -ENODEV;
> +	}
> +
>  	if (packet->page_buf_cnt) {
>  		ret = vmbus_sendpacket_pagebuffer(out_channel,
>  						  packet->page_buf,
> @@ -810,6 +815,7 @@ int netvsc_send(struct hv_device *device,
>  			   packet, ret);
>  	}
> 
> +	vmbus_put_channel(packet->channel);
>  	return ret;
>  }
> 
> --


  reply	other threads:[~2015-02-04  7:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03 17:00 [PATCH 0/4] Drivers: hv: Further protection for the rescind path Vitaly Kuznetsov
2015-02-03 17:00 ` [PATCH 1/4] Drivers: hv: vmbus: implement get/put usage workflow for vmbus channels Vitaly Kuznetsov
2015-02-04  8:18   ` Dexuan Cui
2015-02-04  9:32     ` Vitaly Kuznetsov
2015-02-04  9:54       ` Dexuan Cui
2015-02-04  9:14   ` Jason Wang
2015-02-04  9:33     ` Vitaly Kuznetsov
2015-02-03 17:00 ` [PATCH 2/4] Drivers: hv: vmbus: do not lose rescind offer on failure in vmbus_process_offer() Vitaly Kuznetsov
2015-02-04  7:42   ` Dexuan Cui
2015-02-03 17:00 ` [PATCH 3/4] Drivers: hv: vmbus: protect vmbus_get_outgoing_channel() against channel removal Vitaly Kuznetsov
2015-02-04  7:27   ` Dexuan Cui
2015-02-03 17:00 ` [PATCH 4/4] hyperv: netvsc: improve protection against rescind offer Vitaly Kuznetsov
2015-02-04  7:29   ` Dexuan Cui [this message]
2015-02-04 18:26 ` [PATCH 0/4] Drivers: hv: Further protection for the rescind path KY Srinivasan
2015-02-05 10:10   ` Vitaly Kuznetsov
2015-02-05 12:44     ` Dexuan Cui
2015-02-05 22:47       ` KY Srinivasan
2015-02-06 14:53         ` Dexuan Cui
2015-02-07 16:27           ` KY Srinivasan
2015-02-05 15:52     ` KY Srinivasan

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=F792CF86EFE20D4AB8064279AFBA51C61F33A63D@HKNPRD3002MB017.064d.mgd.msft.net \
    --to=decui@microsoft.com \
    --cc=devel@linuxdriverproject.org \
    --cc=haiyangz@microsoft.com \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vkuznets@redhat.com \
    --subject='RE: [PATCH 4/4] hyperv: netvsc: improve protection against rescind offer' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).