Received: by 10.223.185.116 with SMTP id b49csp6399959wrg; Wed, 28 Feb 2018 08:47:17 -0800 (PST) X-Google-Smtp-Source: AH8x2259kzMhw2VYccx3OPG03rt1gAbY9IUperAsoOQYY7jzCq0OCgt6pw72X7PQZmYx/Kli68Z8 X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr18390704plk.18.1519836437777; Wed, 28 Feb 2018 08:47:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519836437; cv=none; d=google.com; s=arc-20160816; b=dZ/i3vlzD42YfyVtB4F7PakQ8hk6JPWQOR0yCt0QbZhBkih+LTx1Scq1OFoYERVM0k UcqUKvyKuJ+8Jm2RVVAdEWyPIbT9pe+N9Iz2AqnnAoJ/WParL9eRHVFLWSyCLq+AGseD tSYLUyt6qi1aYp/YmHplfN9Hd7NeCJLzduaQfRoA+RvvdTcodMslSFtYLy09qBtJK55Y RbHm1r5Ys196IB3XLxvbVfVrykNcH2gQ2ke/BZ/fcjsJR3r1McMM5hYiXT0NKbOzDjwu qQ3VVSU3UPn7SaiYDxP6tTIAq1Nd6Vf6VKHsDT0/3QFuJZu+ogHupZmlp5okU9dKXJwP nXvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=PEgN0OSaYEldb0uk+zHrHiUFiilw05Zv7Pf0Frnz+pw=; b=oSoVjELF/6FrQUP3LYoRbbShbpVOelYHJTrDrj22SqKiaUNkBrCAglVyVKDDKWhK92 TEAo/pnSllNZQbiqkBFOK+qBfVGUYatHrLm/CtFXpdPyZmBzL87Al9bAvFd/VyT0er7P gKiXHF5h74bD1sFKoGFL/v53iL72ZMDEd4HD7bpz9VD/eKtoYSTTDf9ARgU1jTEF4mdE yo79G/8ezNoA89HsYDuN6Z0XbrJhvmLB7IXt6kQUiHQPrd3M023dCgfTN8v+fmLHQjDT nZtx3Zp9cwecMH4H5GiJs09zi5QQpUCzzzPjzVttT4X6oMtQ+kFupaNYOvuLHx2FLK7O fT4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b65si1480009pfk.283.2018.02.28.08.47.02; Wed, 28 Feb 2018 08:47:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753030AbeB1QAL (ORCPT + 99 others); Wed, 28 Feb 2018 11:00:11 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34635 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbeB1QAH (ORCPT ); Wed, 28 Feb 2018 11:00:07 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yg-0006Xl-PO; Wed, 28 Feb 2018 15:22:19 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yf-0008Tn-Cd; Wed, 28 Feb 2018 15:22:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Richard Fitzgerald" , "Mark Brown" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 079/254] ASoC: wm_adsp: Don't overrun firmware file buffer when reading region data In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Richard Fitzgerald commit 1cab2a84f470e15ecc8e5143bfe9398c6e888032 upstream. Protect against corrupt firmware files by ensuring that the length we get for the data in a region actually lies within the available firmware file data buffer. Signed-off-by: Richard Fitzgerald Signed-off-by: Mark Brown Signed-off-by: Ben Hutchings --- sound/soc/codecs/wm_adsp.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -532,7 +532,7 @@ static int wm_adsp_load(struct wm_adsp * const struct wmfw_region *region; const struct wm_adsp_region *mem; const char *region_name; - char *file, *text; + char *file, *text = NULL; struct wm_adsp_buf *buf; unsigned int reg; int regions = 0; @@ -677,10 +677,21 @@ static int wm_adsp_load(struct wm_adsp * regions, le32_to_cpu(region->len), offset, region_name); + if ((pos + le32_to_cpu(region->len) + sizeof(*region)) > + firmware->size) { + adsp_err(dsp, + "%s.%d: %s region len %d bytes exceeds file length %zu\n", + file, regions, region_name, + le32_to_cpu(region->len), firmware->size); + ret = -EINVAL; + goto out_fw; + } + if (text) { memcpy(text, region->data, le32_to_cpu(region->len)); adsp_info(dsp, "%s: %s\n", file, text); kfree(text); + text = NULL; } if (reg) { @@ -737,6 +748,7 @@ out_fw: regmap_async_complete(regmap); wm_adsp_buf_free(&buf_list); release_firmware(firmware); + kfree(text); out: kfree(file); @@ -1316,6 +1328,17 @@ static int wm_adsp_load_coeff(struct wm_ } if (reg) { + if ((pos + le32_to_cpu(blk->len) + sizeof(*blk)) > + firmware->size) { + adsp_err(dsp, + "%s.%d: %s region len %d bytes exceeds file length %zu\n", + file, blocks, region_name, + le32_to_cpu(blk->len), + firmware->size); + ret = -EINVAL; + goto out_fw; + } + buf = wm_adsp_buf_alloc(blk->data, le32_to_cpu(blk->len), &buf_list);