From patchwork Wed Oct 19 08:24:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp295989wrs; Wed, 19 Oct 2022 05:26:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OpgW9Wt27r4DrH7KJXprekEeuvHRxkrJIw9OLbR0+T+WRymfI1UhAvGHx2ooFGtmaWNLk X-Received: by 2002:a05:6402:1052:b0:459:2c49:1aed with SMTP id e18-20020a056402105200b004592c491aedmr7181079edu.212.1666182402332; Wed, 19 Oct 2022 05:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182402; cv=none; d=google.com; s=arc-20160816; b=uZh6V8UO1g1F/g3LwZYa6P2SKo5QPCjuNgkr4jUjo0vxn9OtgwLehoi9TXvK4ChUIi /uVKoLbOqoVmb/ulBjUpOQeHdIJCgyHc23k62mUN/9OHKt8s04hz3c/JS5Kn2Ecw0Wju YnRkQRug53K8k5PiBEun+r/M/qxkvX2ZfUnOahdXS1tHwU80maMxfqCqe917MI7VMA1Q 0NFyLO6CYJO7LJQ04hR5uqTi4+2sFbCktdwh+3P14Q2FcF9ddpSRODs8ke0DFQV7GyYc 3q+zYPBNUvKJfxSnEkCspIHHGcj8FN6EhfOb/m39SZ80JtjohmzUUdD0l7ZrHYjMlHiV 1sMQ== 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=nFsu5FV8m6N+3OKJuHCbMBVP6my+9BXKTr7NZGTEhvC6A9XrY977h5kTzmuo4Tq156 Vh6PmoP3V9SVnd0fo/YEKYjwBEXj2drMl99u7RwGH7vfEUi993FQyxwklPLZU4csdehI 2/bhJYHbMWMjMdPFVtHonwAhsA0oz0VJ3pwYQ4JV3vv+0I0TZ4CfoFfsxP5f48aLoy5s WiShq4SWig2ydgiuxVCu9aw3QzpdObZ5bLSY/VhtnQX7KFku/Ya0Zy9V/mtvoJVl2gDB q9oEMe2sn5mKpK19owrPptG7fMPmAorF3n3PUChIenYZiu04DT8sdhlYy2D9j156s6dz sdug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=egz38TU6; 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 dn16-20020a17090794d000b00730870cb4b6si11116347ejc.621.2022.10.19.05.26.09; Wed, 19 Oct 2022 05:26:42 -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=egz38TU6; 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 S231796AbiJSMRN (ORCPT + 99 others); Wed, 19 Oct 2022 08:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiJSMQ5 (ORCPT ); Wed, 19 Oct 2022 08:16:57 -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 3B9B4192BAB; Wed, 19 Oct 2022 04:52:42 -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 7B967B82301; Wed, 19 Oct 2022 08:45:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE4A1C433D6; Wed, 19 Oct 2022 08:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169122; bh=v/ymPpgTxvo03kcno91Ec+SWdJWekcA1Tf7hofUOme4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=egz38TU6EI7ktpxMkD9+/9ilebu5b1D/K6uAmNTk0eodL01smbSuWhykSiigcdFIj MIU7OUFyzV6EMMlW6OodF2sFWoT5ZfvjF3g5Jw4mTjHJ8Cd9nds9d5tOnBliYgQ+R9 xF7EH5xqNNjio12dN8WENFPW//SCwoBliD34g8iM= 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 6.0 166/862] rpmsg: char: Avoid double destroy of default endpoint Date: Wed, 19 Oct 2022 10:24:13 +0200 Message-Id: <20221019083257.311883827@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747118878825874621?= X-GMAIL-MSGID: =?utf-8?q?1747118878825874621?= 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);