Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3390643ybp; Sun, 6 Oct 2019 10:53:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXc6VED0V3Oqyu0C9u85tDCOW+1CCn0MT857O3wX2lBCMLOz0eJYtyQHKB0cFKnuz87BTE X-Received: by 2002:a05:6402:6c6:: with SMTP id n6mr25041003edy.162.1570384423840; Sun, 06 Oct 2019 10:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384423; cv=none; d=google.com; s=arc-20160816; b=zpJqOEsLmKM5tPQey2jgDJANfIYvemnndd5Kt1Sbrg94SCW17EI1YBf2rX/RefD5oW uApSBD2oQkyEDDYEmPre5ybArB8e41gSKHDTQ8jWk1O1K3WvOO4R8XwY2oQt97uYBkz9 I/LWC4L/XyC0+FToS1sTfZIrTSvSLmkGkk5rAKYHn6ozxrUKaldubE0xtXaje/siy8rR p68pouOXUuTsQfs23V/L/TFmBum5m6q0h5/lwbVU3B6IMZosiSSX/GnzUAssAV4XqiIy z+vhHp03rGl3xNIhAZwzABkXOiuggTFYx1GY1eOQ2I2KPHwxcrpeVeLWWZ4LXYW2b06V hZSw== 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=prxUoY88H8CMQVO4+QBCHw+QNjP0F/zDoCcPiAd6+jo=; b=HYkWNaUGwztLfKvqHeC7lntR5zWwedw6+hWcHAnuCzuCiqsKz+hI5jrjjcuEFXT/1F m70cR4jcEXtK62CgB+oHYGpog3okIfw/62umcgowuB4kzLPepG+65h199/yKVmCTKw8s PygjV8K9N8skaz80RB8KyNeI0zO13atDMN9S7kN/DbQfqsqJ0kx6Fisv6voLNXE4jbTu +V5rMLh2dH3eCreDf01StFYbl1K4kZZ+J4RobBStOUr582Miib36cCjhV+gPkH2BGia5 SKuqzfwCVv06ihuzEATqlK5HI0oYSpNHUgXOjxlqZupQym0DIlaTNas0drqt11EwD031 FqNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=00EV2UsV; 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 gg17si5689747ejb.294.2019.10.06.10.53.20; Sun, 06 Oct 2019 10:53:43 -0700 (PDT) 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=00EV2UsV; 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 S1727652AbfJFRxP (ORCPT + 99 others); Sun, 6 Oct 2019 13:53:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730557AbfJFRiM (ORCPT ); Sun, 6 Oct 2019 13:38:12 -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 911182053B; Sun, 6 Oct 2019 17:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383492; bh=GW+r+Rf5qHmzeTuPacvUbQairqdtetqEGa1SdIDAQAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=00EV2UsVxInUAlUKEUPzr6NPDLFwUQxiE1HdYb99vHiqYk17PGeTYLmfZkL4I0f8S 3oBqfANfV+9DafqB5VsNuF/6jE2PKdVSsg1BoroFjlLKS86fQY6WhkD/iivHXzfxxH 9vTfR/g+eHWHDkrlpvURicc4dGVpHz4EMyi/FMjU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Sumit Semwal , Sean Paul , Gustavo Padovan , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin Subject: [PATCH 5.2 087/137] dma-buf/sw_sync: Synchronize signal vs syncpt free Date: Sun, 6 Oct 2019 19:21:11 +0200 Message-Id: <20191006171216.070601806@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@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: Chris Wilson [ Upstream commit d3c6dd1fb30d3853c2012549affe75c930f4a2f9 ] During release of the syncpt, we remove it from the list of syncpt and the tree, but only if it is not already been removed. However, during signaling, we first remove the syncpt from the list. So, if we concurrently free and signal the syncpt, the free may decide that it is not part of the tree and immediately free itself -- meanwhile the signaler goes on to use the now freed datastructure. In particular, we get struck by commit 0e2f733addbf ("dma-buf: make dma_fence structure a bit smaller v2") as the cb_list is immediately clobbered by the kfree_rcu. v2: Avoid calling into timeline_fence_release() from under the spinlock Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111381 Fixes: d3862e44daa7 ("dma-buf/sw-sync: Fix locking around sync_timeline lists") Signed-off-by: Chris Wilson Cc: Sumit Semwal Cc: Sean Paul Cc: Gustavo Padovan Cc: Christian König Cc: # v4.14+ Acked-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20190812154247.20508-1-chris@chris-wilson.co.uk Signed-off-by: Sasha Levin --- drivers/dma-buf/sw_sync.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index 051f6c2873c7a..6713cfb1995c6 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -132,17 +132,14 @@ static void timeline_fence_release(struct dma_fence *fence) { struct sync_pt *pt = dma_fence_to_sync_pt(fence); struct sync_timeline *parent = dma_fence_parent(fence); + unsigned long flags; + spin_lock_irqsave(fence->lock, flags); if (!list_empty(&pt->link)) { - unsigned long flags; - - spin_lock_irqsave(fence->lock, flags); - if (!list_empty(&pt->link)) { - list_del(&pt->link); - rb_erase(&pt->node, &parent->pt_tree); - } - spin_unlock_irqrestore(fence->lock, flags); + list_del(&pt->link); + rb_erase(&pt->node, &parent->pt_tree); } + spin_unlock_irqrestore(fence->lock, flags); sync_timeline_put(parent); dma_fence_free(fence); @@ -265,7 +262,8 @@ static struct sync_pt *sync_pt_create(struct sync_timeline *obj, p = &parent->rb_left; } else { if (dma_fence_get_rcu(&other->base)) { - dma_fence_put(&pt->base); + sync_timeline_put(obj); + kfree(pt); pt = other; goto unlock; } -- 2.20.1