From nobody Mon Sep 29 21:09:36 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC0CAC00140 for ; Tue, 16 Aug 2022 00:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244944AbiHPAiz (ORCPT ); Mon, 15 Aug 2022 20:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351852AbiHPAge (ORCPT ); Mon, 15 Aug 2022 20:36:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B146118B888; Mon, 15 Aug 2022 13:38:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1E06AB80EA9; Mon, 15 Aug 2022 20:38:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 671B2C433C1; Mon, 15 Aug 2022 20:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595887; bh=6ACOjqndLQ3Ih+OOe30yxTbZi6HcEEwp2lVFUhXVsv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OwD2kaRmwVrX45vCECCw7C49DUntf3JAh9RG8rEH7SRD6NJbbJGthMeJd2/lOOu+w NRqTa4eym7E0tDbaB0VF9/rVplqxiG/Zar76JcFjeBAwr0gacX+1vkHnv7M1kiHfc0 anMWBYtyn43FUqyvJShpYkugcJsSVlvSIXBPLCYs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shengjiu Wang , Mathieu Poirier , Sasha Levin Subject: [PATCH 5.19 0907/1157] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Date: Mon, 15 Aug 2022 20:04:23 +0200 Message-Id: <20220815180515.735164159@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Shengjiu Wang [ Upstream commit abe13e9a561d6b3e82b21362c0d6dd3ecd8a5b13 ] There is no mutex protection for rpmsg_eptdev_open(), especially for eptdev->ept read and write operation. It may cause issues when multiple instances call rpmsg_eptdev_open() in parallel,the return state may be success or EBUSY. Fixes: 964e8bedd5a1 ("rpmsg: char: Return an error if device already open") Signed-off-by: Shengjiu Wang Link: https://lore.kernel.org/r/1653104105-16779-1-git-send-email-shengjiu.= wang@nxp.com Signed-off-by: Mathieu Poirier Signed-off-by: Sasha Levin --- drivers/rpmsg/rpmsg_char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index b6183d4f62a2..4f2189111494 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -120,8 +120,11 @@ static int rpmsg_eptdev_open(struct inode *inode, stru= ct file *filp) struct rpmsg_device *rpdev =3D eptdev->rpdev; struct device *dev =3D &eptdev->dev; =20 - if (eptdev->ept) + mutex_lock(&eptdev->ept_lock); + if (eptdev->ept) { + mutex_unlock(&eptdev->ept_lock); return -EBUSY; + } =20 get_device(dev); =20 @@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, str= uct file *filp) if (!ept) { dev_err(dev, "failed to open %s\n", eptdev->chinfo.name); put_device(dev); + mutex_unlock(&eptdev->ept_lock); return -EINVAL; } =20 eptdev->ept =3D ept; filp->private_data =3D eptdev; + mutex_unlock(&eptdev->ept_lock); =20 return 0; } --=20 2.35.1