From patchwork Thu Dec 19 18:34:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182175 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp867934iln; Thu, 19 Dec 2019 10:52:35 -0800 (PST) X-Google-Smtp-Source: APXvYqznHkZmUWmoPegGY8I3D4s6NHwxn1SHge5RnOFLAdea3F7+XUcCk332jU8l08LyVu0vQzlz X-Received: by 2002:a9d:4692:: with SMTP id z18mr9986187ote.163.1576781555550; Thu, 19 Dec 2019 10:52:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781555; cv=none; d=google.com; s=arc-20160816; b=c/gdxcvUk+O2afOBEr/2qQatyoGOGj6GRAx43dvlKkufVFjLu9NGo5vLeedBHg89z5 uwypqTvaOYUulDJyQSRUOPye23HYtQWpcuoVl3CECPv+XOFDkqLdQJqGvWzNB9NQQzE2 FB7cdN+gkUvGBvp0w2m/Ae9OGxZsvMvVCeVw/6JanGH7LARXojiUMA6G8ymlY3RZa4Rj EufriHzH52SJsVLUImoMFQU+el7bLUvU7U0fsQvtT+IRIrGCZKJuxUsmi1AFYcugsiW1 Rt2b/wajJUGy0n7wKqQibQZeuWz700r9kCvk14Ns4FGw9J3x/xjAy5hPAotYyOOMI471 UNCw== 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=yYB2Qs7vXPq2l0eqGgRlcdZ9G5tNeY0Hd+9qH+WPQDc=; b=jG/+f5UGMHaR0c22PMVfNO3YTuzKFD/P5atuP3X5KXkpmXlukDsur7gbr03rrCNwNO qmF+O8fqwYUVDUP5dFj8nna+fpSt/Wm98014zfRNNT7f0lonl+8CZMnwTgjsMG1c50Mq PIXMOnXkEKy3/pIm7e80XabyGTnDeIshgOMdQM+5KI4hEtV/sIzJGHEakrpSXZZZ2gyg OskOQOL8Lwhxc9cK12hTkWDDYGSvvppnPvLnQapOUyJJ0xbgER9PAc6ZvNpu41UkYJW5 FYjXLkXRMrCUXBwFN92u/37VUMFXTE5roWt49VAJDq1MGo0RsGHBMuJwnuUVuqOAyEyr OxjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sBRkrpSy; 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 y8si3720717otg.309.2019.12.19.10.52.35; Thu, 19 Dec 2019 10:52:35 -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=sBRkrpSy; 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 S1729411AbfLSSwd (ORCPT + 27 others); Thu, 19 Dec 2019 13:52:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:47084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727675AbfLSSw2 (ORCPT ); Thu, 19 Dec 2019 13:52:28 -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 A49DB222C2; Thu, 19 Dec 2019 18:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781547; bh=Vmz3wYOJbZc0L0QOMOlJVhOavn4fujjmfqInOPz+33k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBRkrpSy24Z+J0vXZHAaK+/hJ05TAEc8gw6UW0X30nJZKlvlsdLFyx3er3YQE2hVY 88B7rtGz2hkgq47pOavaKsQSApQ3UtSVUFRIr8BRKqP2hwawNlJ0Y51sPC/e4SMmUl k0zaTbQFu265386LrM6LASGe94tr4G+94t581xp0= 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 4.19 29/47] rpmsg: glink: Dont send pending rx_done during remove Date: Thu, 19 Dec 2019 19:34:43 +0100 Message-Id: <20191219182933.427327141@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219182857.659088743@linuxfoundation.org> References: <20191219182857.659088743@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); @@ -1628,7 +1640,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); @@ -1637,7 +1648,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); @@ -1648,7 +1658,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); From patchwork Thu Dec 19 18:34:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 182182 Delivered-To: patch@linaro.org Received: by 2002:a92:d0a:0:0:0:0:0 with SMTP id 10csp876141iln; Thu, 19 Dec 2019 11:00:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzhQyvRG43wnZ2kpskdJaMfmnlXBw/TcGXuj/+8ZniSLsaN/EXiZBzuBQ1H7Zka8bS2O6fl X-Received: by 2002:a05:6830:1112:: with SMTP id w18mr3591205otq.356.1576782013476; Thu, 19 Dec 2019 11:00:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782013; cv=none; d=google.com; s=arc-20160816; b=cb2CPmYT+x1s93q9Z8qbUnbk9UWRO+6aI6LQdSxhih0vZWtx8q0cd6+hwzdtQPDMLy xU1MDKMXoAYqrD4kB/lIWNkPIKTM3VNfwI6y44aUBh+F3ZhtpoNHzqBu/0rcvHXnbwUR vk8tJ9iYzpVofIb5knwF37zf1hPzltCN8/vw6GR9HgS946o9QLcfW/YLQ6QYGae5Z7wT K3Q/CG31ExhEhjpZtImmHONM0HVyEJANN1RbTKHKoT1embawBq3pEvjuZdZSYaiqYXY7 WvEHWJAshAmq2s7iFKB6NpjN+KzAzhEcmXGx7/p+9O+9OOdXnx/lGMXLZyYabCsLCGXy YiTQ== 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=2T2Vh3eSqrBF5sgWOfRlCrSgvULjIc47BO3f1wNwDBw=; b=lEcivbqv+FEYcrnQMNQz2aJ6qLNqw9AZ60YVBhFXyq/hWkBA9zI891T6ankfGJz7ga IHygVpCOjoOhZf3RFy8AKhhu6579OstS9HF3GZz9x4fUB2FktGAqTtpWSGziY+E4012e Ie34x5D2WpMZQqsyjlM9Ya3AtLqq/UANMxGaS1xyU4dvqqnGdAQ21Z3Ho4/MNJgbZPAU 0K8k6Bhr387FFZDHmxUsdT4KThbwKI6GSPB6PSpR4N+6azPnK5YeOeren6TDEdeKmpN0 oDaaYlpDIlVjlyvyxwu1aGVvDVIDj0HLwf6BJ7JLFiMBFNdSfALNGEySUJFlynBi6Gon 7M8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dYEUJRQu; 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 e190si2859343oib.113.2019.12.19.11.00.12; Thu, 19 Dec 2019 11:00:13 -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=dYEUJRQu; 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 S1728239AbfLSTAL (ORCPT + 27 others); Thu, 19 Dec 2019 14:00:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:47128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728752AbfLSSwc (ORCPT ); Thu, 19 Dec 2019 13:52:32 -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 8DA02222C2; Thu, 19 Dec 2019 18:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781552; bh=YhMsg1iYzqKsOGy/17yoIbmWQ5/wgTOI3xyj9vtrgYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dYEUJRQuYgfb6J90uhrUORPNsw93YGVK+ZQSal57vIUHioOI9nok+uAGuSxdLaWNI a+tbdLNpaJ8/bShAlj1GNPh0RdJGG0pfeZ73fJZczUVgMmmTf0i6T4j+Ra1yYLnj5V z3vjjI6o9H3/kh6baG1jeV9x2Kb9dkMhc4NwZhkw= 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 4.19 30/47] rpmsg: glink: Free pending deferred work on remove Date: Thu, 19 Dec 2019 19:34:44 +0100 Message-Id: <20191219182934.163082126@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219182857.659088743@linuxfoundation.org> References: <20191219182857.659088743@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 278bcb7300f61785dba63840bd2a8cf79f14554c upstream. By just cancelling the deferred rx worker during GLINK instance teardown any pending deferred commands are leaked, so free them. Fixes: b4f8e52b89f6 ("rpmsg: Introduce Qualcomm RPM glink driver") 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 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1565,6 +1565,18 @@ static void qcom_glink_work(struct work_ } } +static void qcom_glink_cancel_rx_work(struct qcom_glink *glink) +{ + struct glink_defer_cmd *dcmd; + struct glink_defer_cmd *tmp; + + /* cancel any pending deferred rx_work */ + cancel_work_sync(&glink->rx_work); + + list_for_each_entry_safe(dcmd, tmp, &glink->rx_queue, node) + kfree(dcmd); +} + struct qcom_glink *qcom_glink_native_probe(struct device *dev, unsigned long features, struct qcom_glink_pipe *rx, @@ -1642,7 +1654,7 @@ void qcom_glink_native_remove(struct qco int ret; disable_irq(glink->irq); - cancel_work_sync(&glink->rx_work); + qcom_glink_cancel_rx_work(glink); ret = device_for_each_child(glink->dev, NULL, qcom_glink_remove_device); if (ret)