From patchwork Thu Dec 19 18:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 182177 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp869629iln; Thu, 19 Dec 2019 10:54:21 -0800 (PST) X-Google-Smtp-Source: APXvYqzjLujpNZI8zXMPuWMGxRPOWTfcQ2E2LnmX3warTgcXHV+tdZj7t3mqEkHa8A3M7hV6pjT8 X-Received: by 2002:a05:6830:18e9:: with SMTP id d9mr1931998otf.332.1576781661382; Thu, 19 Dec 2019 10:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781661; cv=none; d=google.com; s=arc-20160816; b=Y3MCa20bFSNqHQMjpKPbaUc0XnXk0gfe7geEKahRY+67Y16U8F6yyPvfMFqBaq1HMm Mbr401rPUKye7rZWuqOW8Y5g2dAoSAjBFgqHn+j5xZWH5TlfuTVobSuWBfuTiTW8pXYc 78pj8ZZh3UEizdu0KV8UzwGokcf3yI1xniNvhrGhOfogT9jD4IrHJfJd1reJPtdBum7D ACKAwSuaJ5TYdUmUV7aQfPzZobceVLQgkAerVEJ70nxm7gY4kVxOSRoWyHjNmUU7+0Wy 6vmRS5s0CIRVw/FA13AUCDjsjB4j33kRErx5kgSN6/4LGcigEVP5+WpDJim2PgAbpEQJ OP6w== 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=rIqZHnhWEMzZH49nTKxn6kMeINUi/gPMcn4u+mUJEHs=; b=t4RBjI1k3+N8t0dQTeW+5tch6DOsXRO0C5eEU1UV6MtYOy6fXDPMNdYoUQEUMb9rLC VBpAgpmPFStfbhdSOmgt0ipoRHf0631mzFQlr3fOi+N76My5zXKlI5sNI1lQq8Utxd9j ji0cm69HZos4vmit1pxRrdn8vjmRo+nQe+SzyUEmhvVZQeOWLpgVhizF0ADk756tedQJ 9V5igJhjjatIqdxxnVlpugV01kBrP7n9CqzyRjijXR5Od+Dj91E43DmVMh0Ct5v8amrq nekC1p7JKGSDNE7PR1iqxF1vz4ENMImJCKkEkh9l9hcfyjNlm9U+axONF4Tg0m/7pHN0 xMLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JqcjvyeY; 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 t20si3615561otr.64.2019.12.19.10.54.21; Thu, 19 Dec 2019 10:54:21 -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=@kernel.org header.s=default header.b=JqcjvyeY; 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 S1730491AbfLSSyT (ORCPT + 27 others); Thu, 19 Dec 2019 13:54:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:49668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730312AbfLSSyR (ORCPT ); Thu, 19 Dec 2019 13:54:17 -0500 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 C7548222C2; Thu, 19 Dec 2019 18:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781656; bh=axVM7PxtCOj1DqmmtjY6K5VnsVEfJD0vyDPh5EF9+2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqcjvyeYsbQ895h0SbhFRB5DBuThKUPEA4ZA4fa1IyIwwb79aS1Fhl+mzA0zzXdJi vKwNWBNW70SWmX86OneTcjDJ63iNQGf9Pm4YKKHhVkbMf9en4Z4vdBHj/oPENuEwX6 3oErKXkfik0dzIwbZEMADlqhaf400IVdMYFsp/RQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Lew , Srinivas Kandagatla , Bjorn Andersson Subject: [PATCH 5.4 26/80] rpmsg: glink: Dont send pending rx_done during remove Date: Thu, 19 Dec 2019 19:34:18 +0100 Message-Id: <20191219183102.757924777@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bjorn Andersson commit c3dadc19b7564c732598b30d637c6f275c3b77b6 upstream. Attempting to transmit rx_done messages after the GLINK instance is being torn down will cause use after free and memory leaks. So cancel the intent_work and free up the pending intents. With this there are no concurrent accessors of the channel left during qcom_glink_native_remove() and there is therefor no need to hold the spinlock during this operation - which would prohibit the use of cancel_work_sync() in the release function. So remove this. Fixes: 1d2ea36eead9 ("rpmsg: glink: Add rx done command") Cc: stable@vger.kernel.org Acked-by: Chris Lew Tested-by: Srinivas Kandagatla Signed-off-by: Bjorn Andersson Signed-off-by: Greg Kroah-Hartman --- drivers/rpmsg/qcom_glink_native.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -241,11 +241,23 @@ static void qcom_glink_channel_release(s { struct glink_channel *channel = container_of(ref, struct glink_channel, refcount); + struct glink_core_rx_intent *intent; struct glink_core_rx_intent *tmp; unsigned long flags; int iid; + /* cancel pending rx_done work */ + cancel_work_sync(&channel->intent_work); + spin_lock_irqsave(&channel->intent_lock, flags); + /* Free all non-reuse intents pending rx_done work */ + list_for_each_entry_safe(intent, tmp, &channel->done_intents, node) { + if (!intent->reuse) { + kfree(intent->data); + kfree(intent); + } + } + idr_for_each_entry(&channel->liids, tmp, iid) { kfree(tmp->data); kfree(tmp); @@ -1625,7 +1637,6 @@ void qcom_glink_native_remove(struct qco struct glink_channel *channel; int cid; int ret; - unsigned long flags; disable_irq(glink->irq); cancel_work_sync(&glink->rx_work); @@ -1634,7 +1645,6 @@ void qcom_glink_native_remove(struct qco if (ret) dev_warn(glink->dev, "Can't remove GLINK devices: %d\n", ret); - spin_lock_irqsave(&glink->idr_lock, flags); /* Release any defunct local channels, waiting for close-ack */ idr_for_each_entry(&glink->lcids, channel, cid) kref_put(&channel->refcount, qcom_glink_channel_release); @@ -1645,7 +1655,6 @@ void qcom_glink_native_remove(struct qco idr_destroy(&glink->lcids); idr_destroy(&glink->rcids); - spin_unlock_irqrestore(&glink->idr_lock, flags); mbox_free_channel(glink->mbox_chan); } EXPORT_SYMBOL_GPL(qcom_glink_native_remove);