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: 10134053 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 2250560318 for ; Wed, 27 Dec 2017 20:03:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11D992C77B for ; Wed, 27 Dec 2017 20:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0667E2C780; Wed, 27 Dec 2017 20:03:07 +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 96B782C77B for ; Wed, 27 Dec 2017 20:03:06 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=BvjStqL4ptO56ZynnzXu9meFXje9iTlb5CzyUzseaeI=; b=k9dx++rg3k46q4 zHYRBETi7dkGIXpRhxfH3sFwHdqqJvH8rXbETc+SJEzE5te//ihvJbCrDH67UfTA7H84I5Sxq6vXB k+h/j4kCG9Ru6DZ9YDE78LikfSV2of20Sx5ewZyUenxmm6rH3PJh6QVEIqExiBLLUdfq6lIay/DHX FhzNIFqJFKZzjoinqk5nxJZB3TsKAcmak/00HE0YZbZNrMkZC9OWvvHw3nbBbLv9nyycaQEMFUPNL WXBt5KglVmhlMoQ6YrChwTHfsND9hqNhOy1LGoJLCnce3HrzJQ28gqHZGtf7QZNb7Y9J1+3z7G4cD ZFojMXxZTcB3MYHTeIwg==; 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 1eUHuj-0000XP-7o; Wed, 27 Dec 2017 20:02:57 +0000 Received: from sabertooth01.qualcomm.com ([65.197.215.72]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eUHuf-0000V2-JD for ath10k@lists.infradead.org; Wed, 27 Dec 2017 20:02:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=qti.qualcomm.com; i=@qti.qualcomm.com; q=dns/txt; s=qcdkim; t=1514404973; x=1545940973; h=from:to:cc:subject:date:message-id:mime-version; bh=5H5L0/FM5ZjxtAJRFfCD1CV+bFxa0ZF5m2KRWoz5rXk=; b=ll8N8RmE1jRccBknCaR1LZM2M75sqh8F3bnqwQ1b4DiUm/U4qrAftAGS C45Rvf1bXXZw3h53MkQO90u35kJn7GmZdihKeMDL9ZgwTg8pBkaCG+u6M bLWiWsvGO+omofA8gbUN1zSNvR6iGHAKpDlVK2N4Jge9uGUo2L7ijEZyc c=; X-IronPort-AV: E=Sophos;i="5.45,467,1508828400"; d="scan'208";a="119684016" Received: from ironmsg02-r-new.qualcomm.com (HELO ironmsg02-R.qualcomm.com) ([10.53.140.106]) by sabertooth01.qualcomm.com with ESMTP; 27 Dec 2017 12:02:39 -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: , 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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171227_120253_682958_9DCA26C9 X-CRM114-Status: UNSURE ( 8.56 ) 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@qti.qualcomm.com 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 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; }