Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1464268ybp; Fri, 4 Oct 2019 15:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyal6T5rV1qM5TeI/8L9yVZipi5BLze7JoTAXMSiZZq4ipqr1y4nSGiwjXUQWt/eK7bJrEH X-Received: by 2002:a17:906:52d8:: with SMTP id w24mr14170887ejn.6.1570228100641; Fri, 04 Oct 2019 15:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570228100; cv=none; d=google.com; s=arc-20160816; b=EBBGrxf11vV+cRLOLi8gAiyLsaHas02naQ17r9kroJWeTRMvEDAwVW4jqtEeRsJitd MwUbKuoI9gdX8EHJuoLGErSXKxjMKu/VtSsUtP3HM4QN6MV8Dj8GoV2CGd+xhGWTYs79 A4TIrc2gs4hOyIuG1F6KVnnZ3mr96F41z8mjiFlPsuWlt1kvLAFgKjvHAb/W8aY6jGys nxh3tIfLqQTZsAeao4UetTjS5a5ni6anCM1bisywaQFZDmASbRawfSxYI1J05Jp4TSKw yl3OaJlvSgLZrYJ0PLDJNiO26wyog7dK+eExtkByt804P0AKyhYllvoKXKRm05SurKUP luxQ== 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 n8si3654656ejz.22.2019.10.04.15.27.57; Fri, 04 Oct 2019 15:28:20 -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 S2388547AbfJDW1R (ORCPT + 99 others); Fri, 4 Oct 2019 18:27:17 -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(-) 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); -- 2.18.0