Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1121598pxx; Tue, 27 Oct 2020 08:44:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3q9BE1Tcga9vpsAJQoHn3edBLslG3cG1Ip1PWb0FyzSTWjJ5R1JkXs+qOO899I204RPof X-Received: by 2002:aa7:d582:: with SMTP id r2mr2799387edq.170.1603813481032; Tue, 27 Oct 2020 08:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603813481; cv=none; d=google.com; s=arc-20160816; b=ISmxcmB0qdhETGptsLh/CtJ2DYaTsArz/9SnZQRypsLBRPN7yoiJZNmHNn3M3SLq1K fAgZSIIKJYR4m1S88F17uTAiaTVauldnT+jP2kl5nrIiGhGs8KR5ShBvUEnWyRoLbwIp DBvLo3yqjxAEIvjpHyTnRS+pfl1aiTld2X8coP9FdyNaeb6fz7lNnENy5yPHbUuTixlT EcjS/h+bJOEbwlKxCYtLeF3wXVJhiQqq07VGrBsoAcsfj3J9Tkm4/xcIfBgLv/qSEtUd ejL6jj4cfLH7ZHjXqS/5tZgcdsDIvp2ZU1WLbppxrYRNlH4vX9Dz6xmlk9Kf9t6bxNaa vH4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6JBbf+J9sSz5bKzCHCPH78fvfXxbxVuHGqbmOA4zN+k=; b=b1f4AUjonQGiHFpTs4IDlyY7LKV8LyM2UZH2+KuLNl/kJI8Vd+VTL3o9D8pmWcuCGr YAqbdwhpA7Bag3vuJKLW6tkWcGgmAVUzq6/3LGXZdR49CJEKZbKnzvabonWPePM+GJwI pTcXJ/NZEIO4lPXujkMV5XPL9VaGCqlWHDZbnKsFxXQQWYTHL01oPzPcNxZkhUnAwjgm HWmAh341BczSntHhbZtQ0B5e3tmW3yVr+Jn+po++btHBQFHMeB2+qSdB+iEVTuFeaLIb etMTYCB1fHSvPI7MOTLoRkXRJvU2LYgBP3zHHqh5CLRHb/LJ2Y0ZfttET2L+4W+R9b+b oNsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iYGnaUTG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si1304256ejd.407.2020.10.27.08.44.18; Tue, 27 Oct 2020 08:44:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iYGnaUTG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763949AbgJ0OrA (ORCPT + 99 others); Tue, 27 Oct 2020 10:47:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:46834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1764524AbgJ0Oq4 (ORCPT ); Tue, 27 Oct 2020 10:46:56 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4C462225E; Tue, 27 Oct 2020 14:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810015; bh=a8CGfV1/BjFZ1fhJM2DyX1eMIpEyq3beSEbIQk/tMCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iYGnaUTGeiJa5Q4EaogsgZLb/KPkMbPT4S+mY8D8dGS0rYyVClhGZRiVWCU71AnOe 9tUQ8LH6Fxty//J6EZ/lY0XC9/uiBJHvLj4GFl70DlUOc+WqjqoHCA5UuWIwzzBQ+F ln7VSYvFNNHVjp2FlfacEJmCRJ/M6NmEtrmhrFik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zekun Shen , Kalle Valo , Sasha Levin Subject: [PATCH 5.4 399/408] ath10k: check idx validity in __ath10k_htt_rx_ring_fill_n() Date: Tue, 27 Oct 2020 14:55:37 +0100 Message-Id: <20201027135513.512494355@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zekun Shen [ Upstream commit bad60b8d1a7194df38fd7fe4b22f3f4dcf775099 ] The idx in __ath10k_htt_rx_ring_fill_n function lives in consistent dma region writable by the device. Malfunctional or malicious device could manipulate such idx to have a OOB write. Either by htt->rx_ring.netbufs_ring[idx] = skb; or by ath10k_htt_set_paddrs_ring(htt, paddr, idx); The idx can also be negative as it's signed, giving a large memory space to write to. It's possibly exploitable by corruptting a legit pointer with a skb pointer. And then fill skb with payload as rougue object. Part of the log here. Sometimes it appears as UAF when writing to a freed memory by chance. [ 15.594376] BUG: unable to handle page fault for address: ffff887f5c1804f0 [ 15.595483] #PF: supervisor write access in kernel mode [ 15.596250] #PF: error_code(0x0002) - not-present page [ 15.597013] PGD 0 P4D 0 [ 15.597395] Oops: 0002 [#1] SMP KASAN PTI [ 15.597967] CPU: 0 PID: 82 Comm: kworker/u2:2 Not tainted 5.6.0 #69 [ 15.598843] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014 [ 15.600438] Workqueue: ath10k_wq ath10k_core_register_work [ath10k_core] [ 15.601389] RIP: 0010:__ath10k_htt_rx_ring_fill_n (linux/drivers/net/wireless/ath/ath10k/htt_rx.c:173) ath10k_core Signed-off-by: Zekun Shen Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20200623221105.3486-1-bruceshenzk@gmail.com Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath10k/htt_rx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c index 9f0e7b4943ec6..8ca0a808a644d 100644 --- a/drivers/net/wireless/ath/ath10k/htt_rx.c +++ b/drivers/net/wireless/ath/ath10k/htt_rx.c @@ -142,6 +142,14 @@ static int __ath10k_htt_rx_ring_fill_n(struct ath10k_htt *htt, int num) BUILD_BUG_ON(HTT_RX_RING_FILL_LEVEL >= HTT_RX_RING_SIZE / 2); idx = __le32_to_cpu(*htt->rx_ring.alloc_idx.vaddr); + + if (idx < 0 || idx >= htt->rx_ring.size) { + ath10k_err(htt->ar, "rx ring index is not valid, firmware malfunctioning?\n"); + idx &= htt->rx_ring.size_mask; + ret = -ENOMEM; + goto fail; + } + while (num > 0) { skb = dev_alloc_skb(HTT_RX_BUF_SIZE + HTT_RX_DESC_ALIGN); if (!skb) { -- 2.25.1