From patchwork Fri Oct 4 22:27:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 175250 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1307275ill; Fri, 4 Oct 2019 15:27:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyM5/vbOfce0TKd9Y/M4TlDMDe+gsXxq/nagBXV6JiOU27Y38HkMN7bMA4nkQeG5jkCVF7g X-Received: by 2002:a17:906:6bca:: with SMTP id t10mr3672352ejs.64.1570228043032; Fri, 04 Oct 2019 15:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570228043; cv=none; d=google.com; s=arc-20160816; b=Mn3hU+RMbROH8f8oBDV/GkIzg2vq7Cfq1GcVGA3LqnbgpRNqIv/1UrbbC2dqhB7yhb ATjr3OV1isPYfHmftJZwg3X/76GnmgE8Qvil6sxTssM5iNO7giAzhrZkjmtr04uTtBRZ SlPZRIVYeNGXvaJ3R12mvNwfLJkXpxGTXJ6rA8jRzd3TKB5JiZI4O5WeadcMqPkCyerr M7DIb385ToK/ElFTNhZaW+MEHTKu8TXy3MjTe7WYJqfPcHOHGYOkYPDtPyid+4y6XK15 3rHuMuNUSSb1SoQt/z00dpPHHjAlfXNeIeH6cC2Bd+cKh2zKmg4UnqsMZ/z3JADPnqWo twsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=DC2A5jSQG+hIe1l9YvJxvxOzUl1uERA8bQ7DMTBdthc=; b=vEjhToeWL3TKkmvxtSGVhCyS0l3GCR+tUQgdkiq3lv7LdNyh2RtkEHeYRs+tB33rfj A3zxY+0ncCMCujYH2a36enwi+NtxUplf63tl7hGTxYwq6rUdHMo7IKicVEOQLmP0B7qZ abydoA1cwfRpvw42tnEqA1/HVduY48QsAhOP+TakPzajQwVHSy4pPdSJef04ijsz9Mrz jtNCpShBql5p0VjdtRp+pWRSz4bWkb467WiF4cSTSKr4FfOzTnAwc1zYElRp4fJ0H63C MR/iVECbPrDd1VJhNRzRN3DkU57HXMUQJgj70xuFP5mCQbB6DmTadqxxzq0TXLViQeU2 1wkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RelufgZ+; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si4703244ede.150.2019.10.04.15.27.22; Fri, 04 Oct 2019 15:27:23 -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=@linaro.org header.s=google header.b=RelufgZ+; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388603AbfJDW1S (ORCPT + 27 others); Fri, 4 Oct 2019 18:27:18 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:47002 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbfJDW1Q (ORCPT ); Fri, 4 Oct 2019 18:27:16 -0400 Received: by mail-pg1-f194.google.com with SMTP id a3so4497600pgm.13 for ; Fri, 04 Oct 2019 15:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DC2A5jSQG+hIe1l9YvJxvxOzUl1uERA8bQ7DMTBdthc=; b=RelufgZ+B/odeePAnM4e87bM9EabciKjaV6lHM4VYkTp/XFzlnEDyH2DNRxjXQF10u Y1cX00PxAOrVJXOMVI4Jz5pH6HZB8i2ZgTpxobzNvMAVib5gLlNe5A3fpFX+wEjHeLbj Nwnh722lDXKm7pVrndqojqo39nvS0EPkjZmnbvzWXqEcvUUc81j573I2IRNppESFcZ5F YSsMlhPDFhMcmTAgawV0PwlSpiD2yzwuqvqvF30LNcae/Vv3w+SsylmXVOuc0gAqGnuJ Ngr4Zw88cfUi/DX9COsC/+pNYS9s4O5KBXOW30BztAa/0l7uBPKY/Lp/6wr1WndjPEPK Uubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DC2A5jSQG+hIe1l9YvJxvxOzUl1uERA8bQ7DMTBdthc=; b=CtsVwp/jtO7ddu7qrq/6/2jvEP5BkpBTvluU//kNWj8EY0DqjWYf9YEtCxhKN3cueE M2X31qANBQoanMiPYa/4qCVlLm1EMJKDf0XFk0BVCMb99nmn6romg9pJxcFwtqynVTPe VOt592j8yW+yZldrcQPljkpC3T6s8LnK4nJARWK5knhI37rEev7wQVYemBeIB5Fm5knu bFfMWGNp44/Y9RPLtU3R6MAQtdrTq6IZzPBuDA2sMKj63McYTlS5HItk7ZgwHmkR5vxJ Nn63ENBwdWNkZgugr4nFNAKhaCgevvilPb3UBkGvjBrKJibnwHvOGBcZehBiA0N5HCoH BJ9w== X-Gm-Message-State: APjAAAU+ttxUEl/re2YRtmH1cLiRlZXc+868DFXMGBqNF+UuFjrc5zKl GnOiyPXTeYt0VdLID9DGb4iT7A== X-Received: by 2002:a17:90a:e38f:: with SMTP id b15mr18969878pjz.140.1570228035009; Fri, 04 Oct 2019 15:27:15 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id x37sm6328136pgl.18.2019.10.04.15.27.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 15:27:14 -0700 (PDT) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 5/6] rpmsg: glink: Don't send pending rx_done during remove Date: Fri, 4 Oct 2019 15:27:01 -0700 Message-Id: <20191004222702.8632-6-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20191004222702.8632-1-bjorn.andersson@linaro.org> References: <20191004222702.8632-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Tested-by: Srinivas Kandagatla Signed-off-by: Bjorn Andersson --- Changes since v1: - Drop the locking of idr_lock in qcom_glink_native_remove() drivers/rpmsg/qcom_glink_native.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.18.0 diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 89e02baea2d0..4117818db6a1 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -241,11 +241,23 @@ static void qcom_glink_channel_release(struct kref *ref) { 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); @@ -1634,7 +1646,6 @@ void qcom_glink_native_remove(struct qcom_glink *glink) 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 +1656,6 @@ void qcom_glink_native_remove(struct qcom_glink *glink) 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);