Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp496776ybl; Tue, 28 Jan 2020 06:52:54 -0800 (PST) X-Google-Smtp-Source: APXvYqw2ANeHz6Hu9FCQiZ8vdBNFndHqZfIaNQi6O23zFJ5AdfZ2d0ptV6iAwYv0alROGqqfXBMH X-Received: by 2002:aca:c256:: with SMTP id s83mr3138695oif.57.1580223174185; Tue, 28 Jan 2020 06:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580223174; cv=none; d=google.com; s=arc-20160816; b=Z/mE7xDOOZoZ8uy60eTiAp3bjWnoO7Lxl+aCl4eAIZoetv3WSNf1IfXw5x06cYG3c2 P3WnK+28N0F83Zbsh6PTw5SS2ZlBN4dAfpTAIg3gi3rcIbrRYhOOqI8l0OJB3DK/5dr7 tAlFQ1lnqJ1UhCiwfSSLCJ6BZrSNaIoKZDN1oZEBa1NshBr5q02ZmN0vnvqevmqQQF9L xC00KInIecGMwcxLtKFoN9+cZW4odb2bOSDWk5jWsmsoPP1NFI6E+NYurhIjJRDg69Ox ezLLXZWOudF8CLpci5PdvH2T77kHGqhgWR0HQ+v5/NFPKHeE76iqoCWEx1YgQxoOMxsB u47g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=eFQApFkHfSijVKTUUrUwJVn0wlaUnmghVVpOTatZBc0=; b=rKorQ2CVZkUV7pCcsdezhvsBq8O+mEkzAKfC5qrXk3tQq80V0qJtfq/vc487v4DzBa mKWmqe2W8z22cfJdNmVE8FSbdd22tvs02a7xgBDzixQnEd9+Gng17uLtfVNuXbtCi5qG Vu9SKUK6DM2UJ/HKjGPg8tJIU20pBVXvN1hDSMvPw9+zrIcC5g1NJGd94wY8KhFszSFi zqQu4psjFp4gC1Ptmxgm3zUI7ZjoJfEy+ah/VDwC21vOGPb2Bg/MEzckCJulxxJXwIZ1 KE/73IpRSDyOq6LdBJkZ1qTGJ0/Ax4Zy8urfaqKaUTtuJcoiz0ji+sUkT5D9YMkAH2xT d7nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i1eWOouQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65si5769314oif.14.2020.01.28.06.52.41; Tue, 28 Jan 2020 06:52:54 -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=@gmail.com header.s=20161025 header.b=i1eWOouQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbgA1Ovp (ORCPT + 99 others); Tue, 28 Jan 2020 09:51:45 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33952 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726762AbgA1Ove (ORCPT ); Tue, 28 Jan 2020 09:51:34 -0500 Received: by mail-lf1-f65.google.com with SMTP id l18so9322587lfc.1; Tue, 28 Jan 2020 06:51:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=eFQApFkHfSijVKTUUrUwJVn0wlaUnmghVVpOTatZBc0=; b=i1eWOouQAS7TnZdny1CCxPmzkOsNL514kyDso/tgHDC9ht6uZ4x5lkco1i1S/K04gd qRThOaBSQ2DgIkOGQ1UHav+qKuX2xP0eSCk9bCFrXG9yt33qrW1iDm0XTvdi/wChIWX1 ErAIZZ3pzbztHsEeSfSnGSX/1WJbTICOcTN0Suln1Ce7TYawxIZY7AhiJV1CYm+ztNMV 9vl9lNzxf0/w1AABEVWAnMlNviFSr/oOZ512zLn3dPXrIweLVqajI2wANbEBG9m1Xpk6 ntCF9xDgpavJHRCBBNsvJRnCWZBlNTdKo8aBnIa2Rg4tUZS+C9phUNST5D+NsHp14v7j Xejg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eFQApFkHfSijVKTUUrUwJVn0wlaUnmghVVpOTatZBc0=; b=lRcAcN0NjvVW4ajUTKCy4rfFB3N1QT7OQuvGfcGNhVgrGtTSODdJ2QtYeX/28C6zbz VSmJEvfUr06XnGbOXD3U7NCaBz+SKN+TJpS6lC+ajVawaXFWgxVuCUiCgvFCB/Lh5n7C Xu0gWkMVLa2svNbiV1jO9hoLvcXtZEhv4aFsNcfHkpGhAzcZYQboU1oZvFOzaWOWSCju NA+cJzraTVxVewD8fHuhJfmR82p1Fd4buAQ9sr/RH+bXaQGISiX2ThNo1ofuE9Wdj3Uz PQyx3D/t0fgJpL2VSMdUDD1o+g9RPI0cAkRBYl8Vbg+05/kZV2bmarEA3z1dlsDtmLMo QFWg== X-Gm-Message-State: APjAAAUksn5nHzyKmf/ioZluIme/6p0kH3ek7s6zFqIsOXK4j9MVxoJK ZaGwdJ/az70mD96nM+s9Q7keHik+ X-Received: by 2002:ac2:5e2e:: with SMTP id o14mr2662509lfg.198.1580223090891; Tue, 28 Jan 2020 06:51:30 -0800 (PST) Received: from [192.168.2.145] (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.googlemail.com with ESMTPSA id u9sm9737575lji.49.2020.01.28.06.51.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Jan 2020 06:51:30 -0800 (PST) Subject: Re: [PATCH v4 01/14] dmaengine: tegra-apb: Fix use-after-free To: Jon Hunter , Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200112173006.29863-1-digetx@gmail.com> <20200112173006.29863-2-digetx@gmail.com> <4c1b9e48-5468-0c03-2108-158ee814eea8@nvidia.com> <1327bb21-0364-da26-e6ed-ff6c19df03e6@gmail.com> <5bbe9e3e-a64f-53be-e7f6-63e36cbae77d@nvidia.com> From: Dmitry Osipenko Message-ID: Date: Tue, 28 Jan 2020 17:51:23 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <5bbe9e3e-a64f-53be-e7f6-63e36cbae77d@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 28.01.2020 17:02, Jon Hunter пишет: > > On 16/01/2020 20:10, Dmitry Osipenko wrote: >> 15.01.2020 12:00, Jon Hunter пишет: >>> >>> On 14/01/2020 20:33, Dmitry Osipenko wrote: >>>> 14.01.2020 18:09, Jon Hunter пишет: >>>>> >>>>> On 12/01/2020 17:29, Dmitry Osipenko wrote: >>>>>> I was doing some experiments with I2C and noticed that Tegra APB DMA >>>>>> driver crashes sometime after I2C DMA transfer termination. The crash >>>>>> happens because tegra_dma_terminate_all() bails out immediately if pending >>>>>> list is empty, thus it doesn't release the half-completed descriptors >>>>>> which are getting re-used before ISR tasklet kicks-in. >>>>> >>>>> Can you elaborate a bit more on how these are getting re-used? What is >>>>> the sequence of events which results in the panic? I believe that this >>>>> was also reported in the past [0] and so I don't doubt there is an issue >>>>> here, but would like to completely understand this. >>>>> >>>>> Thanks! >>>>> Jon >>>>> >>>>> [0] https://lore.kernel.org/patchwork/patch/675349/ >>>>> >>>> >>>> In my case it happens in the touchscreen driver during of the >>>> touchscreen's interrupt handling (in a threaded IRQ handler) + CPU is >>>> under load and there is other interrupts activity. So what happens here >>>> is that the TS driver issues one I2C transfer, which fails with >>>> (apparently bogus) timeout (because DMA descriptor is completed and >>>> removed from the pending list, but tasklet not executed yet), and then >>>> TS immediately issues another I2C transfer that re-uses the >>>> yet-incompleted descriptor. That's my understanding. >>> >>> OK, but what is the exact sequence that it allowing it to re-use the >>> incompleted descriptor? >> >> TDMA driver DMA Client >> >> 1. >> dmaengine_prep() >> >> 2. >> tegra_dma_desc_get() >> dma_desc = kzalloc() >> ... >> tegra_dma_prep_slave_sg() >> INIT_LIST_HEAD(&dma_desc->tx_list); >> INIT_LIST_HEAD(&dma_desc->cb_node); >> list_add_tail(sgreq->node, >> dma_desc->tx_list) >> >> 3. >> dma_async_issue_pending() >> >> 4. >> tegra_dma_tx_submit() >> list_splice_tail_init(dma_desc->tx_list, >> tdc->pending_sg_req) >> >> 5. >> tegra_dma_isr() >> ... >> handle_once_dma_done() >> ... >> sgreq = list_first_entry(tdc->pending_sg_req) >> list_del(sgreq->node); >> ... >> list_add_tail(dma_desc->cb_node, >> tdc->cb_desc); >> list_add_tail(dma_desc->node, >> tdc->free_dma_desc); > > Isn't this the problem here, that we have placed this on the free list > before we are actually done? > > It seems to me that there could still be a potential race condition > between the ISR and the tasklet running. Yes, this should be addressed by the patch #3 "dmaengine: tegra-apb: Prevent race conditions of tasklet vs free list".