From patchwork Sat Oct 22 07:20:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7248 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1091368wrr; Sat, 22 Oct 2022 00:50:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41IovdUN2DZrv5+v8rn/XNuEAvzKr7KbqMItvD9wwpj1gAKwv4oWJFGON3ecUmfXoz7s8K X-Received: by 2002:a17:902:c612:b0:186:8376:208d with SMTP id r18-20020a170902c61200b001868376208dmr5104541plr.89.1666425024564; Sat, 22 Oct 2022 00:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425024; cv=none; d=google.com; s=arc-20160816; b=h1C9s5zdfC5gaWiyFkpId0snCYsyoG8GfoKy09bEBUitPU+RxkPymtGMfGvBv2gUH7 3LjpELbaUeftSGZbMvvcHJPM0oZy0ZlOieXaalxMqYRkkBUB2VTaW/gmixSg+EuzSJHi nqcLsplawm+SbK2Ff2rQMn7sH7WEhiZTjL4EeeFKLyvKFNex70MMxyynBMU72zQRXHP+ 9y/HCl17fkcAys3m72kF2aer5oZOXQEs14t/R/iWQUAWZFYpLfIF4WnlBuMZF1q36+up sha/4B2/azzDnoFLnvNb20T9VX0oM7PBtuUToyxEHJFmeAduXACGw6br3/w/9Bla/fhQ AIYQ== 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=QZKNLBwoFHC2sEhBNc6rWUygaOHlhYxYFQiN1k42kHw=; b=rKd2TsogiHC/ckbZSmYb60y8YLmHhl1XHHH0mgQzZmkoxK1k6IRF5EFFLw4Be5Y2Vo Tew2cEHT8Uo+TyUkGMKX1KfkkKq2lkmaDl8fApLlb+WN23K2ctXQcJUo72jCYqqM4cy8 c37/+ntfp27oAFuJUi+w0Psxqb21MbFuRJiWIhhcDAoETplx+HxbAN92cK4NTHP3LscJ DPg90lEmio3yujG54qRjTVI/76MLRsjMdpQHdNFtqWaZ8g5TRoEstoY4L1zqAGCJJdnJ 0ymSP4934+tHKS2fV3jQsuYtoa2wKDcgDERjFeSvNuZ/VZuqgUptjg+ZzpmmWudH3QiJ a49g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dZASHyKY; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a170902db0100b0017840d9d42esi28136728plx.582.2022.10.22.00.50.11; Sat, 22 Oct 2022 00:50:24 -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=dZASHyKY; 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 S231557AbiJVHtx (ORCPT + 99 others); Sat, 22 Oct 2022 03:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231528AbiJVHsk (ORCPT ); Sat, 22 Oct 2022 03:48:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0B1170DEE; Sat, 22 Oct 2022 00:45:23 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1FFCB60B81; Sat, 22 Oct 2022 07:40:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FE78C433D6; Sat, 22 Oct 2022 07:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424458; bh=v/ymPpgTxvo03kcno91Ec+SWdJWekcA1Tf7hofUOme4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dZASHyKYh38l+fHIRIsbIwv4G4/GwxI77btu0Jr4FsJx4YD4nlbKBq6W+r6Yo10LK Conf41P4RiNEnSMK/1KCW845jPlAUAcjAdvUWFi6FX1JnEEgoUKLUY4YqzzC0qmoxT nDj6cwTXrCNp17tMw0ekOVWWKD7GNMPmM6SnpemA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shengjiu Wang , Arnaud Pouliquen , Peng Fan , Mathieu Poirier Subject: [PATCH 5.19 153/717] rpmsg: char: Avoid double destroy of default endpoint Date: Sat, 22 Oct 2022 09:20:32 +0200 Message-Id: <20221022072442.508885436@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373286944096907?= X-GMAIL-MSGID: =?utf-8?q?1747373286944096907?= From: Shengjiu Wang commit 467233a4ac29b215d492843d067a9f091e6bf0c5 upstream. The rpmsg_dev_remove() in rpmsg_core is the place for releasing this default endpoint. So need to avoid destroying the default endpoint in rpmsg_chrdev_eptdev_destroy(), this should be the same as rpmsg_eptdev_release(). Otherwise there will be double destroy issue that ept->refcount report warning: refcount_t: underflow; use-after-free. Call trace: refcount_warn_saturate+0xf8/0x150 virtio_rpmsg_destroy_ept+0xd4/0xec rpmsg_dev_remove+0x60/0x70 The issue can be reproduced by stopping remoteproc before closing the /dev/rpmsgX. Fixes: bea9b79c2d10 ("rpmsg: char: Add possibility to use default endpoint of the rpmsg device") Signed-off-by: Shengjiu Wang Reviewed-by: Arnaud Pouliquen Reviewed-by: Peng Fan Cc: stable Link: https://lore.kernel.org/r/1663725523-6514-1-git-send-email-shengjiu.wang@nxp.com Signed-off-by: Mathieu Poirier Signed-off-by: Greg Kroah-Hartman --- drivers/rpmsg/rpmsg_char.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -76,7 +76,9 @@ int rpmsg_chrdev_eptdev_destroy(struct d mutex_lock(&eptdev->ept_lock); if (eptdev->ept) { - rpmsg_destroy_ept(eptdev->ept); + /* The default endpoint is released by the rpmsg core */ + if (!eptdev->default_ept) + rpmsg_destroy_ept(eptdev->ept); eptdev->ept = NULL; } mutex_unlock(&eptdev->ept_lock);