Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3506870imu; Fri, 18 Jan 2019 11:36:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN7ICNIxM3vGxVUSU3Qv52Nfi/B5FNzUPO4ltSJk4NXVX7QyRFFukNSEXqbPmq0jll5yZU/d X-Received: by 2002:a63:5c41:: with SMTP id n1mr18320042pgm.1.1547840170291; Fri, 18 Jan 2019 11:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547840170; cv=none; d=google.com; s=arc-20160816; b=HgYJnS+7PXKVQ9UONVSSoG+nvtq1WS8nXWkwmbvtA8CvIxHvGBS5/tSevnNrkygDjT KfdMij+o1XzSnImN2xOfSaIqpXxMia2GLpbpW8QLigxGtAfVzHf7q8wfKN2/u15sQVDs nu/dFm4aKtcpbTGnH0uSuCnRhygla4spibGvuKXFSr9Z8fYxE2kUPm/xLm0mO+mfUvbQ USFSLcy9SMpGZgpNhhmeyV6MH06vCM73hUW6S1sIRi6lTHl0rWFYyJwll0dUqt554DJL lTU5I7udt3CoeT4f/CFkEX2pdQqRwwqRoPnPbpFWOTfKnlH5T0aRAZFMn6os2wnudbya kVcA== 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=6nglwg59ccw6RG8umST1ZgDFbaRU7W9E+lf+vsjMHh4=; b=hLTWBPXwgJxUtbSq8JWdvcLUU4k2qSfGF7GEOtHWnPAz/ClBY52rFEVRyBTtoA3Ger JUTpEg8zSeJx5IZTIu55eNDuqbVmabDkh/AH7AAynffaA6enzUooCST4jPERKm3XYvWC lzw1sE40Ww/OshAo/sfPqrC87NqjVZCACBZRbqhnjI/lQLT1zcTnXElOiqBMo1O2Ohyc DBOBYuzCtwmT+QkqLuhLT6WeRL7bPE5fCrmLONmSqrEI+48rzB9gu4I3px3+Pkv58+uR dYwUfTQkfnq6k/xCc/pFHSGjpD7u8ivJqUztytqUGqeci08yixOM369ym/MJtPLvRnrV U/iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=OIj8XrKg; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si1645422pgd.461.2019.01.18.11.35.54; Fri, 18 Jan 2019 11:36:10 -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=@ti.com header.s=ti-com-17Q1 header.b=OIj8XrKg; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729300AbfARTe2 (ORCPT + 99 others); Fri, 18 Jan 2019 14:34:28 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:39086 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbfARTe1 (ORCPT ); Fri, 18 Jan 2019 14:34:27 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0IJYHEm003496; Fri, 18 Jan 2019 13:34:17 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1547840057; bh=6nglwg59ccw6RG8umST1ZgDFbaRU7W9E+lf+vsjMHh4=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=OIj8XrKgcIR9fb71zukjpn0Bm2oaH0gLeqa7YrbE+f1c6Y5hSGdgfO5l9q4AMtGIi UXEyofuPj2epe6U5N9QJTiV4LVt3HFdCGSoeJ0u88wr/Vko+I0Mn1tj4GLeA7/vlgt LcGxPnznLTu8GEJBOyduS+F1ryz9uaCU2/b2jfu8= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0IJYHLP067694 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Jan 2019 13:34:17 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 18 Jan 2019 13:34:17 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Fri, 18 Jan 2019 13:34:17 -0600 Received: from [172.22.101.212] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0IJYGY0015015; Fri, 18 Jan 2019 13:34:16 -0600 Subject: Re: [PATCH 1/4] staging: android: ion: Support cpu access during dma_buf_detach To: Liam Mark , , CC: , , , , , , , , , References: <1547836667-13695-1-git-send-email-lmark@codeaurora.org> <1547836667-13695-2-git-send-email-lmark@codeaurora.org> From: "Andrew F. Davis" Message-ID: Date: Fri, 18 Jan 2019 13:34:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1547836667-13695-2-git-send-email-lmark@codeaurora.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/18/19 12:37 PM, Liam Mark wrote: > Often userspace doesn't know when the kernel will be calling dma_buf_detach > on the buffer. > If userpace starts its CPU access at the same time as the sg list is being > freed it could end up accessing the sg list after it has been freed. > > Thread A Thread B > - DMA_BUF_IOCTL_SYNC IOCT > - ion_dma_buf_begin_cpu_access > - list_for_each_entry > - ion_dma_buf_detatch > - free_duped_table > - dma_sync_sg_for_cpu > The window for this seems really small, but it does seem technically possible, good find. for what it's worth: Acked-by: Andrew F. Davis > Fix this by getting the ion_buffer lock before freeing the sg table memory. > > Fixes: 2a55e7b5e544 ("staging: android: ion: Call dma_map_sg for syncing and mapping") > Signed-off-by: Liam Mark > --- > drivers/staging/android/ion/ion.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c > index a0802de8c3a1..6f5afab7c1a1 100644 > --- a/drivers/staging/android/ion/ion.c > +++ b/drivers/staging/android/ion/ion.c > @@ -248,10 +248,10 @@ static void ion_dma_buf_detatch(struct dma_buf *dmabuf, > struct ion_dma_buf_attachment *a = attachment->priv; > struct ion_buffer *buffer = dmabuf->priv; > > - free_duped_table(a->table); > mutex_lock(&buffer->lock); > list_del(&a->list); > mutex_unlock(&buffer->lock); > + free_duped_table(a->table); > > kfree(a); > } >