Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2062699ybi; Mon, 1 Jul 2019 05:33:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzheA9WIFb1YLya3hexnikCF9TrLK2VcYUjjgiDYRixftwZHIwL7E59QOhOBMHienhOELFw X-Received: by 2002:a17:90a:8d86:: with SMTP id d6mr2069930pjo.94.1561984438045; Mon, 01 Jul 2019 05:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561984438; cv=none; d=google.com; s=arc-20160816; b=j2aoxdd/7IKe0X4+4eX026SsFE0dpI5+T2eP20y86NIlbgCBN/QjUqnV5jor/vpKI8 nUDvY4uedKbEAQPoGRl13sflf+DHMcK+9vN3nn0nfJqAEhehJ54HugiIh53jEDNow561 4GoKmeJLXIZehGIkKLN2mSCXDFoqM69QDEAOeHYlF+6Ac2TsCQ6cU3civ9243d2C3jR8 /cTclV5ap8E21P7y/DlRMTdqnKX3w5rtTf6/YNdojXXFmfkHvsRzkCdrj4VHba14kA/q I/boU9f+8Cg8QtNTs9B4+BrZg6w+wXo6mL96LKkLGf3Mwbr5uNvfTtQjRHzCwz+W4yyc nD8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=8xeQ8Ouu97Qg8BegnrjEEygtfPvTpW6Qo6/jKRbo+sM=; b=Zka2hk+e6zfyEtl3uR9sVmWZHaOXuBzwI3WR3WxOsAxEesgi46JWSzr1jKXPhvre3d 5ICMLIO8j9JtASQSzg+HpBaRkp1NgUtPMpMOektf68K6qEjwTfJLH4Ba8+omcYNZM+by eMa1aOQ4v7R8UNRV1jPsYhf+P38O8rSZ9UpUBfwKwfD4I5/PrcZ0e7MLkuQiOVMZoAqD cxGA84w1MCNo6pLK51QAp2xkYO1Dhfu1QVSFhyNczQV7sDC74aJZYRiJWz45py3Ztm+v oNB8ENIIBuwGPTnURyDWq0fTQLxPNE70oi1Mwh50NFHin3y3V06c/QqgfaKewJCKF1ZC rDLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=LVfpJzyo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2si10099937pgo.463.2019.07.01.05.33.37; Mon, 01 Jul 2019 05:33:58 -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=@nbd.name header.s=20160729 header.b=LVfpJzyo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727979AbfGAL1h (ORCPT + 99 others); Mon, 1 Jul 2019 07:27:37 -0400 Received: from nbd.name ([46.4.11.11]:40242 "EHLO nbd.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbfGAL1h (ORCPT ); Mon, 1 Jul 2019 07:27:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8xeQ8Ouu97Qg8BegnrjEEygtfPvTpW6Qo6/jKRbo+sM=; b=LVfpJzyovRUV1R30IH63mbqg0u 65d/MuBzKcsiMYJl6PQ73a3Hyteg+afEV9mv2aN1gSfPdlE+1nnv6UaCYtvyCM2bM15eRuASdCs5s vHdwdlITFs+Unu/69ww9wGwzZ2uOEPoCdTe37pJ4jJQJUVS7VQYzAKRERlXP28TANUVA=; Received: from p54ae9425.dip0.t-ipconnect.de ([84.174.148.37] helo=maeck-3.local) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhuT9-00044o-Uu; Mon, 01 Jul 2019 13:27:36 +0200 Received: by maeck-3.local (Postfix, from userid 501) id 3D91260D3CE5; Mon, 1 Jul 2019 13:27:34 +0200 (CEST) From: Felix Fietkau To: linux-wireless@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH] mt76: round up length on mt76_wr_copy Date: Mon, 1 Jul 2019 13:27:34 +0200 Message-Id: <20190701112734.86552-1-nbd@nbd.name> X-Mailer: git-send-email 2.17.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org When beacon length is not a multiple of 4, the beacon could be sent with the last 1-3 bytes corrupted. The skb data is guaranteed to have enough room for reading beyond the end, because it is always followed by skb_shared_info, so rounding up is safe. All other callers of mt76_wr_copy have multiple-of-4 length already. Cc: stable@vger.kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mmio.c | 2 +- drivers/net/wireless/mediatek/mt76/usb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mmio.c b/drivers/net/wireless/mediatek/mt76/mmio.c index 38368d19aa6f..83c96a47914f 100644 --- a/drivers/net/wireless/mediatek/mt76/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mmio.c @@ -43,7 +43,7 @@ static u32 mt76_mmio_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val) static void mt76_mmio_copy(struct mt76_dev *dev, u32 offset, const void *data, int len) { - __iowrite32_copy(dev->mmio.regs + offset, data, len >> 2); + __iowrite32_copy(dev->mmio.regs + offset, data, DIV_ROUND_UP(len, 4)); } static int mt76_mmio_wr_rp(struct mt76_dev *dev, u32 base, diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 61b27f3ec6e4..87ecbe290f99 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -164,7 +164,7 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, int i, ret; mutex_lock(&usb->usb_ctrl_mtx); - for (i = 0; i < (len / 4); i++) { + for (i = 0; i < DIV_ROUND_UP(len, 4); i++) { put_unaligned_le32(val[i], usb->data); ret = __mt76u_vendor_request(dev, MT_VEND_MULTI_WRITE, USB_DIR_OUT | USB_TYPE_VENDOR, -- 2.17.0