Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp514263ybj; Thu, 7 May 2020 00:56:36 -0700 (PDT) X-Google-Smtp-Source: APiQypIOXMkAuNLYTM9cKtOR7Sr25BRfDB1jKSDC/P4mx8FoDoXyroNKMUCKA5jYJQWpUb044137 X-Received: by 2002:a17:906:809:: with SMTP id e9mr10456299ejd.81.1588838196478; Thu, 07 May 2020 00:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588838196; cv=none; d=google.com; s=arc-20160816; b=gisd41KgawYwSILuCDyR0TouvjWfLTj6I3mboBhy0pCgB7m1jmmqySdX9n/uJBd63w edyCeHyz4mU1fj3ZK2yh0l85AM2g7F/n3zx4e+Fd7SCc0qVWSvOX9LA1CSfeZ5OgnMZK c8m5Q010v+9evtboApALCQAoDiAeYwwZwKID8zBZ+1ftNm+94OxsbUv0OIwttv9uRX46 ZIAfwRzDtDVZ8RtPt049XjWrBQ7fvL34/v61gEJyqaiECiCSiu2OB/si/nsQybK5rCI/ S0rgDQN6mt3vH0/xXXYkKnQc/wg8DZWbemQKtFhEWgZgVAQAYDJ6Zby8z/1MIjNZd5SO pu0A== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=eFKh3xlI+Xgv0k6IbPszgqC/hrLMKNTJMkwvKZUlf1E=; b=oHXKE2Btmr45QuqBj9Z7lo3WBHq8YL3C5jkfELeUFPIdjZ/kb5U5vQFLJamWZsGErk J7/8y92AvP06+my68Du8ajQ/lBq93opESR2ySK83/JxRP4ZXr8j4HF7Bld+B6VvPDQDa gXG1obGk/a8GLrEW0kG27zqwZlp+7JdC3TrJFIx++2X+ikLwH2C2gRT1PBb+UuXnK4lP Msx768g/RJAm12bCYLCR4OPrW88JQpM538WjUhWdKMS1gU3A3xcP/ani4J+hC0nxvTy9 U1F9S/kOenveDP1vhcFk5L3FhGcyfcLcswJhoGomUIzZem1+Z+ZTYOfqsw7vxoaGBpg4 LDtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ukCLcKni; 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 n8si2703189edt.33.2020.05.07.00.56.13; Thu, 07 May 2020 00:56:36 -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=ukCLcKni; 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 S1725857AbgEGHwm (ORCPT + 99 others); Thu, 7 May 2020 03:52:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:56292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgEGHwm (ORCPT ); Thu, 7 May 2020 03:52:42 -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 6DF482075E; Thu, 7 May 2020 07:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588837959; bh=ujCMRVMfllan9Dbh7F/kka0DBgXEpAIyKSGPSNapBOU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ukCLcKniQbJ+p1k6xGU8np7WcT4oId0rAQPLlQ1Nl69qiSkwMs8/VX1DTPIBGNE9J CqeyQg2AP4KLedw93hbwe+NxmaoWy0HwRxdqUfzMCC4CGO45h8h5Vx7kj/qhj2KT5n qBc6nfkMYSvi6r/6oSTPlC2ZhkZm2Un7NrWKN5mo= Date: Thu, 7 May 2020 09:52:37 +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: <20200507075237.GA1024567@kroah.com> References: <20200505142110.7620-1-baijiaju1990@gmail.com> <20200505181042.GD1199718@kroah.com> <0e4a86ee-8c4e-4ac3-8499-4e9a6ed7bd1e@gmail.com> <20200506110722.GA2975410@kroah.com> <20200506155257.GB3537174@kroah.com> <46615f6e-11ec-6546-42a9-3490414f9550@gmail.com> <20200506174345.GA3711921@kroah.com> <4bc70ec6-e518-5f42-b336-c86e1f92619f@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4bc70ec6-e518-5f42-b336-c86e1f92619f@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 01:15:22PM +0800, Jia-Ju Bai wrote: > > > On 2020/5/7 1:43, Greg KH wrote: > > On Thu, May 07, 2020 at 12:48:47AM +0800, Jia-Ju Bai wrote: > > > Yes, I agree that this issue is not new, because DMA attacks are old > > > problems. > > > But I am a little surprised that many current drivers are still vulnerable > > > to DMA attacks. > > Given that the attack vector is very hard to actually do, that's not > > a suprise. > > > > It's only a very recent thing that Linux drivers have started to work on > > "we don't trust the data coming from the hardware" path. Previously we > > always trusted that, but did not trust data coming from userspace. So > > work on fixing up drivers in this area is always encouraged. > > > > An example of this would be all of the fuzzing that USB drivers have > > been getting with custom loop-back interfaces and the like over the past > > year or so. Expanding that to "we don't trust PCI device data" should > > be the next step on this, and would help out your area as well. > > Okay, I am glad to hear that :) > Hardware security for the Linux kernel should receive more attention. If you care about that, yes it should. At the least it is providing lots of graduate students with good research papers :) > Last year some researchers finished an interesting work about fuzzing the > inputs from hardware: > https://github.com/securesystemslab/periscope Nice! > > > > If you trust a device enough to plug it in, well, you need to trust it > > > > :) > > > Well, maybe I need to trust all devices in my computer :) > > > > > > Anyway, thanks a lot for your patient explanation and reply. > > > If you have encountered other kinds of DMA-related bugs/vulnerabilities, > > > maybe I can help to detect them using my static-analysis tool :) > > Did you only find a problem in this one driver? Have you run it on any > > more "complex" drivers and gotten any good results showing either that > > we are programming defensively in this area, or not? > > > > At present, I only detect the cases that a DMA value *directly* taints array > index, loop condition and important kernel-interface calls (such as > request_irq()). > In this one driver, I only find two problems that mentioned in this patch. > With the kernel configuration "allyesconfig" in my x86_64 machine, I find > nearly 200 such problems (intra-procedurally and inter-procedurally) in all > the compiled device drivers. > > I also find that several drivers check the data from DMA memory, but some of > these checks can be bypassed. > Here is an example in drivers/scsi/esas2r/esas2r_vda.c: > > The function esas2r_read_vda() uses a DMA value "vi": > ? struct atto_ioctl_vda *vi = > ??? ??? ??? (struct atto_ioctl_vda *)a->vda_buffer; > > Then esas2r_read_vda() calls esas2r_process_vda_ioctl() with vi: > ? esas2r_process_vda_ioctl(a, vi, rq, &sgc); > > In esas2r_process_vda_ioctl(), the DMA value "vi->function" is > used at many places, such as: > ? if (vi->function >= vercnt) > ? ... > ? if (vi->version > esas2r_vdaioctl_versions[vi->function]) > ? ... > > However, when DMA failures or attacks occur, the value of vi->function can > be changed at any time. In this case, vi->function can be first smaller than > vercnt, and then it can be larger than vercnt when it is used as the array > index of esas2r_vdaioctl_versions, causing a buffer-overflow vulnerability. > > I also submitted this patch, but no one has replied yet: > https://lore.kernel.org/lkml/20200504172412.25985-1-baijiaju1990@gmail.com/ It's only been a few days, give them time. But, as with this patch, you might want to change your approach. Having the changelog say "this is a security problem!" really isn't that "real" as the threat model is very obscure at this point in time. Just say something like I referenced here, "read the value from memory and test it and use that value instead of constantly reading from memory each time in case it changes" is nicer and more realistic. It's a poential optimization as well, if the complier didn't already do it for us automatically (which you really should look into...) If you make up a large series of these, I'd be glad to take them through one of my trees to try to fix them all up at once, that's usually a simpler way to do cross-tree changes like this. thanks, greg k-h