Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3113698rwb; Mon, 15 Aug 2022 18:26:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR44rSO1HCrlImoeO1k5n3QtpmnhZBLN2ikFF/1xpx82MlwwFsxvCf/LVr3tAsAHwBOQSFbN X-Received: by 2002:a05:6a00:2352:b0:52e:f0bd:981e with SMTP id j18-20020a056a00235200b0052ef0bd981emr18250412pfj.28.1660613185824; Mon, 15 Aug 2022 18:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613185; cv=none; d=google.com; s=arc-20160816; b=vStCiI57n2NblO+jHMliXaXlFXVkO4keC7SiE6UlV6568SaODcfCVatZnppCq29Gtb pWraaMykQLvlj40+J5PCV2RTSEuBRZpcZ9hfj/V/zmYm9YSQcHJbYQ1U3/ewlcpM37kO HBiW/Q9bLBE9+C/ng5kPqWLyHJqRKzcg96Ay1Ln0Th/G/Fe2vSFq1dzMSo5nGu5GVPHn hLpT6fT7vC0CAMRmtGSxOA+myHevb0bui8FWlavNpNtHFysX/ccE9I6VfYavGwsmHJn1 PhsCMAH98PkvuCgX6Z8kSueDGLEPKyQPDYRvMfk2ahwVlOzi9n7JkWejzwcnSiDGl3bs tiog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N5B6Ma07scVnvANkflDqkpczgo0YT6+Qj2DDJ+xs8es=; b=ghm61JhdFt2EyedmrD7yRRpIHAOzmDwZhec1UM0zr4oWWEZjBrfJhpdwywGOXCYsYh t/hBQ/oobIB3WSDIwpLk2RXVlFGHL/NpKjiP6m61MUi0+dtOj2y6Q3SLHmV13GjxNIHY ZRD71G5Dnc3DnyGDh09p78Fx/74XqgFp2LlEerZ18uLTz29WL215/JlRszP1j5suRG3e 3ENWFiLZFD2x1kwbpugaXs6BUsrQ6woBiZEufKFOl2v1rTO6ImZ3VlaJNM00NQyuVXoO MZ4tNsq/RFRaw+rB4VQBvoP5AMggE2Hhlvj7UuBSyyZmdTiVx7U1zOVjeZQJ3XePZ2KU ZYfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OwD2kaRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d20-20020a170902729400b001713d5d096esi12528207pll.14.2022.08.15.18.26.05; Mon, 15 Aug 2022 18:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OwD2kaRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244387AbiHPAix (ORCPT + 99 others); Mon, 15 Aug 2022 20:38:53 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, struct file *filp) struct rpmsg_device *rpdev = eptdev->rpdev; struct device *dev = &eptdev->dev; - if (eptdev->ept) + mutex_lock(&eptdev->ept_lock); + if (eptdev->ept) { + mutex_unlock(&eptdev->ept_lock); return -EBUSY; + } get_device(dev); @@ -137,11 +140,13 @@ static int rpmsg_eptdev_open(struct inode *inode, struct 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; } eptdev->ept = ept; filp->private_data = eptdev; + mutex_unlock(&eptdev->ept_lock); return 0; } -- 2.35.1