From patchwork Sun Jul 17 16:09:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920546 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24649C43334 for ; Sun, 17 Jul 2022 16:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbiGQQM0 (ORCPT ); Sun, 17 Jul 2022 12:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbiGQQMX (ORCPT ); Sun, 17 Jul 2022 12:12:23 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 706C413CD3 for ; Sun, 17 Jul 2022 09:12:22 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id b2so7108365plx.7 for ; Sun, 17 Jul 2022 09:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Faeb9WST+LXAKImiDS2N+PsjJjwyu4Jg+NnCwxRofSA=; b=oy1m4R4MV9w4C/yy5GzL/9QNzDYt7RyZ5wVYdAo+gUIjh+oP2HizIN039fiDSkrpXM Y5qVv7JVMf9R9XQ10+OQBl/qiy5C/gfHxN7oIpDhbXDOp+JyxLfiFl99LHuoLMaQwNeu G66mrY6Zxuut1SNThAuBSULmFXZYgbLq5VyS1nDSHTu4HT1wsP7n+4psRpBrH0V93VrM 4+cPAU5jpf8CGLrKnG26kcKjaAqR5CKas8/vn1VJM/nhlYEGvBnWFLmkfrvQdq76wQtj H1tFdKvCMg8DgGwZ3ASWyGGce6Xpxu4TVhmQtgEZDqUStzRSSNem2ztSUQVo4caF1van 7Q2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Faeb9WST+LXAKImiDS2N+PsjJjwyu4Jg+NnCwxRofSA=; b=oHatRT1S9VExmsyMaETbTumFT2NKmnc5aT8u/UyeoqPYgz707m8dWxyOen+/ss1nMh +dYq6WMnoNegce3AmJH+WvLRf0Qt0kzUfMg7O7ASiHVTea79qrU8DftE82yRABduvEsT FSRRggc9eIbQNd4H9+gYRtfAD5e3DM/Zvi4Ub1uSxQ8KhWK0WG2MglracYe18tW+TrvZ Xzuah18/GAUW+isloOYzYQ8V6qck2EL2OW+QSFXwFT2VMPvheslXx9a1Qxo0ey8Z9TnH Jn0FmlfxudaTHmlEMBitFUjEJ98e2XahA1zxkECB54habv2MlOyj9SBzCthsE/vVb6z1 rByw== X-Gm-Message-State: AJIora+mgFijyWnfbH9sxOkMyuk2ZZyRhxDaVZosvR0LisYspu12my5A gOo9yLug4Jfay6pyV+VsTNU= X-Google-Smtp-Source: AGRyM1sJYVtQ7sYX6+DEtVi/z3XioLiI9MwzD43rBqdBQpKPfSzOdE1wKsli15CyvZz7hSKooL0rSw== X-Received: by 2002:a17:903:32cb:b0:16c:3c8d:380a with SMTP id i11-20020a17090332cb00b0016c3c8d380amr23474228plr.108.1658074341749; Sun, 17 Jul 2022 09:12:21 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:21 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 1/8] amt: use workqueue for gateway side message handling Date: Sun, 17 Jul 2022 16:09:03 +0000 Message-Id: <20220717160910.19156-2-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are some synchronization issues(amt->status, amt->req_cnt, etc) if the interface is in gateway mode because gateway message handlers are processed concurrently. This applies a work queue for processing these messages instead of expanding the locking context. So, the purposes of this patch are to fix exist race conditions and to make gateway to be able to validate a gateway status more correctly. When the AMT gateway interface is created, it tries to establish to relay. The establishment step looks stateless, but it should be managed well. In order to handle messages in the gateway, it saves the current status(i.e. AMT_STATUS_XXX). This patch makes gateway code to be worked with a single thread. Now, all messages except the multicast are triggered(received or delay expired), and these messages will be stored in the event queue(amt->events). Then, the single worker processes stored messages asynchronously one by one. The multicast data message type will be still processed immediately. Now, amt->lock is only needed to access the event queue(amt->events) if an interface is the gateway mode. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - Use local_bh_disable() instead of rcu_read_lock_bh() in amt_membership_query_handler. - Fix using uninitialized variables. - Fix unexpectedly start the event after stopping. - Fix possible deadlock in amt_event_work(). - Add a limit variable in amt_event_work() to prevent infinite working. - Rename amt_queue_events() to amt_queue_event(). drivers/net/amt.c | 159 +++++++++++++++++++++++++++++++++++++++++----- include/net/amt.h | 20 ++++++ 2 files changed, 164 insertions(+), 15 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index be2719a3ba70..21104efd803f 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -900,6 +900,28 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel) } #endif +static bool amt_queue_event(struct amt_dev *amt, enum amt_event event, + struct sk_buff *skb) +{ + int index; + + spin_lock_bh(&amt->lock); + if (amt->nr_events >= AMT_MAX_EVENTS) { + spin_unlock_bh(&amt->lock); + return 1; + } + + index = (amt->event_idx + amt->nr_events) % AMT_MAX_EVENTS; + amt->events[index].event = event; + amt->events[index].skb = skb; + amt->nr_events++; + amt->event_idx %= AMT_MAX_EVENTS; + queue_work(amt_wq, &amt->event_wq); + spin_unlock_bh(&amt->lock); + + return 0; +} + static void amt_secret_work(struct work_struct *work) { struct amt_dev *amt = container_of(to_delayed_work(work), @@ -913,12 +935,8 @@ static void amt_secret_work(struct work_struct *work) msecs_to_jiffies(AMT_SECRET_TIMEOUT)); } -static void amt_discovery_work(struct work_struct *work) +static void amt_event_send_discovery(struct amt_dev *amt) { - struct amt_dev *amt = container_of(to_delayed_work(work), - struct amt_dev, - discovery_wq); - spin_lock_bh(&amt->lock); if (amt->status > AMT_STATUS_SENT_DISCOVERY) goto out; @@ -933,11 +951,19 @@ static void amt_discovery_work(struct work_struct *work) spin_unlock_bh(&amt->lock); } -static void amt_req_work(struct work_struct *work) +static void amt_discovery_work(struct work_struct *work) { struct amt_dev *amt = container_of(to_delayed_work(work), struct amt_dev, - req_wq); + discovery_wq); + + if (amt_queue_event(amt, AMT_EVENT_SEND_DISCOVERY, NULL)) + mod_delayed_work(amt_wq, &amt->discovery_wq, + msecs_to_jiffies(AMT_DISCOVERY_TIMEOUT)); +} + +static void amt_event_send_request(struct amt_dev *amt) +{ u32 exp; spin_lock_bh(&amt->lock); @@ -967,6 +993,17 @@ static void amt_req_work(struct work_struct *work) spin_unlock_bh(&amt->lock); } +static void amt_req_work(struct work_struct *work) +{ + struct amt_dev *amt = container_of(to_delayed_work(work), + struct amt_dev, + req_wq); + + if (amt_queue_event(amt, AMT_EVENT_SEND_REQUEST, NULL)) + mod_delayed_work(amt_wq, &amt->req_wq, + msecs_to_jiffies(100)); +} + static bool amt_send_membership_update(struct amt_dev *amt, struct sk_buff *skb, bool v6) @@ -2392,12 +2429,14 @@ static bool amt_membership_query_handler(struct amt_dev *amt, skb->pkt_type = PACKET_MULTICAST; skb->ip_summed = CHECKSUM_NONE; len = skb->len; + local_bh_disable(); if (__netif_rx(skb) == NET_RX_SUCCESS) { amt_update_gw_status(amt, AMT_STATUS_RECEIVED_QUERY, true); dev_sw_netstats_rx_add(amt->dev, len); } else { amt->dev->stats.rx_dropped++; } + local_bh_enable(); return false; } @@ -2688,6 +2727,38 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) return false; } +static void amt_gw_rcv(struct amt_dev *amt, struct sk_buff *skb) +{ + int type = amt_parse_type(skb); + int err = 1; + + if (type == -1) + goto drop; + + if (amt->mode == AMT_MODE_GATEWAY) { + switch (type) { + case AMT_MSG_ADVERTISEMENT: + err = amt_advertisement_handler(amt, skb); + break; + case AMT_MSG_MEMBERSHIP_QUERY: + err = amt_membership_query_handler(amt, skb); + if (!err) + return; + break; + default: + netdev_dbg(amt->dev, "Invalid type of Gateway\n"); + break; + } + } +drop: + if (err) { + amt->dev->stats.rx_dropped++; + kfree_skb(skb); + } else { + consume_skb(skb); + } +} + static int amt_rcv(struct sock *sk, struct sk_buff *skb) { struct amt_dev *amt; @@ -2719,8 +2790,12 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) err = true; goto drop; } - err = amt_advertisement_handler(amt, skb); - break; + if (amt_queue_event(amt, AMT_EVENT_RECEIVE, skb)) { + netdev_dbg(amt->dev, "AMT Event queue full\n"); + err = true; + goto drop; + } + goto out; case AMT_MSG_MULTICAST_DATA: if (iph->saddr != amt->remote_ip) { netdev_dbg(amt->dev, "Invalid Relay IP\n"); @@ -2738,11 +2813,12 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) err = true; goto drop; } - err = amt_membership_query_handler(amt, skb); - if (err) + if (amt_queue_event(amt, AMT_EVENT_RECEIVE, skb)) { + netdev_dbg(amt->dev, "AMT Event queue full\n"); + err = true; goto drop; - else - goto out; + } + goto out; default: err = true; netdev_dbg(amt->dev, "Invalid type of Gateway\n"); @@ -2780,6 +2856,46 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb) return 0; } +static void amt_event_work(struct work_struct *work) +{ + struct amt_dev *amt = container_of(work, struct amt_dev, event_wq); + struct sk_buff *skb; + u8 event; + int i; + + for (i = 0; i < AMT_MAX_EVENTS; i++) { + spin_lock_bh(&amt->lock); + if (amt->nr_events == 0) { + spin_unlock_bh(&amt->lock); + return; + } + event = amt->events[amt->event_idx].event; + skb = amt->events[amt->event_idx].skb; + amt->events[amt->event_idx].event = AMT_EVENT_NONE; + amt->events[amt->event_idx].skb = NULL; + amt->nr_events--; + amt->event_idx++; + amt->event_idx %= AMT_MAX_EVENTS; + spin_unlock_bh(&amt->lock); + + switch (event) { + case AMT_EVENT_RECEIVE: + amt_gw_rcv(amt, skb); + break; + case AMT_EVENT_SEND_DISCOVERY: + amt_event_send_discovery(amt); + break; + case AMT_EVENT_SEND_REQUEST: + amt_event_send_request(amt); + break; + default: + if (skb) + kfree_skb(skb); + break; + } + } +} + static int amt_err_lookup(struct sock *sk, struct sk_buff *skb) { struct amt_dev *amt; @@ -2867,6 +2983,8 @@ static int amt_dev_open(struct net_device *dev) amt->ready4 = false; amt->ready6 = false; + amt->event_idx = 0; + amt->nr_events = 0; err = amt_socket_create(amt); if (err) @@ -2892,6 +3010,8 @@ static int amt_dev_stop(struct net_device *dev) struct amt_dev *amt = netdev_priv(dev); struct amt_tunnel_list *tunnel, *tmp; struct socket *sock; + struct sk_buff *skb; + int i; cancel_delayed_work_sync(&amt->req_wq); cancel_delayed_work_sync(&amt->discovery_wq); @@ -2904,6 +3024,15 @@ static int amt_dev_stop(struct net_device *dev) if (sock) udp_tunnel_sock_release(sock); + cancel_work_sync(&amt->event_wq); + for (i = 0; i < AMT_MAX_EVENTS; i++) { + skb = amt->events[i].skb; + if (skb) + kfree_skb(skb); + amt->events[i].event = AMT_EVENT_NONE; + amt->events[i].skb = NULL; + } + amt->ready4 = false; amt->ready6 = false; amt->req_cnt = 0; @@ -3146,8 +3275,8 @@ static int amt_newlink(struct net *net, struct net_device *dev, INIT_DELAYED_WORK(&amt->discovery_wq, amt_discovery_work); INIT_DELAYED_WORK(&amt->req_wq, amt_req_work); INIT_DELAYED_WORK(&amt->secret_wq, amt_secret_work); + INIT_WORK(&amt->event_wq, amt_event_work); INIT_LIST_HEAD(&amt->tunnel_list); - return 0; err: dev_put(amt->stream_dev); @@ -3280,7 +3409,7 @@ static int __init amt_init(void) if (err < 0) goto unregister_notifier; - amt_wq = alloc_workqueue("amt", WQ_UNBOUND, 1); + amt_wq = alloc_workqueue("amt", WQ_UNBOUND, 0); if (!amt_wq) { err = -ENOMEM; goto rtnl_unregister; diff --git a/include/net/amt.h b/include/net/amt.h index 0e40c3d64fcf..08fc30cf2f34 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -78,6 +78,15 @@ enum amt_status { #define AMT_STATUS_MAX (__AMT_STATUS_MAX - 1) +/* Gateway events only */ +enum amt_event { + AMT_EVENT_NONE, + AMT_EVENT_RECEIVE, + AMT_EVENT_SEND_DISCOVERY, + AMT_EVENT_SEND_REQUEST, + __AMT_EVENT_MAX, +}; + struct amt_header { #if defined(__LITTLE_ENDIAN_BITFIELD) u8 type:4, @@ -292,6 +301,12 @@ struct amt_group_node { struct hlist_head sources[]; }; +#define AMT_MAX_EVENTS 16 +struct amt_events { + enum amt_event event; + struct sk_buff *skb; +}; + struct amt_dev { struct net_device *dev; struct net_device *stream_dev; @@ -308,6 +323,7 @@ struct amt_dev { struct delayed_work req_wq; /* Protected by RTNL */ struct delayed_work secret_wq; + struct work_struct event_wq; /* AMT status */ enum amt_status status; /* Generated key */ @@ -345,6 +361,10 @@ struct amt_dev { /* Used only in gateway mode */ u64 mac:48, reserved:16; + /* AMT gateway side message handler queue */ + struct amt_events events[AMT_MAX_EVENTS]; + u8 event_idx; + u8 nr_events; }; #define AMT_TOS 0xc0 From patchwork Sun Jul 17 16:09:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920547 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 507F0C433EF for ; Sun, 17 Jul 2022 16:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbiGQQM2 (ORCPT ); Sun, 17 Jul 2022 12:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbiGQQM0 (ORCPT ); Sun, 17 Jul 2022 12:12:26 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAFFC13CE6 for ; Sun, 17 Jul 2022 09:12:24 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id q13-20020a17090a304d00b001f1af9a18a2so1941648pjl.5 for ; Sun, 17 Jul 2022 09:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E18DipzlHTOPrZ1X/RxGRT5qcnFx2LP+FUY7Y7RSdQs=; b=BhAIVG+kWJEvDgTK17VfboQjIlRxEzi/ja7mZtmTV/+t/3E26Wb6PvaltvuTfD0KU4 3idlsp3pKbiGVkDgQt+/3zZSa7dYU31utTq1QZfI/1uPxv1QBxE5VgC3B5C/2xuGXYjB BHfeOJHQOJUU5HtkrlAP6hqY2qu/R7NZ9RLKJmbPvpacp+PmRFp+HpiH/b8XIuiTu1am hslfyIAvb21vcFdajvgmkLENjQiJ0CnBtmnHx1Sg7HC1Y8ggVNtmnOXIM7uvvGbPlyCT tnBfhwrM3qp5VN17Rd3Xfa8orb+b9CGuX6oO6JR2lYAihIZZyoUl7cj3AUyASi/v4c0G Xnfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E18DipzlHTOPrZ1X/RxGRT5qcnFx2LP+FUY7Y7RSdQs=; b=jcqPzsuMVUEx4sP7h3LEPKCzc7iAsmQXCnebECw4Y2UG2JWYPt0TADiuY0kGH9aKtV UDbjarqrXPRKrP6j/MbrwFzVcEhISwSEQoVejD6a4oMkiw6er430k7oUfQpQSJHwZ3gn A2OkeSq0DiiuBvlceukqj6Gy8LaYoV7pMLkZFGbvcK/Qtcsk0zE87vAGL2eSSaDbhBSc q1KDiDUvUf0ca5DAEZh07rMi3Aoau6HinlldVOng9b/USiqQCuvvg9D/UIaFELU5T8D8 qI8yjshL6XFHpvbNV8QXfbXH9YgYhgH8ga+YRfDt1pqK44zaT4xNRuI+Dz+K8ULqVO7S SW7Q== X-Gm-Message-State: AJIora/qYc6B1iemCNtaptUuJ3QVmIBiqY1XYK9LDc5GAZs3HCKWaApR dkIDbIRWSMIRi2yu+/Kz9W8= X-Google-Smtp-Source: AGRyM1tsOMMbEORPdKVcqXa3W+F74XBuzLftWgdQXAzgn1VuFdD2sfIqm7weFaWKBkIRbHbcW2StkA== X-Received: by 2002:a17:903:11c5:b0:16c:ece7:f687 with SMTP id q5-20020a17090311c500b0016cece7f687mr2412270plh.165.1658074344261; Sun, 17 Jul 2022 09:12:24 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:23 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 2/8] amt: remove unnecessary locks Date: Sun, 17 Jul 2022 16:09:04 +0000 Message-Id: <20220717160910.19156-3-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org By the previous patch, amt gateway handlers are changed to worked by a single thread. So, most locks for gateway are not needed. So, it removes. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 21104efd803f..42220d857f8a 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -577,8 +577,8 @@ static struct sk_buff *amt_build_igmp_gq(struct amt_dev *amt) return skb; } -static void __amt_update_gw_status(struct amt_dev *amt, enum amt_status status, - bool validate) +static void amt_update_gw_status(struct amt_dev *amt, enum amt_status status, + bool validate) { if (validate && amt->status >= status) return; @@ -600,14 +600,6 @@ static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, tunnel->status = status; } -static void amt_update_gw_status(struct amt_dev *amt, enum amt_status status, - bool validate) -{ - spin_lock_bh(&amt->lock); - __amt_update_gw_status(amt, status, validate); - spin_unlock_bh(&amt->lock); -} - static void amt_update_relay_status(struct amt_tunnel_list *tunnel, enum amt_status status, bool validate) { @@ -700,9 +692,7 @@ static void amt_send_discovery(struct amt_dev *amt) if (unlikely(net_xmit_eval(err))) amt->dev->stats.tx_errors++; - spin_lock_bh(&amt->lock); - __amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true); - spin_unlock_bh(&amt->lock); + amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true); out: rcu_read_unlock(); } @@ -937,18 +927,14 @@ static void amt_secret_work(struct work_struct *work) static void amt_event_send_discovery(struct amt_dev *amt) { - spin_lock_bh(&amt->lock); if (amt->status > AMT_STATUS_SENT_DISCOVERY) goto out; get_random_bytes(&amt->nonce, sizeof(__be32)); - spin_unlock_bh(&amt->lock); amt_send_discovery(amt); - spin_lock_bh(&amt->lock); out: mod_delayed_work(amt_wq, &amt->discovery_wq, msecs_to_jiffies(AMT_DISCOVERY_TIMEOUT)); - spin_unlock_bh(&amt->lock); } static void amt_discovery_work(struct work_struct *work) @@ -966,7 +952,6 @@ static void amt_event_send_request(struct amt_dev *amt) { u32 exp; - spin_lock_bh(&amt->lock); if (amt->status < AMT_STATUS_RECEIVED_ADVERTISEMENT) goto out; @@ -976,21 +961,18 @@ static void amt_event_send_request(struct amt_dev *amt) amt->ready4 = false; amt->ready6 = false; amt->remote_ip = 0; - __amt_update_gw_status(amt, AMT_STATUS_INIT, false); + amt_update_gw_status(amt, AMT_STATUS_INIT, false); amt->req_cnt = 0; goto out; } - spin_unlock_bh(&amt->lock); amt_send_request(amt, false); amt_send_request(amt, true); - spin_lock_bh(&amt->lock); - __amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true); + amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true); amt->req_cnt++; out: exp = min_t(u32, (1 * (1 << amt->req_cnt)), AMT_MAX_REQ_TIMEOUT); mod_delayed_work(amt_wq, &amt->req_wq, msecs_to_jiffies(exp * 1000)); - spin_unlock_bh(&amt->lock); } static void amt_req_work(struct work_struct *work) @@ -2386,12 +2368,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt, ihv3 = skb_pull(skb, sizeof(*iph) + AMT_IPHDR_OPTS); skb_reset_transport_header(skb); skb_push(skb, sizeof(*iph) + AMT_IPHDR_OPTS); - spin_lock_bh(&amt->lock); amt->ready4 = true; amt->mac = amtmq->response_mac; amt->req_cnt = 0; amt->qi = ihv3->qqic; - spin_unlock_bh(&amt->lock); skb->protocol = htons(ETH_P_IP); eth->h_proto = htons(ETH_P_IP); ip_eth_mc_map(iph->daddr, eth->h_dest); @@ -2411,12 +2391,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt, mld2q = skb_pull(skb, sizeof(*ip6h) + AMT_IP6HDR_OPTS); skb_reset_transport_header(skb); skb_push(skb, sizeof(*ip6h) + AMT_IP6HDR_OPTS); - spin_lock_bh(&amt->lock); amt->ready6 = true; amt->mac = amtmq->response_mac; amt->req_cnt = 0; amt->qi = mld2q->mld2q_qqic; - spin_unlock_bh(&amt->lock); skb->protocol = htons(ETH_P_IPV6); eth->h_proto = htons(ETH_P_IPV6); ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); From patchwork Sun Jul 17 16:09:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920548 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB1FEC433EF for ; Sun, 17 Jul 2022 16:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231938AbiGQQMb (ORCPT ); Sun, 17 Jul 2022 12:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbiGQQM2 (ORCPT ); Sun, 17 Jul 2022 12:12:28 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B8F013CD3 for ; Sun, 17 Jul 2022 09:12:27 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id f11so8632449pgj.7 for ; Sun, 17 Jul 2022 09:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PLhOnTBMd6RLNUqtsrx+gCZ1FA1A76mcTFjIVf9ITGE=; b=eU3vyp+232ASD+WaMdUUyDEgWgqo4Na6P4txFp9amiNMhKbvj8+KIQ4VXRX29v1Rk/ 716r4T5npSOIQXOgHyTqI7iRDS5RQgf2gRcuaJ7A3u3Kg+cDA6og5vVDXlJz5qnHffjh MyexgeWQisjsG8Fb+BDWxMPqmrWUdsVqWQYetl6p9J9WCpv20tjH3avb5MLmUd2ewQTi Q13j8kW/Ip9guy5oX2bSRfkzARCkK+UErKDC3RUwL42GaeX6Sa244IRUko2qBSHoA9xq hbEQMeyGPUiShW/rnRWdaEqmptJCUH6ha7ZU6FWXInR2RrBG9TUDDntzsnsIx6Si4CNT OjQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PLhOnTBMd6RLNUqtsrx+gCZ1FA1A76mcTFjIVf9ITGE=; b=fNb9L3mo5OrraPzqV6YChaMvfKH6LMBd8kut4d3nWvf1+ZdxnhrOFUc38uzO3oh3qs v8rhOLanVGuuKFDUX/5cY6kbfvZEr6UomYC3nzqu7IcwMReQe9XrCcfMWOveD8ltV8OD L6a3O7yzgl25cRE5k2U+8vjar6IgyFVI0WKVjiZrky0BCvJGACIwWuhugevwLL0vaD8G DiytoeakeVZe8YKM6H1QibJTYk/9/2GortCgWTAnt7T0bgAWSlxn0NwqxcudTh39XHHM 8oWMdXBMWB9JaFnStrLMFvi+rpkjz4mhc9usTscXIOm0Yiwx6wr3RspE/BtVV6YVLaD1 PzPw== X-Gm-Message-State: AJIora9rI3LP8fJfX1xFlgAjU8i3RkqyfeCSvWzyQu5i2fCvIly1v8R0 57inOthX/F7cXqdQO5BeE1zBt8W8ATg= X-Google-Smtp-Source: AGRyM1tY4JdeIOdj6R2Ynztyn1hUN6hWTX9yYiNIQAmkhZDYaD4w77XcXcSfT5LhIAYZ1wThWhbnDg== X-Received: by 2002:a05:6a00:162e:b0:52b:5909:fdfd with SMTP id e14-20020a056a00162e00b0052b5909fdfdmr6529187pfc.65.1658074346745; Sun, 17 Jul 2022 09:12:26 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:26 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 3/8] amt: use READ_ONCE() in amt module Date: Sun, 17 Jul 2022 16:09:05 +0000 Message-Id: <20220717160910.19156-4-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are some data races in the amt module. amt->ready4, amt->ready6, and amt->status can be accessed concurrently without locks. So, it uses READ_ONCE() and WRITE_ONCE(). Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 42220d857f8a..f0703284a1f1 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -584,7 +584,7 @@ static void amt_update_gw_status(struct amt_dev *amt, enum amt_status status, return; netdev_dbg(amt->dev, "Update GW status %s -> %s", status_str[amt->status], status_str[status]); - amt->status = status; + WRITE_ONCE(amt->status, status); } static void __amt_update_relay_status(struct amt_tunnel_list *tunnel, @@ -958,8 +958,8 @@ static void amt_event_send_request(struct amt_dev *amt) if (amt->req_cnt > AMT_MAX_REQ_COUNT) { netdev_dbg(amt->dev, "Gateway is not ready"); amt->qi = AMT_INIT_REQ_TIMEOUT; - amt->ready4 = false; - amt->ready6 = false; + WRITE_ONCE(amt->ready4, false); + WRITE_ONCE(amt->ready6, false); amt->remote_ip = 0; amt_update_gw_status(amt, AMT_STATUS_INIT, false); amt->req_cnt = 0; @@ -1239,7 +1239,8 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev) /* Gateway only passes IGMP/MLD packets */ if (!report) goto free; - if ((!v6 && !amt->ready4) || (v6 && !amt->ready6)) + if ((!v6 && !READ_ONCE(amt->ready4)) || + (v6 && !READ_ONCE(amt->ready6))) goto free; if (amt_send_membership_update(amt, skb, v6)) goto free; @@ -2368,7 +2369,7 @@ static bool amt_membership_query_handler(struct amt_dev *amt, ihv3 = skb_pull(skb, sizeof(*iph) + AMT_IPHDR_OPTS); skb_reset_transport_header(skb); skb_push(skb, sizeof(*iph) + AMT_IPHDR_OPTS); - amt->ready4 = true; + WRITE_ONCE(amt->ready4, true); amt->mac = amtmq->response_mac; amt->req_cnt = 0; amt->qi = ihv3->qqic; @@ -2391,7 +2392,7 @@ static bool amt_membership_query_handler(struct amt_dev *amt, mld2q = skb_pull(skb, sizeof(*ip6h) + AMT_IP6HDR_OPTS); skb_reset_transport_header(skb); skb_push(skb, sizeof(*ip6h) + AMT_IP6HDR_OPTS); - amt->ready6 = true; + WRITE_ONCE(amt->ready6, true); amt->mac = amtmq->response_mac; amt->req_cnt = 0; amt->qi = mld2q->mld2q_qqic; @@ -2898,7 +2899,7 @@ static int amt_err_lookup(struct sock *sk, struct sk_buff *skb) break; case AMT_MSG_REQUEST: case AMT_MSG_MEMBERSHIP_UPDATE: - if (amt->status >= AMT_STATUS_RECEIVED_ADVERTISEMENT) + if (READ_ONCE(amt->status) >= AMT_STATUS_RECEIVED_ADVERTISEMENT) mod_delayed_work(amt_wq, &amt->req_wq, 0); break; default: From patchwork Sun Jul 17 16:09:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920549 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF125C43334 for ; Sun, 17 Jul 2022 16:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231328AbiGQQMh (ORCPT ); Sun, 17 Jul 2022 12:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbiGQQMa (ORCPT ); Sun, 17 Jul 2022 12:12:30 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB47413CE0 for ; Sun, 17 Jul 2022 09:12:29 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id o15so9733392pjh.1 for ; Sun, 17 Jul 2022 09:12:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tskLN9RRTBYf0z1bjTfnQUZRCpE2NkGGXvIE/jPwV8I=; b=lZcNujBKhnReognLOX3uMRASdM3tJ4oZvoDmTqf9FHG9NcUCaoPTZ/VmwfhsJ2zl74 aAFWYPTmq6WBr7g+9U0/9kmps6ULNP0OOPAFe29xWzW7rd4SbV5QxCzLk+kBBvmi3RIE /fAUFcVQ/MMs0MHHMmI1mVvtb8aPu9JS/aG+o9Dh4dnJtTp4uJUiwSimdB5v9/n3kGFG m4fa8FmofERE5KgqG2JnnMuEf8YvVbJ3xgETKJlCzBT5im2xGmU0xlClvR0/7N6ht188 MagOhigIK9/C0rZCrGeAvMl3VOLe7Opn6+kZinpG9uRS188XIrdPLvqvgtSL71RU1oEu jOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tskLN9RRTBYf0z1bjTfnQUZRCpE2NkGGXvIE/jPwV8I=; b=GzdZYU/tdFPHldsjBYdKm/zO23OgkjprMdTniAvz+7f1ViwzqBTOLIgK+DGIAUnP/W qnWbAur1hfAmCdfFq6ujWofUJ2Y/XrSKYGidZ6r74UpLV9V22HNaMuPdXbf6n/RvBbPK 82djZwuhau2CsELruw6v1fcr9INavf2lql43KRt7V3B6891uaROg+Y3MvIjHeG73yQhG j0MYzFRog8vnJT8bs7fkBOIVv4g4YiAQbVBRMrAD08sZyMWCBi221clPk0Pcb5+ab9BW 9sD3qhwp9XD2m9zHiFilHI9mqzg15T63RmD6aeG2+p4v1KDomTp6bWqvdeGKA54KNQ4q Uhaw== X-Gm-Message-State: AJIora/+YpPlmDyDQYIRu1qo8vmYlzvusDsEs0pgwCcw/RnP2CuiTLbC rOufivzZYQEzU5Yg0s7Lu8M= X-Google-Smtp-Source: AGRyM1ukhO0qHfgBeqmLvOq5kNS6CAMmWUJvBQzazU8Kfv0I6v9CGldLIo737OxYtWcF/d4yWru6TA== X-Received: by 2002:a17:90a:7784:b0:1ef:c0fe:968c with SMTP id v4-20020a17090a778400b001efc0fe968cmr33582300pjk.26.1658074349234; Sun, 17 Jul 2022 09:12:29 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:28 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 4/8] amt: add missing regeneration nonce logic in request logic Date: Sun, 17 Jul 2022 16:09:06 +0000 Message-Id: <20220717160910.19156-5-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When AMT gateway starts sending a new request message, it should regenerate the nonce variable. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index f0703284a1f1..60e77e91a2b6 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -963,9 +963,13 @@ static void amt_event_send_request(struct amt_dev *amt) amt->remote_ip = 0; amt_update_gw_status(amt, AMT_STATUS_INIT, false); amt->req_cnt = 0; + amt->nonce = 0; goto out; } + if (!amt->req_cnt) + get_random_bytes(&amt->nonce, sizeof(__be32)); + amt_send_request(amt, false); amt_send_request(amt, true); amt_update_gw_status(amt, AMT_STATUS_SENT_REQUEST, true); From patchwork Sun Jul 17 16:09:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920550 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37064C433EF for ; Sun, 17 Jul 2022 16:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbiGQQMi (ORCPT ); Sun, 17 Jul 2022 12:12:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbiGQQMf (ORCPT ); Sun, 17 Jul 2022 12:12:35 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4947F13DC2 for ; Sun, 17 Jul 2022 09:12:32 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id x21so7104159plb.3 for ; Sun, 17 Jul 2022 09:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c8OkwLcbGuzYC0abfME/JKh+XFIW52Kra8iG6OA4zeM=; b=lECtfNMOZvceShvfJ7Z6/ISyR/wlQ/wjCsC/2p2L8vTqXBVDn/95EKk6UffagerVlO aTVzA+PM8avH1KTDyF4WCQ9v18BC5KCKy5hzEcXs/emJLpjXeNKoxDiW1TOUfTsWgok7 6+jxTSqlvjv4ZKV6Dgb0pZSE0GW+oZCsw7IT6p21bHhbiRvyk9njAdBDbHiXJY0He0/S KH70ZPwD71KmBwIj5UlK1mkV3DNT9m7F1gridCRbpEqVt6UqPJqa259/QWkRJqXwy/xi XQbnZj/4Fe08bGwWi4bpiOWk2Oih0sY31vw9R7wvQSRpDNfRnHdljvU/+P9KgR6o16Nh I7mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c8OkwLcbGuzYC0abfME/JKh+XFIW52Kra8iG6OA4zeM=; b=MR1gHacB17bs7+pOkiV07VW/FsYCV27J6pQQk41mpV8xsRtaIV7cWZkHcQwfk8Fwx3 hcMCAsy2bY2oqrDzKwi0B1chRZH2+bboOb90O75vrqdPCTqc/CZSTL3dyxNDW/AeuAe1 8OqX3OQA+b6kSthMrDU9sILQsM0R3yPfIsChIvuAYWZi3dK3iWVg7mGDgP7yb/7UPhXy 3ysaGvOnUQQgVH60ZZUEqf4XnaC4XU30wGPdnxVrSX0kK02S3ihDc8g532DMlsJLVdOZ B1tpQM757VR2TSe5QWkhOLj6llLorVx+0+A9mOgDoU7X5/XoHKsjNQwQH/z3fbB9hnv/ HbOg== X-Gm-Message-State: AJIora/MdZvSQEV6/wIUcNrjMSZbZGIuX2jsJUeuE2a4t02vqX6n2Aa2 Kx5CoxlsqC6ZcWFVgxyHZdw= X-Google-Smtp-Source: AGRyM1tQwkn/lmPN56ltfGfRA/dyqb3Y8uBf1K62uVJh3BKCKR+U3F1xpYcgNGBNmBCNKUlv+wAyJg== X-Received: by 2002:a17:90a:68c3:b0:1f1:874a:e0c6 with SMTP id q3-20020a17090a68c300b001f1874ae0c6mr9567499pjj.102.1658074351705; Sun, 17 Jul 2022 09:12:31 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:31 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 5/8] amt: drop unexpected advertisement message Date: Sun, 17 Jul 2022 16:09:07 +0000 Message-Id: <20220717160910.19156-6-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org AMT gateway interface should not receive unexpected advertisement messages. In order to drop these packets, it should check nonce and amt->status. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 60e77e91a2b6..3e41dc6235b7 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2260,6 +2260,10 @@ static bool amt_advertisement_handler(struct amt_dev *amt, struct sk_buff *skb) ipv4_is_zeronet(amta->ip4)) return true; + if (amt->status != AMT_STATUS_SENT_DISCOVERY || + amt->nonce != amta->nonce) + return true; + amt->remote_ip = amta->ip4; netdev_dbg(amt->dev, "advertised remote ip = %pI4\n", &amt->remote_ip); mod_delayed_work(amt_wq, &amt->req_wq, 0); @@ -2975,6 +2979,7 @@ static int amt_dev_open(struct net_device *dev) amt->req_cnt = 0; amt->remote_ip = 0; + amt->nonce = 0; get_random_bytes(&amt->key, sizeof(siphash_key_t)); amt->status = AMT_STATUS_INIT; From patchwork Sun Jul 17 16:09:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920551 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46121C43334 for ; Sun, 17 Jul 2022 16:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232667AbiGQQMq (ORCPT ); Sun, 17 Jul 2022 12:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbiGQQMg (ORCPT ); Sun, 17 Jul 2022 12:12:36 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C12E140F7 for ; Sun, 17 Jul 2022 09:12:34 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id b2so7108603plx.7 for ; Sun, 17 Jul 2022 09:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=t2JmiWu5xuS6YJGZJO3rAneJ9uWBddl1DmsWrtCvXJU=; b=l+pXb0ZsEGIomyR7nEvSPvFK/ejghSc5X7bUjDNYYAbBAPJw84tJGqjTSQcT777iuC unHUb4/TZIXrp4HV3q0GFIagV3LDoNypyXiY7/kCoM0Tn2cF49KM8/hrQRJTw7DbEVob JTdADdMVYEXBlKxsjYPGVGzh3z9oD6Ur66GUzYzCkkfFcSM3oVapVqmyN3WvwH14U/Ff h/csOZHwM72Ysxf3vdxmy4Re2tx0BBG9EJBibAJPsNiZRP5dMNDyKpJ2nl7JtcJq/z8V K0J44Ks6aIO94RkY13fMm/ehkNQzN/ZwRBWOMVyEFY2wNkuNJx6xtX9117XV+ieIhzPL yumw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t2JmiWu5xuS6YJGZJO3rAneJ9uWBddl1DmsWrtCvXJU=; b=OJs4TvLOMKYFr3et6gm7merEKIe662iXoPZLXlKAomsKnJCeXsBYZKfK1Q9QelZaE7 gsWEgxiM9rCGVii7BfKIA6JDI20DTDVkx42PPMgfsnQN0Hr5MB35CeYqSMa91/WbNEQN 0zau3irffVSbSKgTAp8Db8hVa/eL+d0ciK98w4LVXon9+iSKioYosCZcVv+6LzDQbjPK hF91J0LrK0aAepwCWj5DuRQybco0olx0oBgzNCao25GI714XZMWpMzzzB1jweaU9QNgy EPW+AQ4SKVqOhJQFtmvyKW5t/cXQrKq/JNtYpjSqwb9qGkSMc4Pfr/LyotqO2wmfVEu4 qg6Q== X-Gm-Message-State: AJIora9EBBg18vJpafukoQ/VAZq7Pbt+XpMfDyCuIRwbOi9cSlK6HcPN IXUjLypq+FF2qA7HoRbA8fo= X-Google-Smtp-Source: AGRyM1vPAh/yMwyIL8xTlZbx1S01AqtVy34ZUHTeAuv6dE3vnrF1PJ1op8/4yoNg/qCIzCD5aY/Q0Q== X-Received: by 2002:a17:902:a406:b0:16b:c816:6427 with SMTP id p6-20020a170902a40600b0016bc8166427mr24146848plq.88.1658074354176; Sun, 17 Jul 2022 09:12:34 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:33 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 6/8] amt: drop unexpected query message Date: Sun, 17 Jul 2022 16:09:08 +0000 Message-Id: <20220717160910.19156-7-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org AMT gateway interface should not receive unexpected query messages. In order to drop unexpected query messages, it checks nonce. And it also checks ready4 and ready6 variables to drop duplicated messages. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 3e41dc6235b7..396cfee018a0 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -967,8 +967,11 @@ static void amt_event_send_request(struct amt_dev *amt) goto out; } - if (!amt->req_cnt) + if (!amt->req_cnt) { + WRITE_ONCE(amt->ready4, false); + WRITE_ONCE(amt->ready6, false); get_random_bytes(&amt->nonce, sizeof(__be32)); + } amt_send_request(amt, false); amt_send_request(amt, true); @@ -2353,6 +2356,9 @@ static bool amt_membership_query_handler(struct amt_dev *amt, if (amtmq->reserved || amtmq->version) return true; + if (amtmq->nonce != amt->nonce) + return true; + hdr_size -= sizeof(*eth); if (iptunnel_pull_header(skb, hdr_size, htons(ETH_P_TEB), false)) return true; @@ -2367,6 +2373,9 @@ static bool amt_membership_query_handler(struct amt_dev *amt, iph = ip_hdr(skb); if (iph->version == 4) { + if (READ_ONCE(amt->ready4)) + return true; + if (!pskb_may_pull(skb, sizeof(*iph) + AMT_IPHDR_OPTS + sizeof(*ihv3))) return true; @@ -2389,6 +2398,9 @@ static bool amt_membership_query_handler(struct amt_dev *amt, struct mld2_query *mld2q; struct ipv6hdr *ip6h; + if (READ_ONCE(amt->ready6)) + return true; + if (!pskb_may_pull(skb, sizeof(*ip6h) + AMT_IP6HDR_OPTS + sizeof(*mld2q))) return true; From patchwork Sun Jul 17 16:09:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920552 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 592A0C433EF for ; Sun, 17 Jul 2022 16:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232075AbiGQQMr (ORCPT ); Sun, 17 Jul 2022 12:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbiGQQMi (ORCPT ); Sun, 17 Jul 2022 12:12:38 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35F2813D40 for ; Sun, 17 Jul 2022 09:12:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id o15so9733571pjh.1 for ; Sun, 17 Jul 2022 09:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n6Dthk+er3Yye3+nU1WvbyJD3N/uReAOaBDLcBvSh0c=; b=YL9A2AiWdSd/2h96ldJdtutfZNJAHNzgbq/ubApd7f3ntrTZ7qgH2/chN+ER7UByLd x8gLvRx5eSBu4yx+PIGrRx+XUGF0vn0nHXOIw2r7AySbQFpNbL7HahW+aNicUkUfJCuG 7TVC/Un+RiQdbshWhP89w3EaONH4WiMd5qn5JV7Xu/QKzGluygT81dZ5IwfYYbAO1Y3P hOWS+++ac+EXOor1cv09qpAAGO7197uII4iog6bsKLmMdM0SBe0/LpcBABtixgo7Z3x3 mJ/uGONm2tBpXNZnyIdyFGRFlTlUG3s+g8dTB86gqmNkHS+fi9lmcu2rcjuBPjgRP+0R ifDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n6Dthk+er3Yye3+nU1WvbyJD3N/uReAOaBDLcBvSh0c=; b=i1o4+Kvz96MQJ1VrfG43DniCHgHarWhjZxoQN8VvceoV+Hc6Ll+3nL52AoQ3MRuE3S JWIfgW7X1jBPejtsgLYSQYMD+p5XvydBqx6KN93E5JmfRXguc6cQqorc5ubswq/zpD6K BbZa6DDpSTDJTHLniXZmOtco7fFJaqz9e6QMUO8K4MOHYxz+90yQmGhGSO4N5U8637BU pn42Vd4W2AB+t3CWw1uRqSYT7CFUooKGn9KLOc+MylVyhBfIOa+jesIScfiNCrwxppg0 3FtyQDaltzSs1yJUoq+6M6TRYU9iRE3kZY0qToL5KUBmatruYFGL6rLb5xoLwgvZRppM YYxA== X-Gm-Message-State: AJIora9e+kookDUL8HtJpyrrIAi65uwCmfe4U9hUMLKH8k1MIe6XIdE7 +49ZlBnIM+6SrJclp2pUYS4= X-Google-Smtp-Source: AGRyM1sOsHm8nQ295+8oQrN4tUBVeYI78dUdT1V/bedxUzDAMGOZAmTZrh4QcuMUqY0vxxlfGiwfCQ== X-Received: by 2002:a17:902:da92:b0:16b:ecee:28a8 with SMTP id j18-20020a170902da9200b0016becee28a8mr24344478plx.71.1658074356699; Sun, 17 Jul 2022 09:12:36 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:36 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 7/8] amt: drop unexpected multicast data Date: Sun, 17 Jul 2022 16:09:09 +0000 Message-Id: <20220717160910.19156-8-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org AMT gateway interface should not receive unexpected multicast data. Multicast data message type should be received after sending an update message, which means all establishment between gateway and relay is finished. So, amt_multicast_data_handler() checks amt->status. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 396cfee018a0..ecd2de22bdfc 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2282,6 +2282,9 @@ static bool amt_multicast_data_handler(struct amt_dev *amt, struct sk_buff *skb) struct ethhdr *eth; struct iphdr *iph; + if (READ_ONCE(amt->status) != AMT_STATUS_SENT_UPDATE) + return true; + hdr_size = sizeof(*amtmd) + sizeof(struct udphdr); if (!pskb_may_pull(skb, hdr_size)) return true; From patchwork Sun Jul 17 16:09:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taehee Yoo X-Patchwork-Id: 12920553 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67CEBC43334 for ; Sun, 17 Jul 2022 16:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbiGQQMt (ORCPT ); Sun, 17 Jul 2022 12:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbiGQQMp (ORCPT ); Sun, 17 Jul 2022 12:12:45 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08C8014D13 for ; Sun, 17 Jul 2022 09:12:39 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id e132so8638680pgc.5 for ; Sun, 17 Jul 2022 09:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T7jJfuQoI/zAs+0wTsZFpJFNNINBRQJRY9aIrhVtCac=; b=akt6HxozCgjfyAgu/p+8ik9KDNkB+3K97ozFzd5aNi1E3r6Ty8njezemcTJLa1nzEc k+2PBGD5YiM2DVWVDhq+BcEunNnoaMJ6qZduzEMrHBhVZZTMvNa0jsFyrUtfgUuNyEnT SmbNdH24UN9NFQJKrcTx7PTu5J7grLQgc8GxAE1+gVdIIDnOcbHI/FEeZJCRvQdgV5Wg HUqO96u47wUzT4SNo3kT8NACPt7JJ6uD8K3Wo5yDRT6+PR1BvQzRcdq0gLulFo7rs+KJ bs9L18tczH2O+jUitLk982RSQmzhbcxcaspXnHItjh6CzvxlBJKHrCVWwm2ZoturAvnx HWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T7jJfuQoI/zAs+0wTsZFpJFNNINBRQJRY9aIrhVtCac=; b=d75k9h7C/m2LAaDvBLlbojM+QKkcrOlJJEkBsIei6nvKqMCDPw+n8kX/LerwAyukLP o0ZwhMGZjqOwJnO8QVpLQ83s77PvjXI0ZWOTQrIx5MAALElNf7Q2aQphIe3Uy7+idKaU j34g5HPphr5khGtzJ5X7j2AIDkWI4ftqIqfahr+dzIc8Ka1z7eY0KbwgxZUriqHN4bbV 1cWH8q84xkTNd/iwVPh+Z5NUyUBpIh20VSjljA/NWIUkwkeWNew2BzzA+vO2CJgIzsIb eEJoDwR6O0kkQXeSHmE3KsJuwT9Yf83LjnIkdC3x8M4To18TGK0aUy8koHzGkWsC4sdd Qthw== X-Gm-Message-State: AJIora93B+R3H+IfaaWHf5lj7S/TIw63LtHAESb/jK+pMaktipriuEaA 3y/0P9xCtQT2fUOYqoVPrdA= X-Google-Smtp-Source: AGRyM1t2H7baGcHobhouoTtgXtBKwZtOvH+xCUWHKzN67FOcuzy78y8ZdLI21U843sEHJooWj7My6g== X-Received: by 2002:a63:b44a:0:b0:40b:8ebd:524 with SMTP id n10-20020a63b44a000000b0040b8ebd0524mr20330114pgu.207.1658074359210; Sun, 17 Jul 2022 09:12:39 -0700 (PDT) Received: from localhost.localdomain ([182.213.254.91]) by smtp.gmail.com with ESMTPSA id x10-20020a170902ec8a00b0016bde5edfb1sm7443026plg.171.2022.07.17.09.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 09:12:38 -0700 (PDT) From: Taehee Yoo To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, netdev@vger.kernel.org Cc: ap420073@gmail.com Subject: [PATCH net v2 8/8] amt: do not use amt->nr_tunnels outside of lock Date: Sun, 17 Jul 2022 16:09:10 +0000 Message-Id: <20220717160910.19156-9-ap420073@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220717160910.19156-1-ap420073@gmail.com> References: <20220717160910.19156-1-ap420073@gmail.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org amt->nr_tunnels is protected by amt->lock. But, amt_request_handler() has been using this variable without the amt->lock. So, it expands context of amt->lock in the amt_request_handler() to protect amt->nr_tunnels variable. Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo --- v2: - No changes. drivers/net/amt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index ecd2de22bdfc..0f2983f1897e 100644 --- a/drivers/net/amt.c +++ b/drivers/net/amt.c @@ -2679,7 +2679,9 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) if (tunnel->ip4 == iph->saddr) goto send; + spin_lock_bh(&amt->lock); if (amt->nr_tunnels >= amt->max_tunnels) { + spin_unlock_bh(&amt->lock); icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0); return true; } @@ -2687,8 +2689,10 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) tunnel = kzalloc(sizeof(*tunnel) + (sizeof(struct hlist_head) * amt->hash_buckets), GFP_ATOMIC); - if (!tunnel) + if (!tunnel) { + spin_unlock_bh(&amt->lock); return true; + } tunnel->source_port = udph->source; tunnel->ip4 = iph->saddr; @@ -2701,10 +2705,9 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire); - spin_lock_bh(&amt->lock); list_add_tail_rcu(&tunnel->list, &amt->tunnel_list); tunnel->key = amt->key; - amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true); + __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true); amt->nr_tunnels++; mod_delayed_work(amt_wq, &tunnel->gc_wq, msecs_to_jiffies(amt_gmi(amt)));