Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1722206ybj; Wed, 6 May 2020 04:14:04 -0700 (PDT) X-Google-Smtp-Source: APiQypJLk0pa6xvClltUQi6D1h8/Vu6nkbwS/JH93MBnBXl3HPSh1ebhMnHq0vEnkziRNh1b2TkF X-Received: by 2002:a05:6402:b99:: with SMTP id cf25mr6337216edb.372.1588763643988; Wed, 06 May 2020 04:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588763643; cv=none; d=google.com; s=arc-20160816; b=FShUCohsFuLbp2ZqU/5HE2Gtd67B3pU8jB2RleVrE8EMzdHS8w0UQEyvuTQWSH0eXH vLJy33xbBtbnJNqii+NTuKsofBk+agKOIdv7Qz2ANLa8kkIweJ9V6oouXpyjPMTtF/pJ l6tSHJBNtoZkakbr4Desd4Co6mgYWaCgy1HmW++V4NwpyL7ZMlufgRKzesy5cl8gusXb 8QEqbSrfl5uXGasl3A8TCNwJNV59VYpQhS6CwCOJLTcgnTs8XMB6TAuWFLGySW7iOlYJ k7QTL2iV8IiSEgiRBORBxvWTc9xdTjMMpZT1FlN4zIaYNUjqyuoP3nBX8Z84RkLO+cPC 4rZQ== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8vHCRSvG8D/XlivIS5MkyFwGyNAW1tdlQW/9Pmve0hM=; b=KEdA17jFls/ydYe/gViKBTAgzOwD4a0cFSa0625pe5nnUBD9rWlzF4GXb/8DrTjlj6 VmxMvWvJTRSzuo++MdzNOZSeOd7mjhHaiikhLf3wUBfgLBibelxN1ZqLOS6Nnhx4xhrL W/mi9R7JHCBZsy9WHSjvkhD2x+8jr4fEt0zOrnHIyFKKHcPpMLHgKBHi0jLAT54QJJBx u0A95TiwBtyt0WnDX4D/Ai4vIaXTNeOfNxfrwSQxVYsiE98MrB0CA9EM99jl2r66tQDN X8hcFOcF2Y6K+z6uqDq5IG7vjHDVgpaD24H8jwVB6L6N2A8jOwZ4AoHKR2IwpYz10cmz F6bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uWC3u5Wj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p9si924254ejf.493.2020.05.06.04.13.41; Wed, 06 May 2020 04:14:03 -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=uWC3u5Wj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727969AbgEFLH0 (ORCPT + 99 others); Wed, 6 May 2020 07:07:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:54584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbgEFLHZ (ORCPT ); Wed, 6 May 2020 07:07:25 -0400 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 A715D2068E; Wed, 6 May 2020 11:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588763245; bh=uKEKqSAFW/aYJ2Fu+oNP2OG3gCFuq6s+Y3wl5j44KCE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uWC3u5WjG91H2+dc4Bkf6aVXMcIZ0cAuEkHSQiBXupiDku785TgQK/8AchuZvCRSG oLTZkJjYLiUNP+XKf6tsDH+yQkf+MqTseD2H85JSofiEwG1AEPIj9Uzs5ZCZ7I9PjY /4W33vNyBVdBAqI3MwKPvoAUUXXrOumzYHYytn28= Date: Wed, 6 May 2020 13:07:22 +0200 From: Greg KH To: Jia-Ju Bai Cc: mchehab@kernel.org, kstewart@linuxfoundation.org, tomasbortoli@gmail.com, sean@mess.org, allison@lohutok.net, tglx@linutronix.de, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: usb: ttusb-dec: avoid buffer overflow in ttusb_dec_handle_irq() when DMA failures/attacks occur Message-ID: <20200506110722.GA2975410@kroah.com> References: <20200505142110.7620-1-baijiaju1990@gmail.com> <20200505181042.GD1199718@kroah.com> <0e4a86ee-8c4e-4ac3-8499-4e9a6ed7bd1e@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0e4a86ee-8c4e-4ac3-8499-4e9a6ed7bd1e@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 06, 2020 at 06:13:01PM +0800, Jia-Ju Bai wrote: > Hi Greg, > > Thanks for the reply :) > > On 2020/5/6 2:10, Greg KH wrote: > > On Tue, May 05, 2020 at 10:21:10PM +0800, Jia-Ju Bai wrote: > > > In this case, "buffer[4] - 1 < ARRAY_SIZE(rc_keys)" > > > can be first satisfied, and then the value of buffer[4] can be changed > > > to a large number, causing a buffer-overflow vulnerability. > > Um, maybe. I agree testing and then using the value can cause problems > > when userspace provides you with that data and control, but for > > DMA-backed memory, we are in so much other trouble if that is the case. > > > > > To avoid the risk of this vulnerability, buffer[4] is assigned to a > > > non-DMA local variable "index" at the beginning of > > > ttusb_dec_handle_irq(), and then this variable replaces each use of > > > buffer[4] in the function. > > I strongly doubt this is even possible. Can you describe how you can > > modify DMA memory and if so, would you do something tiny like this? > > > > I have never modified DMA memory in the real world, but an attacker can use > a malicious device to do this. > There is a video that shows how to use the Inception tool to perform DMA > attacks and login in the Windows OS without password: > https://www.youtube.com/watch?v=HDhpy7RpUjM If you have control over the hardware, and can write to any DMA memory, again, there's almost nothing a kernel can do to protect from that. > Besides, the Windows OS resists against DMA attacks by disabling DMA of > external devices by default: > http://support.microsoft.com/kb/2516445 So does Linux :) > Considering that this patch is for a USB media driver, I think that an > attacker can just insert a malicious USB device to modify DMA memory and > trigger this bug. USB devices do not touch DMA memory so they physically can not do things like what thunderbolt devices can do. > Besides, not related to this patch, some drivers use DMA to send/receive > data (such as the URB used in USB drivers and ring descriptors used in > network drivers). In this case, if the data is malicious and used as an > array index through DMA, security problems may occur. > > In my opinion, similar to the data from userspace, the data from hardware > may be also malicious and should be checked. > > Maybe we could discuss this issue with DMA driver developers? Sure, but I think that's outside the scope of this tiny patch :) thanks, greg k-h