From patchwork Mon Jan 8 23:51:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Hsu X-Patchwork-Id: 10150769 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FA0A601BE for ; Mon, 8 Jan 2018 23:51:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 113E228426 for ; Mon, 8 Jan 2018 23:51:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE0728A72; Mon, 8 Jan 2018 23:51:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDC2528426 for ; Mon, 8 Jan 2018 23:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933868AbeAHXvv (ORCPT ); Mon, 8 Jan 2018 18:51:51 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:48986 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932905AbeAHXvu (ORCPT ); Mon, 8 Jan 2018 18:51:50 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 640DD60BE7; Mon, 8 Jan 2018 23:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1515455510; bh=5xouhMxzXz2q/Ifv3CyJZ5p722/NJ0VwR8WeJb197wQ=; h=From:To:Cc:Subject:Date:From; b=n5qPWDcIdpBRGWOYD4fBv8HSJeO8bzVgqIS63xbH8SLdOh7wbL6NFEnn4J89t3Uhf zE8f6KEsMx3xzYsi7F7zm6ClIG7ahx4lzZTI75vw0oU/qkASfeh4HuznkGIycFGkZi CMJC/FVTb3UswBp/8tmwH0t/1MMfsj+L2hV0Dluo= Received: from ryanhsu-linux2.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ryanhsu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id AD1B760BDF; Mon, 8 Jan 2018 23:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1515455509; bh=5xouhMxzXz2q/Ifv3CyJZ5p722/NJ0VwR8WeJb197wQ=; h=From:To:Cc:Subject:Date:From; b=Bzb1OgTqRSVcE7QQjmwt1o9Ac28+wpT2un/yuu1QvtwaQs/WZ7iaoWxMk9eiNNrav imCATztk4SfVIV9hsHYJ3bBPctux9qu7TgbLtiUpSMtj7WKC5gy1AwuZ0HIrTWYlnS Pj37Fnw0KbC5X4MavH9RWsXwQeZoHtstjQfLM1fI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AD1B760BDF Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ryanhsu@codeaurora.org From: ryanhsu@codeaurora.org To: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org Cc: ryanhsu@codeaurora.org Subject: [PATCH] ath10k: add sanity check to ie_len before parsing fw/board ie Date: Mon, 8 Jan 2018 15:51:01 -0800 Message-Id: <1515455461-19286-1-git-send-email-ryanhsu@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ryan Hsu Validate ie_len after the alignment padding before access the buffer to avoid potential overflow. Signed-off-by: Ryan Hsu --- drivers/net/wireless/ath/ath10k/core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 51444d3..64713d1 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -1276,7 +1276,10 @@ static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, len -= sizeof(*hdr); data = hdr->data; - if (len < ALIGN(ie_len, 4)) { + /* jump over the padding */ + ie_len = ALIGN(ie_len, 4); + + if (len < ie_len) { ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n", ie_id, ie_len, len); ret = -EINVAL; @@ -1315,8 +1318,6 @@ static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, goto out; } - /* jump over the padding */ - ie_len = ALIGN(ie_len, 4); len -= ie_len; data += ie_len; @@ -1448,6 +1449,9 @@ int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name, len -= sizeof(*hdr); data += sizeof(*hdr); + /* jump over the padding */ + ie_len = ALIGN(ie_len, 4); + if (len < ie_len) { ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n", ie_id, len, ie_len); @@ -1553,9 +1557,6 @@ int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name, break; } - /* jump over the padding */ - ie_len = ALIGN(ie_len, 4); - len -= ie_len; data += ie_len; }