From patchwork Thu Aug 29 09:29:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172547 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp2071985ocp; Thu, 29 Aug 2019 02:29:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRxjByKFCa6+gt21Elu5sevgnakA4cC9LYtWqcqB2As43UQYPsfqwfv9RZotOTXBF3iq9i X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr8981470plp.245.1567070981428; Thu, 29 Aug 2019 02:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567070981; cv=none; d=google.com; s=arc-20160816; b=kaTeSjSBBby3TteMSphWA1nip1H+TBdR1fheDZLqA71WRYZ33Rtbdnubgxd46si13+ zGj0404wwbi6o69/5bJ1D60+inHE7ZZQR+fUbKUKkqRnKa6ekLOh1xD4UvUvWo23MC9C nmopv9IGtB/K2WEb2ORi5y3vXvtIP0LdN8spnNjodwU5k0PRzvx29R8CO+EBqf+WM54d lKfwhc3cyfpRCiJsfsCkWg0FWVXUuEUrma1Yr+eV8l8rU9GnCKpGY6crRrjdu1h46Osz zDxaujWXTbUYBcHkXd+DZH7oC88xtCSD5q1uf8anURQ1CD89XY2+pZRqmGpZHwAuxj+j Vmzg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8gReQ7CjJRAhm4L6Tiz8Y9x8ZLQilV94lsV5veC3IIc=; b=JVHmRYRy7IOGubOGZ70ojbYRSaa7uoKO4FB2biZmi7K5UQwRTkN/vl+cDWGkSX0Fzo ZhUQTmBT0zGIcxfLVRHD/26FlhJkyrSFEJUCCH6L6eioF6qAhxOOT0VVdPooRurdIW+0 6/3YSpps3ED5EMmmx2YbI+AwXxDP6HnMp+jvTSad1Wc89efmCGXCgrz5ensZa9a3euUR rGbznl5fXnUR8Ni7ER8XfPJwTSlkee+L4vj4LlJ0qywl2P00ZQ10KPEcnz4oSeOgqgT3 rweaqJIweCW4eNbmIq8eMitsgUqFkWd2fwiwtNQwT7d1OBtHhna+CEtgJSeG8yk2EopQ bONQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PtDj5xCz; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 m27si2016689pff.186.2019.08.29.02.29.41; Thu, 29 Aug 2019 02:29:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=PtDj5xCz; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1727073AbfH2J3j (ORCPT + 16 others); Thu, 29 Aug 2019 05:29:39 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52699 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbfH2J3i (ORCPT ); Thu, 29 Aug 2019 05:29:38 -0400 Received: by mail-wm1-f67.google.com with SMTP id t17so2945265wmi.2 for ; Thu, 29 Aug 2019 02:29:37 -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 :mime-version:content-transfer-encoding; bh=8gReQ7CjJRAhm4L6Tiz8Y9x8ZLQilV94lsV5veC3IIc=; b=PtDj5xCzFk2wfuU6zYpS9GCEDFNAdkqEJTun597to8/wlUXA2ovkmt2++lgNbddgWj nghCcmSOy88teYBBZJklqSkpkrGk0u7G46HXOPF8zXasJG7NYAM4xbl+IrqiDHsa4a0t Us1d9idE5Oe+d+yY46bKYHNlylT6HBA1I4f9ZwezXwkD49LPzyQsGAN7eAW+RkSJIfrX oFM8uxkVTyFTRc9rtET54Bn2IAabx2x7VgSIL6F2u1KCjd6gCSJJ11GQ/KNwG/jIsSzh Zlf6IL+bUikvtRslDtQAgaYAJGHhijvgZ0U1TiJIxLjlZ0DTgAmlBZZXglO3NV/qtQoq 2AEg== 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:mime-version:content-transfer-encoding; bh=8gReQ7CjJRAhm4L6Tiz8Y9x8ZLQilV94lsV5veC3IIc=; b=QPSk37819q+fTxJjt4KDfOsQEJlA6wABnDn+ogvKTG867qxHS47K2Ik344mIOS4mpw 1lakuUgrXisxFXAyHQApuJyZHN3gWyaTj+lxvSJrRKxbg/dKyJNMMh7X1TsD0nbM3rO7 CvQMhW99wEffjzmmIm6EcpMJypR5UdGLFwja8/0A/AvRyNETihATkG8tPq/odd2hB485 8ZHThLK+7CIEinMQ5zaK/WhnS5ifSdX/95ngS/46Q+ltaQhnqQG+W21XeP79Rep3gj2h ODNTZfoLGdhjtrH+yuUkl0XRxPSb15bJ/+DBHvkxVNnA5q02A011xN84Sjzs+Cz+gvR8 n+5g== X-Gm-Message-State: APjAAAUjJZNGeV3eCgkZq2nZNX/sWJyGryAiemuxOSEJvNKpAfRSS1an hZxxPFpOpIPW4P7+NGetzLoqLQ== X-Received: by 2002:a7b:cc0f:: with SMTP id f15mr10002879wmh.39.1567070976668; Thu, 29 Aug 2019 02:29:36 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id f197sm3609512wme.22.2019.08.29.02.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 02:29:36 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Mayank Chopra , Abhinav Asati , Vamsi Singamsetty , Srinivas Kandagatla Subject: [PATCH v2 2/5] misc: fastrpc: Don't reference rpmsg_device after remove Date: Thu, 29 Aug 2019 10:29:23 +0100 Message-Id: <20190829092926.12037-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> References: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bjorn Andersson As fastrpc_rpmsg_remove() returns the rpdev of the channel context is no longer a valid object, so ensure to update the channel context to no longer reference the old object and guard in the invoke code path against dereferencing it. Signed-off-by: Bjorn Andersson Signed-off-by: Mayank Chopra Signed-off-by: Abhinav Asati Signed-off-by: Vamsi Singamsetty Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c019e867e7fa..59ee6de26229 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -913,6 +913,9 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel, if (!fl->sctx) return -EINVAL; + if (!fl->cctx->rpdev) + return -EPIPE; + ctx = fastrpc_context_alloc(fl, kernel, sc, args); if (IS_ERR(ctx)) return PTR_ERR(ctx); @@ -1495,6 +1498,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev) misc_deregister(&cctx->miscdev); of_platform_depopulate(&rpdev->dev); + cctx->rpdev = NULL; fastrpc_channel_ctx_put(cctx); } From patchwork Thu Aug 29 09:29:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 172550 Delivered-To: patch@linaro.org Received: by 2002:ac9:5c4b:0:0:0:0:0 with SMTP id r11csp2072214ocp; Thu, 29 Aug 2019 02:29:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxtEO6c1Kqw8FKylVObNiHsp68S4eUNOrJZyPmWyhP1I7/9uoH8gypjTgQWtUuwJ+Un1IUc X-Received: by 2002:a17:902:f217:: with SMTP id gn23mr8779913plb.21.1567070993284; Thu, 29 Aug 2019 02:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567070993; cv=none; d=google.com; s=arc-20160816; b=woyQAE3X0WT0zHIssxB4ZnHZc4Zpi481HlSgENxGRJWQnGM8IUNky59ksNRqiOBKJy 5szlhSCPKVL7iXb8q0bYQXghuB7x6Af4Lt3nIalt5F+EgBK5D2tx0FTgGf5xPC+nY113 r1uibXTO8kCd3xAyex/o8kSwCpLEdKol/UDotxBhI+Bb8JSAdaAGPA7SWepzlO9Z5oFR QMMDYjonuWbBGPYwSm12CMEY9tVqExk9H+hkKS013mBk2Lk7MG+0kfKpZE33oZRVExbt NW8QQTTbpDrWG9kn5yz2stHE32YJhT7Elw/GC6CBgjRx/B3LRKN85zJEAGLk6TwpbfGn wo8w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=txsHPtmH/4H2/WnX6EiFrXzeHkL+qrKcHt+2DoU5kzQ=; b=PP2BWB9cjbWSk52bgo+I3GMQvzKq1Ewwy4yQ/ryfiLKiCZLPrmySmr0dlP75dIQpmq 8pFzWq6A8vaCo5Z2res24cuegmkMyE6PAZQphwELtdBH1eUxX1xk6L7f/Yb45398M2eN CqUYBT0GDUOkrLfTWsZXaRXWlwfjLE5YuTJdybJlT/bEh5xhvWhw25I1JSvFYuacxoqK NVwjNJc3jrH/Ss0rgQdRb+FN9zcFsg3tWqSOnRgrHcZhtirpZBCPil45CIcMns6jvWfd BR1Hhdcvupin403u6Nqhy/tPvwcCxZyque2+rez7w3R/mMPXYotbv4pxjG/8CdUQUzdG e+gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xRwJYrUX; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 t7si1725600pjf.74.2019.08.29.02.29.53; Thu, 29 Aug 2019 02:29:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=xRwJYrUX; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1727176AbfH2J3o (ORCPT + 16 others); Thu, 29 Aug 2019 05:29:44 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43806 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbfH2J3m (ORCPT ); Thu, 29 Aug 2019 05:29:42 -0400 Received: by mail-wr1-f68.google.com with SMTP id y8so2636382wrn.10 for ; Thu, 29 Aug 2019 02:29:40 -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 :mime-version:content-transfer-encoding; bh=txsHPtmH/4H2/WnX6EiFrXzeHkL+qrKcHt+2DoU5kzQ=; b=xRwJYrUXbrpjGAWB4+R5fH7G0mRDkrSB5nnGWG4+zYs587hY8Cesq2JqG0vUTu0shm 5pkphlWZMXlMveg2S4oPS4BdCQp2Mnchh4Ih0wV4GdImugyPNv/ZM0MA3she+V9WXGWU BIretLX6+0BXSa3pOq9OZv9oxXVx8pLDf9VNglZBXBTOuIjqJQ63fAQnH8yB/WoV8lxJ Q7aWiOA/e79K4dnGQJ0uBooFrp4oD2jiMo/YosYL+IqpZRMk9m18+GjoTP70snfB5NND zZadvljCyol2fsr5UIoZl+vVT1xk+csmPx3MmyUoosgeuNBmiciKo4MlvIDgOc+ntJ54 g+HA== 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:mime-version:content-transfer-encoding; bh=txsHPtmH/4H2/WnX6EiFrXzeHkL+qrKcHt+2DoU5kzQ=; b=nPPqZjk22ZLKxHaOeCRE9/Fz36aLnwJEf7t8sz9ZHSf9v/8eXTsSWy/lMuCmav8PXL WLpzr280XE5lnDaibh97AXnwqFd6GIbCCN57Daa1Kil9CV/t52fE9GuNASBdKTiA2UmE 11u8tXN809Y6aOTvRbBzN0FSQJrlzBupAxy0GQqC/0Vj158UZS5gO22umK5HSt7uloMM oP6V3KsLrDtnGLrCPs6NjzvYI7WHBj0U39FrrEw+SyzudsgICcJyYBawdNyumhMgzacl j8+I/9rSzri4H0fokB1mHqTbjqlaTU2niGTPgwEoiM1yU49IEagWIOBGoC28aKMYncg8 YVTQ== X-Gm-Message-State: APjAAAWtwLJIjStyKNwV/f0ODzafsRyvQigQUaLIkPJcMNe3fTi/9+1r tOBZHbwMd4EiuZvIdYuLN+zW2w== X-Received: by 2002:adf:a55d:: with SMTP id j29mr9662074wrb.275.1567070980206; Thu, 29 Aug 2019 02:29:40 -0700 (PDT) Received: from srini-hackbox.lan (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.gmail.com with ESMTPSA id f197sm3609512wme.22.2019.08.29.02.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 02:29:39 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Srinivas Kandagatla , Mayank Chopra Subject: [PATCH v2 5/5] misc: fastrpc: free dma buf scatter list Date: Thu, 29 Aug 2019 10:29:26 +0100 Message-Id: <20190829092926.12037-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> References: <20190829092926.12037-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org dma buf scatter list is never freed, free it! Orignally detected by kmemleak: backtrace: [] kmemleak_alloc+0x50/0x84 [] sg_kmalloc+0x38/0x60 [] __sg_alloc_table+0x60/0x110 [] sg_alloc_table+0x28/0x58 [] __sg_alloc_table_from_pages+0xc0/0x1ac [] sg_alloc_table_from_pages+0x14/0x1c [] __iommu_get_sgtable+0x5c/0x8c [] fastrpc_dma_buf_attach+0x84/0xf8 [] dma_buf_attach+0x70/0xc8 [] fastrpc_map_create+0xf8/0x1e8 [] fastrpc_device_ioctl+0x508/0x900 [] compat_SyS_ioctl+0x128/0x200 [] el0_svc_naked+0x34/0x38 [] 0xffffffffffffffff Reported-by: Mayank Chopra Signed-off-by: Srinivas Kandagatla --- drivers/misc/fastrpc.c | 1 + 1 file changed, 1 insertion(+) -- 2.21.0 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index eee2bb398947..47ae84afac2e 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -550,6 +550,7 @@ static void fastrpc_dma_buf_detatch(struct dma_buf *dmabuf, mutex_lock(&buffer->lock); list_del(&a->node); mutex_unlock(&buffer->lock); + sg_free_table(&a->sgt); kfree(a); }