From patchwork Sun Aug 30 14:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Kumar Singh X-Patchwork-Id: 261760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE844C433E6 for ; Sun, 30 Aug 2020 14:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88E5B20707 for ; Sun, 30 Aug 2020 14:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="B5/piHQs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbgH3OlQ (ORCPT ); Sun, 30 Aug 2020 10:41:16 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:43765 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726887AbgH3Oj0 (ORCPT ); Sun, 30 Aug 2020 10:39:26 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1598798365; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=YsxKBIKWbk9+hM99fxRravC3T6qT3Gy/CmU0L8pLAw0=; b=B5/piHQs/yOV17JkIrdbyM0F76xPkC0NVQHkk/rhJhZlaAacks50Kab50p36BlfyId1UA5jV Wm6Uqbet/+XxYvysBXraAhMVp3BcTWoKvFK5we6AJsx1KrujQ/rfZnYob9TVBBLz0PQ2HDCn xg5ro9Bftc/9HGFF285I4PtB93Y= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyJiZjI2MiIsICJuZXRkZXZAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n04.prod.us-east-1.postgun.com with SMTP id 5f4bb9f2c4154e1df2124dfe (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sun, 30 Aug 2020 14:38:42 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 83F08C43395; Sun, 30 Aug 2020 14:38:41 +0000 (UTC) Received: from deesin-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: deesin) by smtp.codeaurora.org (Postfix) with ESMTPSA id 36322C433C6; Sun, 30 Aug 2020 14:38:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 36322C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=deesin@codeaurora.org From: Deepak Kumar Singh To: bjorn.andersson@linaro.org, clew@codeaurora.org Cc: mathieu.poirier@linaro.org, linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Manivannan Sadhasivam , Carl Huang , Necip Fazil Yildiran , netdev@vger.kernel.org (open list:NETWORKING [GENERAL]) Subject: [PATCH V1 1/4] net: qrtr: Do not send packets before hello negotiation Date: Sun, 30 Aug 2020 20:08:09 +0530 Message-Id: <1598798292-5971-2-git-send-email-deesin@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598798292-5971-1-git-send-email-deesin@codeaurora.org> References: <1598798292-5971-1-git-send-email-deesin@codeaurora.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Chris Lew There is a race where broadcast packets can be sent to a node that has not sent the hello message to the remote processor. This breaks the protocol expectation. Add a status variable to track when the hello packet has been sent. An alternative solution attempted was to remove the nodes from the broadcast list until the hello packet is sent. This is not a valid solution because hello messages are broadcasted if the ns is restarted or started late. There needs to be a status variable separate from the broadcast list. --- net/qrtr/qrtr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 90c558f8..d9858a1 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -115,6 +115,7 @@ static DEFINE_MUTEX(qrtr_port_lock); * @ep: endpoint * @ref: reference count for node * @nid: node id + * @hello_sent: hello packet sent to endpoint * @qrtr_tx_flow: tree of qrtr_tx_flow, keyed by node << 32 | port * @qrtr_tx_lock: lock for qrtr_tx_flow inserts * @rx_queue: receive queue @@ -125,6 +126,7 @@ struct qrtr_node { struct qrtr_endpoint *ep; struct kref ref; unsigned int nid; + atomic_t hello_sent; struct radix_tree_root qrtr_tx_flow; struct mutex qrtr_tx_lock; /* for qrtr_tx_flow */ @@ -335,6 +337,11 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, int rc = -ENODEV; int confirm_rx; + if (!atomic_read(&node->hello_sent) && type != QRTR_TYPE_HELLO) { + kfree_skb(skb); + return rc; + } + confirm_rx = qrtr_tx_wait(node, to->sq_node, to->sq_port, type); if (confirm_rx < 0) { kfree_skb(skb); @@ -370,6 +377,8 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, * confirm_rx flag if we dropped this one */ if (rc && confirm_rx) qrtr_tx_flow_failed(node, to->sq_node, to->sq_port); + if (!rc && type == QRTR_TYPE_HELLO) + atomic_inc(&node->hello_sent); return rc; } @@ -563,6 +572,7 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid) skb_queue_head_init(&node->rx_queue); node->nid = QRTR_EP_NID_AUTO; node->ep = ep; + atomic_set(&node->hello_sent, 0); INIT_RADIX_TREE(&node->qrtr_tx_flow, GFP_KERNEL); mutex_init(&node->qrtr_tx_lock); @@ -854,6 +864,8 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, mutex_lock(&qrtr_node_lock); list_for_each_entry(node, &qrtr_all_nodes, item) { + if (node->nid == QRTR_EP_NID_AUTO) + continue; skbn = skb_clone(skb, GFP_KERNEL); if (!skbn) break; From patchwork Sun Aug 30 14:38:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Kumar Singh X-Patchwork-Id: 261761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA570C433E6 for ; Sun, 30 Aug 2020 14:40:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C58A520707 for ; Sun, 30 Aug 2020 14:40:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="sdi9d+vU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbgH3Oj6 (ORCPT ); Sun, 30 Aug 2020 10:39:58 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:50661 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727015AbgH3Oje (ORCPT ); Sun, 30 Aug 2020 10:39:34 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1598798373; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=63k57UM9aKfRQtY/EP8nhwKq5dGcYV4cF/NPx0Pmcm0=; b=sdi9d+vUk/dlIzn4y8sRdxdPYwkNiziMnsnWdgv6jnxOV7O7Y4cu5zo5dlRF4C7WNwNLBqfH LeqtXwklvOHr5eR39LeoeuVL5nURm04vigo5TYXlUAfSwDYrODLDalNinRBOS7qYYV94wdnH MXNoKAcznIBXptxqA6cCvsaoy34= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyJiZjI2MiIsICJuZXRkZXZAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-east-1.postgun.com with SMTP id 5f4bba03f4f3e646136427d3 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sun, 30 Aug 2020 14:38:59 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 076CBC433CA; Sun, 30 Aug 2020 14:38:59 +0000 (UTC) Received: from deesin-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: deesin) by smtp.codeaurora.org (Postfix) with ESMTPSA id A8D5FC433C6; Sun, 30 Aug 2020 14:38:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A8D5FC433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=deesin@codeaurora.org From: Deepak Kumar Singh To: bjorn.andersson@linaro.org, clew@codeaurora.org Cc: mathieu.poirier@linaro.org, linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Arun Kumar Neelakantam , "David S. Miller" , Jakub Kicinski , Manivannan Sadhasivam , Carl Huang , Necip Fazil Yildiran , netdev@vger.kernel.org (open list:NETWORKING [GENERAL]) Subject: [PATCH V1 4/4] net: qrtr: Check function pointer before calling Date: Sun, 30 Aug 2020 20:08:12 +0530 Message-Id: <1598798292-5971-5-git-send-email-deesin@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1598798292-5971-1-git-send-email-deesin@codeaurora.org> References: <1598798292-5971-1-git-send-email-deesin@codeaurora.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arun Kumar Neelakantam sk_error_report callback function called without validating cause the NULL pointer dereference. Validate function pointer before using for error report. --- net/qrtr/qrtr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index e2dd38e..01cabd3 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -786,7 +786,8 @@ static void qrtr_reset_ports(void) sock_hold(&ipc->sk); ipc->sk.sk_err = ENETRESET; - ipc->sk.sk_error_report(&ipc->sk); + if (ipc->sk.sk_error_report) + ipc->sk.sk_error_report(&ipc->sk); sock_put(&ipc->sk); } mutex_unlock(&qrtr_port_lock);