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: 10150771 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 EC9F4601BE for ; Mon, 8 Jan 2018 23:52:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E04E728584 for ; Mon, 8 Jan 2018 23:52:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEE5B287DC; Mon, 8 Jan 2018 23:52:15 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5829A28584 for ; Mon, 8 Jan 2018 23:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=4a8ZDKCdBCf1W4ne8ebUSs16ClcUwAsq2ne1cHTRL24=; b=LPx uFWL296+gh1D4PDThZa8OdngWKEAnwBmnHJZAquwdYSEy9mywtE5I1BEb1GKmiu8viKnoR5GxFK9T HQCkO0ef4i/EtwwwxCFvq3/Z2mvZFAs/GzBtFKH+05KOCVSEczhBqIFhCnY5vUGaey3egvNjFraZG GU2Ro2KnlJ3WbhdWN5cXdanywqArs5dHiSJQa/JBlJsGsMj3fPs69f6O1ARZtx28UB35sa3n0mIF1 g0HWskuaCwgrrNOasOAf3LFzo4bjYLm9fH+3/rowK/DoMCeOZ/97FmOA1oHkH4L0HKBe+Kdgj6oxM pEli/OdSJOFO9y+xSTTbNPG9bIUtboQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eYhD2-0004I9-JT; Mon, 08 Jan 2018 23:52:04 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYhCz-0004H0-D6 for ath10k@lists.infradead.org; Mon, 08 Jan 2018 23:52:02 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4377C60BE6; 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180108_155201_478495_B6BF6E04 X-CRM114-Status: UNSURE ( 9.74 ) X-CRM114-Notice: Please train this message. X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ryanhsu@codeaurora.org MIME-Version: 1.0 Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.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; }