Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2915447rwb; Mon, 15 Aug 2022 14:00:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/6QBZQ2kdfmaQK0oaD9SArjCK6zKkZN+SV3At/LIoY8Cf7E1EuXzaq3adM642zsl7F5WN X-Received: by 2002:a05:6a00:13a2:b0:52e:128a:23dd with SMTP id t34-20020a056a0013a200b0052e128a23ddmr18286791pfg.54.1660597212298; Mon, 15 Aug 2022 14:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597212; cv=none; d=google.com; s=arc-20160816; b=PaNw++1KZjHGtyCDodNkl9rtBRgh+XlTZ0a6LkJ2cCHD44qLcv/6MKoSiX7C/1OHRf 8THgt+r4WZkCn7x8DxxVLb4FjUAzrFhkjsdlQsQT/zGATmbDUuZxYm2BVWp+fgog6tMK k8VLOJidMmgLFUFhl9WbdwnlCIKYx5Ei2lujdcrL9RYJKg2Pl9YJkKp200cNQN1RpFn4 JMkg0muw/ZdpAq0dc8Wot/Ezz6sAEtUL2jazmzJGaKbyZW2IsCySZW/w8AVopijpryzc xP0VW+ouBgFJazQkx7HaubIz1bGaHFMJD/fOVRvUmGiGc+VPy/ZgMsTZdFXqwfA8l7UL yfwg== 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=kcyH59cCgpoMYFedXwlV3B+rUQwoSGcddZ4YSb7UaVM=; b=CGhxzL9uPsWKYvYmHs2rX7C5UDwLUU4P0s3YuigrNH9bCvKk/Tj4s1e/jsI813w9s4 4ahg0ckr7qNgNW19Q5qwvnWZIWtoWOuo0/CxQvvfV4gCOaZ5dc4UOdxah8g4kBub4taK kc0phaBLjlKpITMPSUDruJgkPCpnwWADDEkfILXNZy2Ejf6UlH+C3oStr4tIB/WtIuKs cuICRUDwsGvu0L2vD9ZbW7PA/RUarnsCFVQn3q1odf5SZOAlYPR0yp5mQ0s6os2P4kv2 blhgMlMGRt2b8DP2c8ylt4uQlkVOZtRqnWpDskAuM2NwiWBu5sY3fOkCb/F4zCZZHdV4 8ThA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0xu7Gb1N; 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 j12-20020a056a00174c00b0052c79a96579si13123758pfc.360.2022.08.15.14.00.01; Mon, 15 Aug 2022 14:00:12 -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=0xu7Gb1N; 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 S244537AbiHOTcM (ORCPT + 99 others); Mon, 15 Aug 2022 15:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344645AbiHOT1F (ORCPT ); Mon, 15 Aug 2022 15:27:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A71F95A3CA; Mon, 15 Aug 2022 11:42:53 -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 34656B810A2; Mon, 15 Aug 2022 18:42:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DD8EC433D6; Mon, 15 Aug 2022 18:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588970; bh=kqisEMR1dw40SEAe95IXg/m0xgPf6Z1t4GvyGIxY2Uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0xu7Gb1N8l6dFWTvcbynATkdbttLyU1SlTDRgi8H/t7Ri+qTWT7C67gM90TCcr+kB lBCUvJCVEycWpeyENIO+AduaSbaHm4XMiFRREMdLfxKVRup6yLutVE0TTKvibjibtg nADPVLrtt4DIFXQQdTu8Y8hOwj7HNffA1uypIfOI= 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.15 573/779] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Date: Mon, 15 Aug 2022 20:03:37 +0200 Message-Id: <20220815180401.816997752@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 49dd5a200998..88c985f9e73a 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -127,8 +127,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); @@ -136,11 +139,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