From patchwork Wed Dec 27 20:02:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ryanhsu@qti.qualcomm.com X-Patchwork-Id: 10134051 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 6374F60318 for ; Wed, 27 Dec 2017 20:02:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 537042C77B for ; Wed, 27 Dec 2017 20:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 485CB2C780; Wed, 27 Dec 2017 20:02:44 +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 C82002C77B for ; Wed, 27 Dec 2017 20:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752455AbdL0UCm (ORCPT ); Wed, 27 Dec 2017 15:02:42 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:13467 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751871AbdL0UCl (ORCPT ); Wed, 27 Dec 2017 15:02:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1514404961; x=1545940961; h=from:to:cc:subject:date:message-id:mime-version; bh=5H5L0/FM5ZjxtAJRFfCD1CV+bFxa0ZF5m2KRWoz5rXk=; b=FH9Oj5VB/6jM+5K0J91l48TbOPWyXMk+Boo/zvJD7RWRN9To13tkYSTs oj4pMZP8/fWjrubBJh9kD4VNcBM85VuU3kbsGvSUweb2wTLtdtQdiyzj0 P40HLrFRoB5JAlS4zDDQs04C4/s6ZFdtbWbivTP+HV31/eF6hCcC4ldo/ g=; Received: from ironmsg02-r-new.qualcomm.com (HELO ironmsg02-R.qualcomm.com) ([10.53.140.106]) by alexa-out.qualcomm.com with ESMTP; 27 Dec 2017 12:02:40 -0800 X-IronPort-AV: E=McAfee;i="5900,7806,8757"; a="1094741596" X-MGA-submission: =?us-ascii?q?MDHiLJBvkaHHUMuDlSwyyOpHw2gTF3McbUwIo0?= =?us-ascii?q?yWGXp0UGzcmq5SbUEoqo7VJdChHfxWRqR8jbNMr99Bt53tvKUKTLFp72?= =?us-ascii?q?jEtaxvXyjJpHIimnHgkEJ2gYKFzEo9+9aGICypJymO799Oe35Hk5hfE5?= =?us-ascii?q?sN?= Received: from nasanexm01g.na.qualcomm.com ([10.85.0.33]) by ironmsg02-R.qualcomm.com with ESMTP/TLS/AES256-SHA; 27 Dec 2017 12:02:39 -0800 Received: from ryanhsu-linux2.qualcomm.com (10.80.80.8) by NASANEXM01G.na.qualcomm.com (10.85.0.33) with Microsoft SMTP Server (TLS) id 15.0.1293.2; Wed, 27 Dec 2017 12:02:39 -0800 From: To: , CC: Subject: [PATCH] ath10k: add sanity check to ie_len before parsing fw/board ie Date: Wed, 27 Dec 2017 12:02:11 -0800 Message-ID: <1514404931-9078-1-git-send-email-ryanhsu@qti.qualcomm.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: NASANEXM01E.na.qualcomm.com (10.85.0.31) To NASANEXM01G.na.qualcomm.com (10.85.0.33) 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 042175a..2f24c17 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -1240,7 +1240,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; @@ -1279,8 +1282,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; @@ -1412,6 +1413,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); @@ -1517,9 +1521,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; }