Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5997158ybc; Wed, 27 Nov 2019 13:07:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwWfH/R/m51XqNBM1mHOhHgW5twFvTkx3ccLEK2DePlTiagjAs4Z51ywWtt+hwaBb4FUc6n X-Received: by 2002:a50:fa87:: with SMTP id w7mr9932193edr.0.1574888861676; Wed, 27 Nov 2019 13:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888861; cv=none; d=google.com; s=arc-20160816; b=uxdRIS/k8PUv6MGk+nCw+wkXUHwFWVhbYSsBbk28S3YIpbe0Gxfw80SPBsU6nnA+Tv NvWUwRayFE8i8JgSK+sxbsyEx2Nxk2xljR1n1LyxU/sITkJup294BWtjj3QwWFtmdVs7 tsfk9mJtSBpMSUQt4YDAcJLeS5hLDoQk5RrI3OqZbamXN2RaFr0zEJ9E7Gs7rKL5oFHh tGiiUkc4vwPcYAlbOekoXxlURuHALYApUors9Vv7y6HoM8h7Ju37GQfyD5quzDEwarLZ QhuEQjZQ6lrnnMWQzrW4SJtw/h8QxEUxxefrE6p8BnqlfnhVPRJIkTyDOcJbbfvfLoof x83w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iXOVFWgbumv9sFXDPT+E6emfwLEHneDJXWHi2ZzqgNM=; b=mjOlRcWlGQp/+WDpOnPojVeCSO4bB3ImUN/gihjS9/mnY3T6b875zGGFRSoNPfC4A3 11y4G1GT0jl1rwAPn03wjD4FS8yifZnSqeMBX4A1iHH8lENju4mafPMmAFOsYgojWgAe l22Kdr+BvrywoA5MZH6e+3q1h9tBEzIi7gvXoQ1WuOWvgcIxd3krOHlSJ6Wsan9RQI7w vSoK7bgUr1N2bm45a16YIUwwCFUf6+Ipqc8r+B9DZApFWJybMesnzEoAMg19VONFkM2c mZfTxJfkyLDHD3M0VI6SQMsDRZDSN4z7vJjcaP6LFK93QdqsqFE02IfyoMKPCoK7e/JU YNDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FIRmcfJK; 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 j20si1112214edj.385.2019.11.27.13.07.17; Wed, 27 Nov 2019 13:07:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b=FIRmcfJK; 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 S1732078AbfK0VGC (ORCPT + 99 others); Wed, 27 Nov 2019 16:06:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:59870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727440AbfK0VGA (ORCPT ); Wed, 27 Nov 2019 16:06:00 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 5FF4321739; Wed, 27 Nov 2019 21:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888758; bh=6i2FWlUyBqXoa8E7ahltUpGIlhQC73J1ohUesZ3vAhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIRmcfJKccONqBQK6UnSVEjsiKTljBi8jiMP6p8SBMAED4R9WGs6fBax8ZY598vdz QEkgBHCbvWeNz1LgcnsVQjZa+KTffIHJxVZScT7E9zeZxcnk1/18C0p4gKFYczFxAw oM8+HHNkYrlEMHmvzcA9c5fedO5uJwfVpClar3pc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hui Peng , Mathias Payer , Guenter Roeck , Kalle Valo Subject: [PATCH 4.19 258/306] ath10k: Fix a NULL-ptr-deref bug in ath10k_usb_alloc_urb_from_pipe Date: Wed, 27 Nov 2019 21:31:48 +0100 Message-Id: <20191127203133.694638336@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hui Peng commit bfd6e6e6c5d2ee43a3d9902b36e01fc7527ebb27 upstream. The `ar_usb` field of `ath10k_usb_pipe_usb_pipe` objects are initialized to point to the containing `ath10k_usb` object according to endpoint descriptors read from the device side, as shown below in `ath10k_usb_setup_pipe_resources`: for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; // get the address from endpoint descriptor pipe_num = ath10k_usb_get_logical_pipe_num(ar_usb, endpoint->bEndpointAddress, &urbcount); ...... // select the pipe object pipe = &ar_usb->pipes[pipe_num]; // initialize the ar_usb field pipe->ar_usb = ar_usb; } The driver assumes that the addresses reported in endpoint descriptors from device side to be complete. If a device is malicious and does not report complete addresses, it may trigger NULL-ptr-deref `ath10k_usb_alloc_urb_from_pipe` and `ath10k_usb_free_urb_to_pipe`. This patch fixes the bug by preventing potential NULL-ptr-deref. Signed-off-by: Hui Peng Reported-by: Hui Peng Reported-by: Mathias Payer Reviewed-by: Greg Kroah-Hartman [groeck: Add driver tag to subject, fix build warning] Signed-off-by: Guenter Roeck Signed-off-by: Kalle Valo Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/ath/ath10k/usb.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/net/wireless/ath/ath10k/usb.c +++ b/drivers/net/wireless/ath/ath10k/usb.c @@ -49,6 +49,10 @@ ath10k_usb_alloc_urb_from_pipe(struct at struct ath10k_urb_context *urb_context = NULL; unsigned long flags; + /* bail if this pipe is not initialized */ + if (!pipe->ar_usb) + return NULL; + spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags); if (!list_empty(&pipe->urb_list_head)) { urb_context = list_first_entry(&pipe->urb_list_head, @@ -66,6 +70,10 @@ static void ath10k_usb_free_urb_to_pipe( { unsigned long flags; + /* bail if this pipe is not initialized */ + if (!pipe->ar_usb) + return; + spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags); pipe->urb_cnt++;