Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757725AbcJTJJm (ORCPT ); Thu, 20 Oct 2016 05:09:42 -0400 Received: from mail-sn1nam01on0131.outbound.protection.outlook.com ([104.47.32.131]:50676 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757623AbcJTJJi (ORCPT ); Thu, 20 Oct 2016 05:09:38 -0400 X-Greylist: delayed 1142 seconds by postgrey-1.27 at vger.kernel.org; Thu, 20 Oct 2016 05:09:38 EDT From: Stephen Hemminger To: Vitaly Kuznetsov , "netdev@vger.kernel.org" CC: "devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" , KY Srinivasan , Haiyang Zhang Subject: RE: [PATCH net-next] hv_netvsc: fix a race between netvsc_send() and netvsc_init_buf() Thread-Topic: [PATCH net-next] hv_netvsc: fix a race between netvsc_send() and netvsc_init_buf() Thread-Index: AQHSKhAfyvssqabbKEi9Z8HGzUcpz6CxBdXA Date: Thu, 20 Oct 2016 08:36:21 +0000 Message-ID: References: <1476885181-3456-1-git-send-email-vkuznets@redhat.com> In-Reply-To: <1476885181-3456-1-git-send-email-vkuznets@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=sthemmin@microsoft.com; x-originating-ip: [31.216.236.195] x-ms-office365-filtering-correlation-id: 0dc42c0c-2f88-4b91-e249-08d3f8c42b87 x-microsoft-exchange-diagnostics: 1;DM5PR03MB2491;7:HD5FJMR9ao79saqcQzMUWnzHTRxZ+97R2V6CPBR+Nn9ddoOQAD9x8C51X48RCsmplyjaEK7VORE2q/R1whSrfb24TmgTzu2p5DxFRYz7/Wi9w/dCANj0j4PCrbf87LGgdiScv/Q+DB6MFxXYizRfsMTSmK2O+90UhyYsetlSKLx5rQZ1JFaUHkAPuf4cJCiqUc+wpZ1GHFkGhyCUGTLlhzJssPjfk/ddBBorSZRrYTCC/rYeOOqxq9uPIApoN/2XSnC4cl+UrFMUIkKqz8GWvEr3zaLo69SoT94kTfExOSxdQNtkbmwmx4CfjBXLxDtRbgxZ+OIaY/9eHhgK7+kwDjZ1wtHzgCoO+RMeeg9YwMCfusq2yMF1J5DCfKDHQ2PK x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB2491; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(61426038)(61427038);SRVR:DM5PR03MB2491;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB2491; x-forefront-prvs: 01018CB5B3 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(189002)(57704003)(13464003)(199003)(377454003)(10290500002)(5005710100001)(10400500002)(19580395003)(8990500004)(19580405001)(97736004)(2900100001)(5001770100001)(189998001)(77096005)(6116002)(3846002)(107886002)(102836003)(5002640100001)(586003)(92566002)(9686002)(87936001)(8676002)(7846002)(86612001)(81156014)(74316002)(68736007)(2501003)(8936002)(86362001)(7736002)(305945005)(66066001)(81166006)(4001430100002)(106356001)(33656002)(5660300001)(106116001)(50986999)(2906002)(76176999)(54356999)(99286002)(2950100002)(10090500001)(105586002)(3660700001)(7696004)(4326007)(101416001)(3280700002)(122556002)(76576001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR03MB2491;H:BLUPR0301MB2098.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Oct 2016 08:36:21.3212 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2491 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id u9K9AMqY024089 Content-Length: 2120 Lines: 41 Do we need ACCESS_ONCE() here to avoid check/use issues? -----Original Message----- From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com] Sent: Wednesday, October 19, 2016 2:53 PM To: netdev@vger.kernel.org Cc: Stephen Hemminger ; devel@linuxdriverproject.org; linux-kernel@vger.kernel.org; KY Srinivasan ; Haiyang Zhang Subject: [PATCH net-next] hv_netvsc: fix a race between netvsc_send() and netvsc_init_buf() Fix in commit 880988348270 ("hv_netvsc: set nvdev link after populating chn_table") turns out to be incomplete. A crash in netvsc_get_next_send_section() is observed on mtu change when the device is under load. The race I identified is: if we get to netvsc_send() after we set net_device_ctx->nvdev link in netvsc_device_add() but before we finish netvsc_connect_vsp()->netvsc_init_buf() send_section_map is not allocated and we crash. Unfortunately we can't set net_device_ctx->nvdev link after the netvsc_init_buf() call as during the negotiation we need to receive packets and on the receive path we check for it. It would probably be possible to split nvdev into a pair of nvdev_in and nvdev_out links and check them accordingly in get_outbound_net_device()/ get_inbound_net_device() but this looks like an overkill. Check that send_section_map is allocated in netvsc_send(). Signed-off-by: Vitaly Kuznetsov --- drivers/net/hyperv/netvsc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 720b5fa..e2bfaac 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -888,6 +888,13 @@ int netvsc_send(struct hv_device *device, if (!net_device) return -ENODEV; + /* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get + * here before the negotiation with the host is finished and + * send_section_map may not be allocated yet. + */ + if (!net_device->send_section_map) + return -EAGAIN; + out_channel = net_device->chn_table[q_idx]; packet->send_buf_index = NETVSC_INVALID_INDEX; -- 2.7.4