Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6004127ybc; Wed, 27 Nov 2019 13:14:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwCHjXuB2N1n8fCHtK9HOCPfvQuK2Cawvjd1lV1EzU+0RtWomLnoi4SMGLuPREHKABs7Mg6 X-Received: by 2002:a50:d648:: with SMTP id c8mr4355241edj.20.1574889262405; Wed, 27 Nov 2019 13:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889262; cv=none; d=google.com; s=arc-20160816; b=YPRW3WL/MwzohfQLbyOTZoT8AYe67ZFfQV2IsqYOvqH9IQR3j577vSuFQCQPabWwjd 9rbNjzEreG0zP1O/MwgUZ0Q5G0gnRq2HDrIk0Q15kEKUKRanuQsbpFQPEg9k6cqXmE6H Rr31XCoF7+maTVlZOuueSv3pGaPKdte+/EYlLUJZncIU7PmKoxkwjZYjAxbbZQ0m1R2E IFcmWrAj/3298QaQDdwvC3dYrnjCxFyRgtM9rsERMJ6CKH1ENe/AjRhYZ9H2+1vcM7Fb +kaObbvO5FVTg/+laH9jUcR/9+A7+EGWCTs9hcdOGWr/gz5cvHTGAAX5R6rCQmANCEYQ Aaqg== 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=Y7kWkBQonAtP5PnJGnWC2JWk1kxazRE8eM/oSZwgK6Y=; b=HZf00R5jUYtk6OswOqViUAgYVOu+bDY8yPRpw4Z7WI8mXQ/jPIcZS7eQ6wKOrp5PFY qxw+XWvIqcabgsy0Qc0ZCzozmtmjL8UaMAJVt8Q+qSmygmRWDGjilO2u0f92NgVFW3IE 3x8hQBTxhAKB4TEDzWGJkW2FEUcw3VAk/ZVei5WrmpjkcI+PPZTpwiuokTevtNhuPbY6 inr7AzA+6RzbR310vjt7VLDD3FJjzb1wN2UxbfHqwaJWhdHcSXnXoRmKSvfJPsrlkoIl KGYVrjNB8QV/ZXd7f1HlTSwVODs0Nq0/DVzaEq6EeW5mlMLO89l+oiVkBVQo1+Q7iS5i xRtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CujEas5b; 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 a18si10288483ejj.100.2019.11.27.13.13.59; Wed, 27 Nov 2019 13:14:22 -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=CujEas5b; 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 S1732404AbfK0VJv (ORCPT + 99 others); Wed, 27 Nov 2019 16:09:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:36640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732932AbfK0VJt (ORCPT ); Wed, 27 Nov 2019 16:09:49 -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 0F44D2154A; Wed, 27 Nov 2019 21:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888988; bh=u1csPlVEfQUnMjHvNXx4OmNGhAz9+OVPfxVfdGG03Hw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CujEas5bHANZktUexxTr307KvXe5PNeAL272XrUKOEQAEioNry1DPWBTJf5/p241u gioZ/1mrZu/e1kdzzyKbhqP7y4JY3yIOhD0Yqrv37ONJsKzLXA1Ejo1aH7soo7Jx+8 1/MHjKP3cEypTi6nqC6ZMONrUJoVw8FoqulSiQ1Q= 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 5.3 39/95] ath10k: Fix a NULL-ptr-deref bug in ath10k_usb_alloc_urb_from_pipe Date: Wed, 27 Nov 2019 21:31:56 +0100 Message-Id: <20191127202904.566910219@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127202845.651587549@linuxfoundation.org> References: <20191127202845.651587549@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 @@ -38,6 +38,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, @@ -55,6 +59,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++;