Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4998963ybl; Mon, 26 Aug 2019 20:34:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4I4d0v2HdDHCb9VrFnQz7usKsYgL5V4I7cQ52ij7uXmF0/H9naWPePcxLrRjoGg79x5hJ X-Received: by 2002:a17:902:23:: with SMTP id 32mr22540375pla.214.1566876896711; Mon, 26 Aug 2019 20:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566876896; cv=none; d=google.com; s=arc-20160816; b=YviLV4SO3EOq+TVrFqnDuc5oZjTZu00yQERgek+VJ2K978psa1LQc9MX5Zn+Hm09Ld l/MGKe1QLHgpGcaR1N631rf4h1Fibx+5/wU1reD2ykRg0p8z0oCOgumrLyk+8gXyFLVt fgkLUZ9UW2lByI0JvH0ou/1V+kKFXRyjtH0kV3kgR2FWQaMlvEwtZRbui9Ot0bvzYZH9 5Q1Lvb4iItbVHj9VASORpDX0XzrpRhgiF0rzjM5mdtWgsNnEsCRRNVwqcvIjPWGyCt97 tjLL9TYY8a0jzX5kvsi86j9aUNUoUZokpETCcYmHOjEnyrVD7h/itsnVsezx/p7JIwa7 nhBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:cc:to:from:thread-topic:subject:dkim-signature; bh=KiYWImY/tVdWIHDGrgqbu03AOE0QPwmep7zO9hZ7UCQ=; b=hICqoHJSrBthD6iC1Ie++tlr3EauEZ3l6PCCuXEOixRh9G+ybhaen7sD+1zGj1QcAF dHGTFhOLkJLfvYaEs2aAtv3J4FF2F60a/iFf/aPhJ1U4QpkK+VYv45CW/xmHF8ag41Wi LTIFOXPfRPrgbs/bT5V4Mxl2Z7wUkPMG1VkQZeB3asfUMITcNZGQ6jaZ75UtR/RbSCWQ 63E+KOI71sPMJa1unuomWnPx9CthsJaH9G+F5L60DpXRW/1BpenDD991QuX0awmqF4IN MCZgUQkjkcu9quVeHqOfLgkLv0zJ4GCaTENK5LkWeE6CEXRbHO7mqYtVgkJKHeskAxpt e/+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@qti.qualcomm.com header.s=qcdkim header.b=H1LVoR3y; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=qti.qualcomm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19si12253469pfi.248.2019.08.26.20.34.29; Mon, 26 Aug 2019 20:34:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@qti.qualcomm.com header.s=qcdkim header.b=H1LVoR3y; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=qti.qualcomm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729009AbfH0DeL (ORCPT + 99 others); Mon, 26 Aug 2019 23:34:11 -0400 Received: from alexa-out-tai-01.qualcomm.com ([103.229.16.226]:11520 "EHLO alexa-out-tai-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728025AbfH0DeL (ORCPT ); Mon, 26 Aug 2019 23:34:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1566876849; x=1598412849; h=from:to:cc:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version:subject; bh=HueO28Mo5THvdok84YE2yPuCzBaX4zbwcSWbNLlZqUI=; b=H1LVoR3y8wo6hgALSi7YazTFtgEjRDbOttRQhfsHHW2gRDef72ycTZ+K ip0QswHM7heApBF8Cvc3cuSXy9yQGYS8F4KwqlHbvQgPd8qW1wsXGJY/j 7qsIACb3CymVbVIXoB+BOKlJo6r0kQPwfhX5RVlQEef6Vv2GKPZvEXrEp Y=; Subject: RE: [PATCH, RFC] ath10k: Fix skb->len (properly) in ath10k_sdio_mbox_rx_packet Thread-Topic: [PATCH, RFC] ath10k: Fix skb->len (properly) in ath10k_sdio_mbox_rx_packet Received: from ironmsg03-tai.qualcomm.com ([10.249.140.8]) by alexa-out-tai-01.qualcomm.com with ESMTP; 27 Aug 2019 11:34:07 +0800 Received: from aptaiexm02e.ap.qualcomm.com ([10.249.150.15]) by ironmsg03-tai.qualcomm.com with ESMTP/TLS/AES256-SHA; 27 Aug 2019 11:33:54 +0800 Received: from aptaiexm02f.ap.qualcomm.com (10.249.150.16) by aptaiexm02e.ap.qualcomm.com (10.249.150.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 27 Aug 2019 11:33:52 +0800 Received: from aptaiexm02f.ap.qualcomm.com ([fe80::4152:1436:e436:faa1]) by aptaiexm02f.ap.qualcomm.com ([fe80::4152:1436:e436:faa1%19]) with mapi id 15.00.1473.005; Tue, 27 Aug 2019 11:33:52 +0800 From: Wen Gong To: Nicolas Boichat , "kvalo@codeaurora.org" CC: Alagu Sankar , "netdev@vger.kernel.org" , "briannorris@chromium.org" , "linux-wireless@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "ath10k@lists.infradead.org" , "wgong@codeaurora.org" , "niklas.cassel@linaro.org" , "tientzu@chromium.org" , "David S . Miller" Thread-Index: AQHVXG89wIhJ11LRtUm/dwetQaAonKcOT+iw Date: Tue, 27 Aug 2019 03:33:52 +0000 Message-ID: <36878f3488f047978038c844daedd02f@aptaiexm02f.ap.qualcomm.com> References: <20190827003326.147452-1-drinkcat@chromium.org> In-Reply-To: <20190827003326.147452-1-drinkcat@chromium.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.249.136.10] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org > -----Original Message----- > From: ath10k On Behalf Of Nicolas > Boichat > Sent: Tuesday, August 27, 2019 8:33 AM > To: kvalo@codeaurora.org > Cc: Alagu Sankar ; netdev@vger.kernel.org; > briannorris@chromium.org; linux-wireless@vger.kernel.org; linux- > kernel@vger.kernel.org; ath10k@lists.infradead.org; > wgong@codeaurora.org; niklas.cassel@linaro.org; tientzu@chromium.org; > David S . Miller > Subject: [EXT] [PATCH, RFC] ath10k: Fix skb->len (properly) in > ath10k_sdio_mbox_rx_packet >=20 > (not a formal patch, take this as a bug report for now, I can clean > up depending on the feedback I get here) >=20 > There's at least 3 issues here, and the patch fixes 2/3 only, I'm not sur= e > how/if 1 should be handled. > 1. ath10k_sdio_mbox_rx_alloc allocating skb of a incorrect size (too > small) > 2. ath10k_sdio_mbox_rx_packet calling skb_put with that incorrect size. > 3. ath10k_sdio_mbox_rx_process_packet attempts to fixup the size, but > does not use proper skb_put commands to do so, so we end up with > a mismatch between skb->head + skb->tail and skb->data + skb->len. >=20 > Let's start with 3, this is quite serious as this and causes corruptions > in the TCP stack, as the stack tries to coalesce packets, and relies on > skb->tail being correct (that is, skb_tail_pointer must point to the > first byte _after_ the data): one must never manipulate skb->len > directly. >=20 > Instead, we need to use skb_put to allocate more space (which updates > skb->len and skb->tail). But it seems odd to do that in > ath10k_sdio_mbox_rx_process_packet, so I move the code to > ath10k_sdio_mbox_rx_packet (point 2 above). >=20 > However, there is still something strange (point 1 above), why is > ath10k_sdio_mbox_rx_alloc allocating packets of the incorrect > (too small?) size? What happens if the packet is bigger than alloc_len? > Does this lead to corruption/lost data? >=20 > Fixes: 8530b4e7b22bc3b ("ath10k: sdio: set skb len for all rx packets") > Signed-off-by: Nicolas Boichat >=20 > --- >=20 > One simple way to test this is this scriplet, that sends a lot of > small packets over SSH: > (for i in `seq 1 300`; do echo $i; sleep 0.1; done) | ssh $IP cat >=20 > In my testing it rarely ever reach 300 without failure. >=20 > drivers/net/wireless/ath/ath10k/sdio.c | 18 ++++++++++++------ > 1 file changed, 12 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/net/wireless/ath/ath10k/sdio.c > b/drivers/net/wireless/ath/ath10k/sdio.c > index 8ed4fbd8d6c3888..a9f5002863ee7bb 100644 > --- a/drivers/net/wireless/ath/ath10k/sdio.c > +++ b/drivers/net/wireless/ath/ath10k/sdio.c > @@ -381,16 +381,14 @@ static int > ath10k_sdio_mbox_rx_process_packet(struct ath10k *ar, > struct ath10k_htc_hdr *htc_hdr =3D (struct ath10k_htc_hdr *)skb->data; > bool trailer_present =3D htc_hdr->flags & > ATH10K_HTC_FLAG_TRAILER_PRESENT; > enum ath10k_htc_ep_id eid; > - u16 payload_len; > u8 *trailer; > int ret; >=20 > - payload_len =3D le16_to_cpu(htc_hdr->len); > - skb->len =3D payload_len + sizeof(struct ath10k_htc_hdr); > + /* TODO: Remove this? */ If the pkt->act_len has set again in ath10k_sdio_mbox_rx_packet, seems not = needed. > + WARN_ON(skb->len !=3D le16_to_cpu(htc_hdr->len) + sizeof(*htc_hdr)); >=20 > if (trailer_present) { > - trailer =3D skb->data + sizeof(*htc_hdr) + > - payload_len - htc_hdr->trailer_len; > + trailer =3D skb->data + skb->len - htc_hdr->trailer_len; >=20 > eid =3D pipe_id_to_eid(htc_hdr->eid); >=20 > @@ -637,8 +635,16 @@ static int ath10k_sdio_mbox_rx_packet(struct > ath10k *ar, > ret =3D ath10k_sdio_readsb(ar, ar_sdio->mbox_info.htc_addr, > skb->data, pkt->alloc_len); > pkt->status =3D ret; > - if (!ret) > + if (!ret) { > + /* Update actual length. */ > + /* FIXME: This looks quite wrong, why is pkt->act_len not > + * correct in the first place? > + */ Firmware will do bundle for rx packet, and the aligned length by block size= (256) of each packet's len is same=20 in a bundle. Eg.=20 packet 1 len: 300, aligned length:512 packet 2 len: 400, aligned length:512 packet 3 len: 200, aligned length:256 packet 4 len: 100, aligned length:256 packet 5 len: 700, aligned length:768 packet 6 len: 600, aligned length:768 then packet 1,2 will in bundle 1, packet 3,4 in a bundle 2, packet 5,6 in a= bundle 3. For bundle 1, packet 1,2 will both allocate with len 512, and act_len is 30= 0 first, then packet 2's len will be overwrite to 400. For bundle 2, packet 3,4 will both allocate with len 256, and act_len is 20= 0 first, then packet 4's len will be overwrite to 100. For bundle 3, packet 5,6 will both allocate with len 768, and act_len is 70= 0 first, then packet 6's len will be overwrite to 600. > + struct ath10k_htc_hdr *htc_hdr =3D > + (struct ath10k_htc_hdr *)skb->data; > + pkt->act_len =3D le16_to_cpu(htc_hdr->len) + sizeof(*htc_hdr); > skb_put(skb, pkt->act_len); > + } >=20 > return ret; > } > -- > 2.23.0.187.g17f5b7556c-goog >=20 >=20 > _______________________________________________ > ath10k mailing list > ath10k@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/ath10k