Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2992308rwb; Mon, 15 Aug 2022 15:39:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DKK9BY3jwe+o5hThwhOh5DgnYsseRI0jgU0HszU/iWfyEgklKh3IiYUYpuuB5VywG0yHt X-Received: by 2002:a17:907:7355:b0:738:5087:9a64 with SMTP id dq21-20020a170907735500b0073850879a64mr4505526ejc.295.1660603176484; Mon, 15 Aug 2022 15:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660603176; cv=none; d=google.com; s=arc-20160816; b=Lhcf/nkx0RvHi4JJetA4CdHISzW0JJ5qKOo0tR+GoGk3nj0ThCa5IBWjo8gfz7nkUT p3mX61/Sk9yi9YK/ighK3x6hFPOoBM1imUwrQ/WcBRMFd4a9oCSSiDhqhluTMY+5IYQH jX/5uZJHUteKdVXOur3WgYdf4YYNutcjNQ9pBMQsGVBL4pzt98Eh1ql5mJUh7oTsjI1G m3vu7jWARU7n6VhSt1sQF28rImSbR2NGcwksa50seJT9EE6MNm/V83HpcQklPifEzlKr vZwP7aBw3y6A8wxz+tU4zDj6hWD6aQ3j9qgOcITrvFnWSx03JH324UU2g0aIU5x4GPUG B/EQ== 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=PWwF0fYOmVdxx/0ObwbN+HoT09OugwH7dFWBJRCFXjRX/0bRjgKLe3nheevhjPpahs fWmxN+iA6RhpLPjOPkDjjh1nRqzzH1phnoSFC6Qed0Z7XOF477eRVyG6o6PQUM72aIMC UNmH9nwMXw6PwXAgOyZwmnIfQDKVCZ3mk4GNfPhDLWUfN5NKsHqN0Ffa2Nrfo4ZF4wR8 9Gnc7a367atKQKUNr59Y1VSWFc1GFCyu/FW8wg54iXDsxU9awwSeFGZhBD0WkOZwxZjg 2XiCi5BzHSf+m3kPrN2VKIr7vp88n6A5/tq8qDzFhFmEGp59iPZqI8DEXxYsST6cAxSK qsDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IeJJ0VjE; 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 ds1-20020a170907724100b00731148bc546si9981534ejc.38.2022.08.15.15.39.01; Mon, 15 Aug 2022 15:39:36 -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=IeJJ0VjE; 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 S1350499AbiHOWgk (ORCPT + 99 others); Mon, 15 Aug 2022 18:36:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350976AbiHOW1W (ORCPT ); Mon, 15 Aug 2022 18:27:22 -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 F401512A54C; Mon, 15 Aug 2022 12:45:54 -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 AB6E8B80EA7; Mon, 15 Aug 2022 19:45:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01708C433D6; Mon, 15 Aug 2022 19:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592752; bh=6ACOjqndLQ3Ih+OOe30yxTbZi6HcEEwp2lVFUhXVsv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IeJJ0VjE2v8vHYmDKiQrD39UAj00laEBFlQ02FjbR7uiYb1ZOCb0oWPzQRqyVzMGH ubE4U/qc7C3RNBJzqtmvQbtgiyFcoqE9RPPp7kwbfLog+GkJ6dJWlwZVOorf1UnqQ1 PS73dldZaDuQ241CxNxiglJ07MdYKacfdMJRl/KE= 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.18 0840/1095] rpmsg: char: Add mutex protection for rpmsg_eptdev_open() Date: Mon, 15 Aug 2022 20:03:59 +0200 Message-Id: <20220815180504.090182580@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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