From patchwork Tue Jun 23 19:53:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 191596 Delivered-To: patch@linaro.org Received: by 2002:a54:3249:0:0:0:0:0 with SMTP id g9csp1364798ecs; Tue, 23 Jun 2020 14:20:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfFgGBFjYFtaojvLanhMCroiSjsLHs1j3CAzE49VwNbEphey9ZKiOLMLj03goU9J7Ai9oY X-Received: by 2002:a17:906:4c41:: with SMTP id d1mr10563883ejw.497.1592947217021; Tue, 23 Jun 2020 14:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592947217; cv=none; d=google.com; s=arc-20160816; b=FDRlzanmpqmqEIjcZE9fk5jsQ7c9Eff4kY2XlIWkMlSm4K1QTlBt1JqRteTcl7qiCb tHuJMfca2oyr5DGC2M9eaznjVzyvUZsyfL2YxzPKJiEgXZngCowKNxkYsHVgEhHomk/h QCwjh3IeTzoRQQK/ZVzb7Do2x9+QBm3CkIji2t7CRdCa3UBfG2mjqVnINV8j8tD4FcZ8 9pd00Wt29TcZQYpzEQVgZ9NQHqFHh73YDyscENM3llK+C+Noy+S1NoeaX4XD7511iTjw F0dD+VIhVh9PUgchGbQj6vBXOswksxkd7f5Q1Ywh0XU0gvODFu09Y1lFdhgQ98/0e1fK FB0w== 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=JZx9Qc5pkXZpVWtE31f/KvZH8Flw1ggwNxPrO8bOhAA=; b=Go2wCGtRCHVJ6qdcqKKS/AtQeeufv2QBcXVwu/SpisxS7davL0PoLThOgLI3oWAf7B DbLq9FzgdVdoEfR/un7tRTcZjfpNwZcKkQeC2TO+BHO7mFOPVQeV9unkTa2Bk9f1DWaC /v+e86KZNhUE2QXHptg2uy2aVQjD6s13cQRdJpn+1GPZ1diOLyhyJvHUO6GX3i7h0Cnp S4xefSYLS4VkCxoZqLCKlS/5VpuVZRVWC1iMrEzFZjusA1QZbYKy6//peNaAqEsvd7AS GXJ1KnT3fY6ji/Xyzg2PirEPkr+lsCQjg0DeAYiJC8RoLWtMgtrLPSz+vIEUzjv0WHet SEAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XMsxcJ4v; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si2128607ejk.740.2020.06.23.14.20.16; Tue, 23 Jun 2020 14:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XMsxcJ4v; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390424AbgFWVUO (ORCPT + 15 others); Tue, 23 Jun 2020 17:20:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390324AbgFWUXj (ORCPT ); Tue, 23 Jun 2020 16:23:39 -0400 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 1845920780; Tue, 23 Jun 2020 20:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592943819; bh=Q0uGvxYBaSzETHk8r24Ts7/Bpe5C/cVPyFEOiuYfPts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMsxcJ4v0dSLgJFvS0pm3g/GAmNjh2uGuH/VLDE7pSnYeT5dcZrLNyNrftYZsroL9 MH2luBFUJgZ+4AndNng8g0842TeR6dX/bk6AJvYr7aahrxoHfKLIeqdYHHWISMTaSA V4DB5aP73WZRiduAvszgEa5UGaMoKeuYueQVtvD8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Srinivas Kandagatla , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.4 033/314] misc: fastrpc: fix potential fastrpc_invoke_ctx leak Date: Tue, 23 Jun 2020 21:53:48 +0200 Message-Id: <20200623195340.401181080@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Srinivas Kandagatla [ Upstream commit 74003385cf716f1b88cc7753ca282f5493f204a2 ] fastrpc_invoke_ctx can have refcount of 2 in error path where rpmsg_send() fails to send invoke message. decrement the refcount properly in the error path to fix this leak. This also fixes below static checker warning: drivers/misc/fastrpc.c:990 fastrpc_internal_invoke() warn: 'ctx->refcount.refcount.ref.counter' not decremented on lines: 990. Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context") Reported-by: Dan Carpenter Signed-off-by: Srinivas Kandagatla Reviewed-by: Bjorn Andersson Link: https://lore.kernel.org/r/20200512110930.2550-1-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/fastrpc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index ee3291f7e6156..3a5d2890fe2aa 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -886,6 +886,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, struct fastrpc_channel_ctx *cctx; struct fastrpc_user *fl = ctx->fl; struct fastrpc_msg *msg = &ctx->msg; + int ret; cctx = fl->cctx; msg->pid = fl->tgid; @@ -901,7 +902,13 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx, msg->size = roundup(ctx->msg_sz, PAGE_SIZE); fastrpc_context_get(ctx); - return rpmsg_send(cctx->rpdev->ept, (void *)msg, sizeof(*msg)); + ret = rpmsg_send(cctx->rpdev->ept, (void *)msg, sizeof(*msg)); + + if (ret) + fastrpc_context_put(ctx); + + return ret; + } static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,