From patchwork Fri Oct 4 22:26:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 175253 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1307507ill; Fri, 4 Oct 2019 15:27:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/zXeBuH0P+8thpIuKD1B7FRn3kcoNxYlHNbtiOesrhFgb2YB81gkkEgoul3ZiIpBe+nq7 X-Received: by 2002:a50:d090:: with SMTP id v16mr17817446edd.176.1570228059504; Fri, 04 Oct 2019 15:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570228059; cv=none; d=google.com; s=arc-20160816; b=hZtcMlEw8s0OsDQQ7ldtVHcVZVe0Vcrj5uU/1n8eXRHROkE6FJIBIzdjKSXLKm5Fvo ULlxfMlyh4alk3vmHoKPtI2HJeKcXNS7j5megUN8fOKPhw6CdrtBpL4T169+nITygoBZ 3ghBoq4T0PlrVG4+5FF5Ubv6K64hFDp5lw5K0O0HQYngPy/JHY27S92afo5Ih8FcbRPl 7oMtdgKfpD/jUc+T45bypRX74QaixMlpvvI9IY1kD5RQkFVqOuyq3EBFpyvvZhT+quty EpcRwWWAZXGMCoY1Qan53JoCBgjWTs0t5cIdWEL7fBZFgcexCfeQlrgws0AICeHcbh3v Bo0Q== 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=QoZQF1YbSGqv09dK0KDHECoZ26zQGdAXMaDDkqK/sak=; b=Td0sWGuRQ39AUW2QnaP42Tw6Z7ewPfAO3AgGxHjoqAdGtaIUsYcu5DcWYtvYTeSSJR qCjPbXoxOM7xqKBCA5YL49+ulv9xqJydTSSDYtxjZ3HK8lrBtKfyxtx7u1RFsaa+KKR3 C0GGYwX3YdwkEof2RO4aICwtIjKNcYSsws3+386A3JzdQiueg2Rk5pjWwgz+RWLoOM2b D5+YL8buqHVqTqM1QGGi/eL0/Im5eKvXMSM/esdeTetFRyMfTyyJ28N8Qn59ZStzeFwr KMLvbxCcMtWbrzgrrvY+loOTreQOB3UQD3QYYevVtpYuQToYekEZD2It1llAQ60ziaqw tJ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N1pFmJEh; 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 e14si4510535eda.104.2019.10.04.15.27.39; Fri, 04 Oct 2019 15:27:39 -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=N1pFmJEh; 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 S2388243AbfJDW1O (ORCPT + 27 others); Fri, 4 Oct 2019 18:27:14 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33527 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730542AbfJDW1M (ORCPT ); Fri, 4 Oct 2019 18:27:12 -0400 Received: by mail-pf1-f196.google.com with SMTP id q10so4769272pfl.0 for ; Fri, 04 Oct 2019 15:27:11 -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=QoZQF1YbSGqv09dK0KDHECoZ26zQGdAXMaDDkqK/sak=; b=N1pFmJEh2KW227rJpCbD4242buzzbOIiY6ERrMQ9gsicebzcXfJT8NECywRZ0N5/si Tgj4n3z6k0mSjwaGIY0Sb9m/zLKF/BcICGuTagr4Zg+Au/njphRbjvNov33jKsA/Vf7Q WJF7/x1LoGppiW4Sq9F1hFhlPoIgmJwkPdEhKkhquJh7jCC02RvlcZ/+T+2suX+sWsQ8 0Q8AeMHZ0ScKasmjlFy/MbZh+z5Sjc/tD3uKcmfU+yPdrkHQHmMgRhn7Z+AutgO8kms7 M657x4K//+keOT+lxrB83va5DmkQtIz+fN8gUJr1lTqf+wsnRlzemkuwmS866ClQ9M6O 2XDg== 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=QoZQF1YbSGqv09dK0KDHECoZ26zQGdAXMaDDkqK/sak=; b=PvWv2WAJK7JWYjilN66uY7bmCRi8BDRk9JvuJlwZ63gZVEhDRX2TeTzr8OqWDfDAN0 n1iBtEaAr1zc+5oLAGN5EyQVbeTks1rfDHc3TwZED0yeEpqd86ZIXxjlj7WVG8rWqWlw 3l+hO01I+qfW7lGeeUmWjwgRZLnDpym77KX+Dddhn6gFwMVb9M4KvJZPqy0UTcN64tBI Z3Jbad4I8090qCZjrsabX/GtoWA8ZCORRpTrysBgjSR+TEx4H0D3q5VMIKYpxyH6Cme6 qWFMkmDcKTCOrcfYd1X9lKXsMH2jeloQLE4KiP89sEcYg/0vZRYQg0A7pfE2zj1lO5P0 SzGw== X-Gm-Message-State: APjAAAWTwxNa8WsnXXVv3SbxHRBu2DdiSUL2Zod89OT5tqEFS81gFYRc 1FTH7380/U8W//XbcHhJn5Sncw== X-Received: by 2002:a63:1420:: with SMTP id u32mr2589745pgl.62.1570228031137; Fri, 04 Oct 2019 15:27:11 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 15:27:10 -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 2/6] rpmsg: glink: Fix use after free in open_ack TIMEOUT case Date: Fri, 4 Oct 2019 15:26:58 -0700 Message-Id: <20191004222702.8632-3-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 From: Arun Kumar Neelakantam Extra channel reference put when remote sending OPEN_ACK after timeout causes use-after-free while handling next remote CLOSE command. Remove extra reference put in timeout case to avoid use-after-free. Fixes: b4f8e52b89f6 ("rpmsg: Introduce Qualcomm RPM glink driver") Cc: stable@vger.kernel.org Tested-by: Srinivas Kandagatla Signed-off-by: Arun Kumar Neelakantam Signed-off-by: Bjorn Andersson --- Changes since v1: - None drivers/rpmsg/qcom_glink_native.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.18.0 diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 9355ce26fd98..72ed671f5dcd 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1103,13 +1103,12 @@ static int qcom_glink_create_remote(struct qcom_glink *glink, close_link: /* * Send a close request to "undo" our open-ack. The close-ack will - * release the last reference. + * release qcom_glink_send_open_req() reference and the last reference + * will be relesed after receiving remote_close or transport unregister + * by calling qcom_glink_native_remove(). */ qcom_glink_send_close_req(glink, channel); - /* Release qcom_glink_send_open_req() reference */ - kref_put(&channel->refcount, qcom_glink_channel_release); - return ret; } From patchwork Fri Oct 4 22:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 175254 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1307572ill; Fri, 4 Oct 2019 15:27:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGK/nHTd5tGDlEMrGnw45uPwqL4SYDk3oNe3fDBy9i1S1+aY3FREr9I8s6MA4BSHe6b6+p X-Received: by 2002:a17:906:e0d1:: with SMTP id gl17mr13925266ejb.99.1570228063555; Fri, 04 Oct 2019 15:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570228063; cv=none; d=google.com; s=arc-20160816; b=wVNQa9Sz4MFC6TOXJAIQNOO5cHYWabPa4/meQlK6/7UK8JPS5OSxGyrOVZ+qPE9pG3 mbXdzP8M9Yfc6JQQi9v1V880vVGOytirTsiUcQ6ih516VJfJTxiyhNjFzf0LlkAWpHc6 zJoR6+/vMUkLM7RkGXxvoilQ99EmDUVL9nLaCYO9hCu3GkrGxwym62DVJOhi6LWO6umY ztzh4D3CmXECJ/4ObEviomyoHgoCFUg7LpU28X/Wu55AM8lGy0yX8QeSqVnaXUxzgTvC VHDXXyZjZvT0rRX7KzGd50XsKXYPXWBEh73ozPlr1L7M4/VJUS+yqqMJxoUpDFCHoq8o ONAA== 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=tgp/FeB2xBiOrdWqd66mmTH1EYf2q2e7GgKZ4PEeOIY=; b=eDjfYF6yWivOlZk8GdWdgHZi35mUrhehOsA/UpNi6k8vsQMIFm3CtnA5nPK93i7fhP Ke1xQtk85837zvu1wAnjDIUg4OE+IPk9wIBSxE3dZe6SCCLXPib7tOWkYeydsNwFmnBZ n9OTyIfqbUSrVo+UJtaSK1Ze9zGDRc+zxge1YEFFqn8JzE9RM6rQ2UPVLIeWHL8mC7J7 TzZvgK/4waSHhQJEbG9tyCZ1oJaO3FycBMyrpuFxnmdpzOW5b4ZBdudUnyNUgXtSTl1g qrnXnWZZ8FDWrjDwhSgwXeTVH6bvvWUpSBLZA34ojKmLwVW6IWWCOD1mE6vR4m1hjQl2 50lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FHrs101s; 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 e14si4510535eda.104.2019.10.04.15.27.43; Fri, 04 Oct 2019 15:27: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=@linaro.org header.s=google header.b=FHrs101s; 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 S2388888AbfJDW1m (ORCPT + 27 others); Fri, 4 Oct 2019 18:27:42 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46325 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388195AbfJDW1O (ORCPT ); Fri, 4 Oct 2019 18:27:14 -0400 Received: by mail-pf1-f196.google.com with SMTP id q5so4698898pfg.13 for ; Fri, 04 Oct 2019 15:27:12 -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=tgp/FeB2xBiOrdWqd66mmTH1EYf2q2e7GgKZ4PEeOIY=; b=FHrs101ssw/11oKSgeFbq+imwHggSoDWpMnD0XoJoGXLDG/DMQVKPS1SAt/7Dlb+jH JR4tbGd6OB7SxAvznNvOb94ShM/oM0QF5d8qI5f2T/sYyJsjAE4B4XDsXOPQ6sonOp9D U9zOwol2bbZakyvNAhVndhWwvqwwSPukMSDkCYis8Q3vdYKsMCjl/1pH8gI6VAzTyu5o NNMJaAGpMm1l5ySndZHzAySTeHWF+t2r2lzOfNybRl5Nm/Ltnl3oDjYSpMtPf5tfDbdP sT/kZkxgMZjvR1ShM9y5mC3EjNH5OJ8AZWS7D0ypKcEWw8VsvrIr3K2Snxpyyh2Crwn7 GQNQ== 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=tgp/FeB2xBiOrdWqd66mmTH1EYf2q2e7GgKZ4PEeOIY=; b=E1vNVoK2Tzos+uAiM65AqGtUdlAZ0FkoAcXMgKeUrGf2WoDUgo6hTfITvb32tWvUQP TxSPkzhQKpKl9OQrBPK4h7zBFeGb8dfV2n/vd5eU87Oe+6Vz+lOJvqwdPecWzGAkbm0t Cn01nRUa3vz/qwaCiepYTg3hfYULKCkgQz2R/+eAbWoMDZ+z588iK9koqUkQvCSSBsGr 18Ljs9HUT8IzGNMCpIgZBaA2BEyK2RyJNKzNEY58CViyDD6pKwseRBkY5tDIxjNL9YsI XdwaXcu0/xVA629OPNDdKK/hTqiD9DWOaLRWO0QXVxGQ2K/XxwqIFSABGSS7yiL3BbKc gFPA== X-Gm-Message-State: APjAAAVrMmADi3dvU1Go+Te0E6Mot0C6iq+DgNjzkHWZSpJJyekHFRgs 331Az9HsBySOkmmEK7M0hYGDjA== X-Received: by 2002:aa7:9210:: with SMTP id 16mr19733167pfo.19.1570228032393; Fri, 04 Oct 2019 15:27:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 15:27:11 -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 3/6] rpmsg: glink: Put an extra reference during cleanup Date: Fri, 4 Oct 2019 15:26:59 -0700 Message-Id: <20191004222702.8632-4-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 From: Chris Lew In a remote processor crash scenario, there is no guarantee the remote processor sent close requests before it went into a bad state. Remove the reference that is normally handled by the close command in the so channel resources can be released. Fixes: b4f8e52b89f6 ("rpmsg: Introduce Qualcomm RPM glink driver") Cc: stable@vger.kernel.org Tested-by: Srinivas Kandagatla Signed-off-by: Chris Lew Reported-by: Srinivas Kandagatla Signed-off-by: Bjorn Andersson --- Changes since v1: - None drivers/rpmsg/qcom_glink_native.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.18.0 diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 72ed671f5dcd..21fd2ae5f7f1 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -1641,6 +1641,10 @@ void qcom_glink_native_remove(struct qcom_glink *glink) idr_for_each_entry(&glink->lcids, channel, cid) kref_put(&channel->refcount, qcom_glink_channel_release); + /* Release any defunct local channels, waiting for close-req */ + idr_for_each_entry(&glink->rcids, channel, cid) + kref_put(&channel->refcount, qcom_glink_channel_release); + idr_destroy(&glink->lcids); idr_destroy(&glink->rcids); spin_unlock_irqrestore(&glink->idr_lock, flags); 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);