Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3406308rwa; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7+j+yUZV6FEM5r26weCJYWXeQCtVUUjfPl4uiWwfsVYBeba0EWZmhWAGfWfIAR5OPYb7w9 X-Received: by 2002:a17:90a:9383:b0:1f4:fd59:7e47 with SMTP id q3-20020a17090a938300b001f4fd597e47mr2916282pjo.172.1661253721098; Tue, 23 Aug 2022 04:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253721; cv=none; d=google.com; s=arc-20160816; b=K4i3EGYwfcQd8GSCv/VeasBhQXatxoPxivOtVgG3u0H/NtWZra0eQYMNiwJ/SY7Wln Wvmvt9OcyGn+NF4v2EyQwR5olZS9UcSqXHFlndKiNztNHHIgb1tgONoaTKJuWqaTyWJS Y2V7wtzEKGkwbKwxZVzx4IQSouz/mT8KpCqoyMSKb8K9NgUzaqc4F17edt4n1j3OavLG cxaYz9t0BxG26fq78OD6eFotcpblfmKx56ljvWgZHfePtlJmkfqkOTgAIHhxSgUwvrJ8 JN0dZ5IddUMK12OT6zK+e3s9iTzIeQX05NQrqGsiyixPJKrH5qKsx3pp2lVPNWoE3V5x Qz2w== 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=Bh+o++BgiQgpnYkRUz3NFmfojFAI93GEmHZiJ8SZrXQ=; b=yNNwBE6k51xkj4bcJSjvuHqztUMZho8iis3UsKP2FYBAsTdLWXvRg46Pvo2Xw1rVB8 AJe1Ym/3l6wJQOxCrE3gTYHSYshdos6Y016UxxTZX4lHvkQZMNuJL1rDxdMOZPcvt35S dJdFvBnfB4DHcPJLqSqYfhijp9ubWDJ+9KUcifcnQcZXnkSkTxcjfjDmCpTg4s2jWuxz bC1luBTdj5FJWv5B6XvWDsemlb4M4Q3arJg9O5IgS4Wf0lQm3eS2P2Lx3+sdepMuaT0g KCY/VmMxZAZCbC64KIwRgYEpzAT92lP5F0LYV8EGtRB9VmaiJKCZwb1EB/dPHjXLVsEy obxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EDc39UpL; 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 g21-20020a170902e39500b0016d47244b85si13209706ple.327.2022.08.23.04.21.50; Tue, 23 Aug 2022 04:22:01 -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=EDc39UpL; 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 S1354097AbiHWKQo (ORCPT + 99 others); Tue, 23 Aug 2022 06:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352327AbiHWKH0 (ORCPT ); Tue, 23 Aug 2022 06:07:26 -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 D10453D597; Tue, 23 Aug 2022 01:53:55 -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 4D579B81C1C; Tue, 23 Aug 2022 08:53:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9878C433C1; Tue, 23 Aug 2022 08:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244833; bh=w2DxzNtSYjlJOxq37XuAFn4T5Dj04nIDkze7xtUTYpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EDc39UpLcRBWhDuMzNyyw2pXjUSvqBhPHYxqp4v7Sjy7iyyJHhPOr9gq3Gh7qxMSl N8oppXNu6eDzH8g2bhkEzfV2IQOCZa4aQf11xPHDrzb0Gp8xH5eOWOz7AlNxvFyLdk kf8SuRHTiia9d5WFtxUWZosHft4ZzSjmz123JQ4Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxim Kochetkov , Hemant Kumar , Manivannan Sadhasivam , Loic Poulain , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 159/244] net: qrtr: start MHI channel after endpoit creation Date: Tue, 23 Aug 2022 10:25:18 +0200 Message-Id: <20220823080104.499836386@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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: Maxim Kochetkov [ Upstream commit 68a838b84effb7b57ba7d50b1863fc6ae35a54ce ] MHI channel may generates event/interrupt right after enabling. It may leads to 2 race conditions issues. 1) Such event may be dropped by qcom_mhi_qrtr_dl_callback() at check: if (!qdev || mhi_res->transaction_status) return; Because dev_set_drvdata(&mhi_dev->dev, qdev) may be not performed at this moment. In this situation qrtr-ns will be unable to enumerate services in device. --------------------------------------------------------------- 2) Such event may come at the moment after dev_set_drvdata() and before qrtr_endpoint_register(). In this case kernel will panic with accessing wrong pointer at qcom_mhi_qrtr_dl_callback(): rc = qrtr_endpoint_post(&qdev->ep, mhi_res->buf_addr, mhi_res->bytes_xferd); Because endpoint is not created yet. -------------------------------------------------------------- So move mhi_prepare_for_transfer_autoqueue after endpoint creation to fix it. Fixes: a2e2cc0dbb11 ("net: qrtr: Start MHI channels during init") Signed-off-by: Maxim Kochetkov Reviewed-by: Hemant Kumar Reviewed-by: Manivannan Sadhasivam Reviewed-by: Loic Poulain Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/qrtr/mhi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c index fa611678af05..49e7cab43d24 100644 --- a/net/qrtr/mhi.c +++ b/net/qrtr/mhi.c @@ -78,11 +78,6 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, struct qrtr_mhi_dev *qdev; int rc; - /* start channels */ - rc = mhi_prepare_for_transfer(mhi_dev); - if (rc) - return rc; - qdev = devm_kzalloc(&mhi_dev->dev, sizeof(*qdev), GFP_KERNEL); if (!qdev) return -ENOMEM; @@ -96,6 +91,13 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev, if (rc) return rc; + /* start channels */ + rc = mhi_prepare_for_transfer(mhi_dev); + if (rc) { + qrtr_endpoint_unregister(&qdev->ep); + return rc; + } + dev_dbg(qdev->dev, "Qualcomm MHI QRTR driver probed\n"); return 0; -- 2.35.1