From patchwork Fri Sep 21 20:42:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 10610975 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-2.web.codeaurora.org (Postfix) with ESMTP id 7301B112B for ; Fri, 21 Sep 2018 20:42:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EC832E7C7 for ; Fri, 21 Sep 2018 20:42:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50FF42E7CC; Fri, 21 Sep 2018 20:42:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 040342E7C7 for ; Fri, 21 Sep 2018 20:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391465AbeIVCd2 (ORCPT ); Fri, 21 Sep 2018 22:33:28 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46954 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391321AbeIVCd2 (ORCPT ); Fri, 21 Sep 2018 22:33:28 -0400 Received: by mail-pl1-f194.google.com with SMTP id t20-v6so3005783ply.13 for ; Fri, 21 Sep 2018 13:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lnUnqCIZWKqsR6b+s8TNA2V60rotZRso+B0fzWMs/bc=; b=G4N/YAp7PzkxC4xw8GTnl/wd67zi1we7Z0vGboZW6HyCQR6SYn6UEGPzUWz0W6pAdU 1/mT71pvigbmmz1hMwYk0FxaWQiJBRIuxYA9aIN0zITP7cpfaxoYP13Xdfj1i+ss19b4 w9ZEWoFdZDsFTx15YYY4limNQByp9pifP8fZA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lnUnqCIZWKqsR6b+s8TNA2V60rotZRso+B0fzWMs/bc=; b=h8Gagpcxj+eh6klxcLAnTWFgblmBtRGG/PfGiJ5mXJ7hpnaWCx1yM0YwPxh3Zge0q+ JAcWg5OVEWrPRNLExamS/ejYUM7FGTSzmvJ2nkjFRnjK7+yuB3JzC6G2TFeI4E9OBYlp WU6xITtGHtAMd2U/jlxiUFp7UV/ELiZKtvjUaMejrrmFRVMNyMOnGOvYGFgV67bowrXz tFy0gqK6+EdXwOG0cvkJcZbORbrSWD3bjzYSaOEmnRTcn2yU0FnrZCfl8gLjkVw9eJfc lrwDFzs14L3axAT/+H8lljevIKdqIihu6RhwAjvPkTl178RCKyvOYNoFXhJk/MXpgxVQ WIlQ== X-Gm-Message-State: APzg51BJqXG2I2ZQT49c/feH5CeTl0bFbdghR3t/viDd8Ze7zLEKM+hH nHJpJisOzqbxIF/fKQXzXuqiDA== X-Google-Smtp-Source: ANB0VdZ7G/cYibGDAnPnqRAqlUX4/MPsaPmWCKEXeP9dINu5rp8VOAxGMniFGEpsZ8K6mNGF3vuOtA== X-Received: by 2002:a17:902:b905:: with SMTP id bf5-v6mr9356308plb.185.1537562574626; Fri, 21 Sep 2018 13:42:54 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id h85-v6sm43682646pfk.71.2018.09.21.13.42.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 13:42:53 -0700 (PDT) From: Brian Norris To: Kalle Valo Cc: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, Carl Huang , Brian Norris Subject: [PATCH] ath10k: add missing sanity check on diag download Date: Fri, 21 Sep 2018 13:42:41 -0700 Message-Id: <20180921204241.34316-1-briannorris@chromium.org> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-goog MIME-Version: 1.0 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 ath10k_hw_diag_fast_download() generally has good boundary checking, but it misses verifying that the next metadata header actually fits in the remaining buffer space. Add such a check. Fixes: 39501ea64116 ("ath10k: download firmware via diag Copy Engine for QCA6174 and QCA9377.") Signed-off-by: Brian Norris --- drivers/net/wireless/ath/ath10k/hw.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/ath/ath10k/hw.c b/drivers/net/wireless/ath/ath10k/hw.c index 2c2870e3e84d..af8ae8117c62 100644 --- a/drivers/net/wireless/ath/ath10k/hw.c +++ b/drivers/net/wireless/ath/ath10k/hw.c @@ -1044,6 +1044,12 @@ int ath10k_hw_diag_fast_download(struct ath10k *ar, left = length - sizeof(*hdr); while (left > 0) { + if (left < sizeof(*metadata)) { + ath10k_warn(ar, "firmware segment is truncated: %d\n", + left); + ret = -EINVAL; + break; + } base_addr = __le32_to_cpu(metadata->addr); base_len = __le32_to_cpu(metadata->length); buf = metadata->data;