From patchwork Tue Oct 15 07:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 18669 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id DA81283FDF for ; Tue, 15 Oct 2024 09:40:37 +0200 (CEST) ARC-Seal: i=2; cv=fail; a=rsa-sha256; d=open-mesh.org; s=20121; t=1728978037; b=wnoZgtXqK2gctobnJ/ncWN5+yJrjpqq8A62dzS/x0AFhXWo0AZxEK4p6C32YfvtJu+GXq rZg0JE40oHPgqvxBI4r2MdfEj+G+/UqevwbhtDB5NbXuR1V/8MYEpyJx+j0VxtwkGA30ATd b4ZdNcRig6mHnw+GO/tpIssWYAnA7MI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728978037; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=o15IjSjSEbc45+xTmKhS0JErs0wEkqd/wxgOrWgoUeU=; b=SPHCYARioSD/z2GgfBpUS5Weks5zKCx83SheOHLXlt9eK8s8kHDTMW9al5k1oy8GazW8n 64dEwAX9h5XqGqgVqB3X21OU3+AEKOH20iTlsaN9mZqN3XXjZRpCCnW4eAYshLjDllX/Uei Bxh1rMvc8c60pcfKHP+wcRGJEFsFA0Y= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Authentication-Results: open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) by diktynna.open-mesh.org (Postfix) with ESMTPS id EE9EA8164E for ; Tue, 15 Oct 2024 09:39:48 +0200 (CEST) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1728977989; a=rsa-sha256; cv=none; b=fuL8zh88uV8DE854IwHcEsl/cqrc5xT9OS7SlclwNFA5t+gKpbxDz/7xYKd8jLY5QyyJca aCpAzSKgsFhPri3Mi0mIrC9bnJHy7ISieF4FdEE4iFPb9aGjCURqNzx1+kX49Z739ErotD NIxFeh46xb3NqDjl1Ian7FuCGhxgPCY= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; dmarc=pass (policy=none) header.from=simonwunderlich.de; spf=pass (diktynna.open-mesh.org: domain of sw@simonwunderlich.de designates 23.88.38.48 as permitted sender) smtp.mailfrom=sw@simonwunderlich.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728977989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o15IjSjSEbc45+xTmKhS0JErs0wEkqd/wxgOrWgoUeU=; b=F2b6XkouKvspbZquRMThnpL7CvW/azTUA06CIH4kFwhNE39QYm3Ek/nk8icu/G7JbvXW+W opvJ/thi5H/2BeAuYrkm5np/DIAgHFk75ot0tPEAEs+m44AaPCh2vWhYPb7JSJGOFyz3Xf ilxlNNj808JF6pVZFLwoH0Qa/al7Tw8= Received: from kero.packetmixer.de (p5480b09e.dip0.t-ipconnect.de [84.128.176.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with ESMTPSA id 95D0CFA181; Tue, 15 Oct 2024 09:39:48 +0200 (CEST) From: Simon Wunderlich To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Simon Wunderlich Subject: [PATCH 1/4] batman-adv: Start new development cycle Date: Tue, 15 Oct 2024 09:39:43 +0200 Message-Id: <20241015073946.46613-2-sw@simonwunderlich.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015073946.46613-1-sw@simonwunderlich.de> References: <20241015073946.46613-1-sw@simonwunderlich.de> MIME-Version: 1.0 Message-ID-Hash: 23W3GUH42BEQKEU2WJVIJ4JLASPZCADU X-Message-ID-Hash: 23W3GUH42BEQKEU2WJVIJ4JLASPZCADU X-MailFrom: sw@simonwunderlich.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This version will contain all the (major or even only minor) changes for Linux 6.13. The version number isn't a semantic version number with major and minor information. It is just encoding the year of the expected publishing as Linux -rc1 and the number of published versions this year (starting at 0). Signed-off-by: Simon Wunderlich --- net/batman-adv/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index 3d4c36ae2e1a..97ea71a052f8 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h @@ -13,7 +13,7 @@ #define BATADV_DRIVER_DEVICE "batman-adv" #ifndef BATADV_SOURCE_VERSION -#define BATADV_SOURCE_VERSION "2024.2" +#define BATADV_SOURCE_VERSION "2024.3" #endif /* B.A.T.M.A.N. parameters */ From patchwork Tue Oct 15 07:39:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 18670 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 8EDEB83FC1 for ; Tue, 15 Oct 2024 09:41:23 +0200 (CEST) ARC-Seal: i=2; cv=fail; a=rsa-sha256; d=open-mesh.org; s=20121; t=1728978083; b=2FkdJtqsCdQktV09AqUQQj2XQDwoA2WD+Oh0tQj8m4gWH27ajvol1Az6Ljsxege72HhrA jI20PoLg0emgrcqbdJfoZheXft5MYjWsM1001ONpl4vkQR+WK87mTTGL+pSzbAIgAiPEcx8 sTRaz5GAIaAM3EUlL0dOFhP+wOgVlq8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728978083; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=baAA5WrpU78YFXqmaxRUHVCJ0YXD0LfABWg0PwxohC0=; b=cDU63P4vLafYAX8kJ6TNSpV6MzASuo7X9maHYbSuqgfSOKCjNBJ9mWY/NQgfijDS1SBnr mFx8o7SB0vJUauSVRfJZGGT/3Cli8VOIQ26n/x1Eh0ZlZkkpx4ErSiCriiAotN+G8sWyPlA lH6sIfhfMA4PIfKfOtfgQBB6K6DweCk= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Authentication-Results: open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [IPv6:2a01:4f8:c17:e8c0::1]) by diktynna.open-mesh.org (Postfix) with ESMTPS id CD3AE8267A for ; Tue, 15 Oct 2024 09:39:49 +0200 (CEST) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1728977989; a=rsa-sha256; cv=none; b=vY289RnHwGj5yLr1RPqA4a/o5z1/xLbl3MyDdV3b78oQZxfCTyOxJ9oVFo5cYT1bEj6KhO S1oWtNBgOSsyG9jQbOAJly3jQvz+kOd0+qNUG7jyVCF2m3nAKof7OMpKODO23Ls1NVUEwE 2ncJq9aMUEXJtRIHDXdzJlROmVAvf80= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; dmarc=pass (policy=none) header.from=simonwunderlich.de; spf=pass (diktynna.open-mesh.org: domain of sw@simonwunderlich.de designates 2a01:4f8:c17:e8c0::1 as permitted sender) smtp.mailfrom=sw@simonwunderlich.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728977989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=baAA5WrpU78YFXqmaxRUHVCJ0YXD0LfABWg0PwxohC0=; b=pi1zaSkIUF5Jy8HsJ4qVG+mKheMZs9gZFxBXuO81yPt60x+6H99VqkdXYY5jsGvkgBr2pe VsWD7qNWKXBiq5Swh1ctgKV4F0BHdufS9bosDvAhfYE+csB6k40EDbKuBmHG5cWyvNhpAM FW7ZOSYjchOMjxnGwU6j4lJ9aRgsEn4= Received: from kero.packetmixer.de (p5480b09e.dip0.t-ipconnect.de [84.128.176.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with ESMTPSA id 2DFFEFAA30; Tue, 15 Oct 2024 09:39:49 +0200 (CEST) From: Simon Wunderlich To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Erick Archer , Kees Cook , Sven Eckelmann , Simon Wunderlich Subject: [PATCH 2/4] batman-adv: Add flex array to struct batadv_tvlv_tt_data Date: Tue, 15 Oct 2024 09:39:44 +0200 Message-Id: <20241015073946.46613-3-sw@simonwunderlich.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015073946.46613-1-sw@simonwunderlich.de> References: <20241015073946.46613-1-sw@simonwunderlich.de> MIME-Version: 1.0 Message-ID-Hash: ZGTJERWRXHVXLUPH5BLWHCKM4FA5FLN6 X-Message-ID-Hash: ZGTJERWRXHVXLUPH5BLWHCKM4FA5FLN6 X-MailFrom: sw@simonwunderlich.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Erick Archer The "struct batadv_tvlv_tt_data" uses a dynamically sized set of trailing elements. Specifically, it uses an array of structures of type "batadv_tvlv_tt_vlan_data". So, use the preferred way in the kernel declaring a flexible array [1]. At the same time, prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). In this case, it is important to note that the attribute used is specifically __counted_by_be since variable "num_vlan" is of type __be16. The following change to the "batadv_tt_tvlv_ogm_handler_v1" function: - tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1); - tt_change = (struct batadv_tvlv_tt_change *)(tt_vlan + num_vlan); + tt_change = (struct batadv_tvlv_tt_change *)((void *)tt_data + + flex_size); is intended to prevent the compiler from generating an "out-of-bounds" notification due to the __counted_by attribute. The compiler can do a pointer calculation using the vlan_data flexible array memory, or in other words, this may be calculated as an array offset, since it is the same as: &tt_data->vlan_data[num_vlan] Therefore, we go past the end of the array. In other "multiple trailing flexible array" situations, this has been solved by addressing from the base pointer, since the compiler either knows the full allocation size or it knows nothing about it (this case, since it came from a "void *" function argument). The order in which the structure batadv_tvlv_tt_data and the structure batadv_tvlv_tt_vlan_data are defined must be swap to avoid an incomplete type error. Also, avoid the open-coded arithmetic in memory allocator functions [2] using the "struct_size" macro and use the "flex_array_size" helper to clarify some calculations, when possible. Moreover, the new structure member also allow us to avoid the open-coded arithmetic on pointers in some situations. Take advantage of this. This code was detected with the help of Coccinelle, and audited and modified manually. Link: https://www.kernel.org/doc/html/next/process/deprecated.html#zero-length-and-one-element-arrays [1] Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [2] Reviewed-by: Kees Cook Signed-off-by: Erick Archer Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- include/uapi/linux/batadv_packet.h | 29 ++++++++++-------- net/batman-adv/translation-table.c | 49 ++++++++++++------------------ 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/include/uapi/linux/batadv_packet.h b/include/uapi/linux/batadv_packet.h index 6e25753015df..439132a819ea 100644 --- a/include/uapi/linux/batadv_packet.h +++ b/include/uapi/linux/batadv_packet.h @@ -9,6 +9,7 @@ #include #include +#include #include /** @@ -592,19 +593,6 @@ struct batadv_tvlv_gateway_data { __be32 bandwidth_up; }; -/** - * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container - * @flags: translation table flags (see batadv_tt_data_flags) - * @ttvn: translation table version number - * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by - * one batadv_tvlv_tt_vlan_data object per announced vlan - */ -struct batadv_tvlv_tt_data { - __u8 flags; - __u8 ttvn; - __be16 num_vlan; -}; - /** * struct batadv_tvlv_tt_vlan_data - vlan specific tt data propagated through * the tt tvlv container @@ -618,6 +606,21 @@ struct batadv_tvlv_tt_vlan_data { __u16 reserved; }; +/** + * struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container + * @flags: translation table flags (see batadv_tt_data_flags) + * @ttvn: translation table version number + * @num_vlan: number of announced VLANs. In the TVLV this struct is followed by + * one batadv_tvlv_tt_vlan_data object per announced vlan + * @vlan_data: array of batadv_tvlv_tt_vlan_data objects + */ +struct batadv_tvlv_tt_data { + __u8 flags; + __u8 ttvn; + __be16 num_vlan; + struct batadv_tvlv_tt_vlan_data vlan_data[] __counted_by_be(num_vlan); +}; + /** * struct batadv_tvlv_tt_change - translation table diff data * @flags: status indicators concerning the non-mesh client (see diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 2243cec18ecc..6815d1262feb 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -856,8 +857,7 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node, num_entries += atomic_read(&vlan->tt.num_entries); } - change_offset = sizeof(**tt_data); - change_offset += num_vlan * sizeof(*tt_vlan); + change_offset = struct_size(*tt_data, vlan_data, num_vlan); /* if tt_len is negative, allocate the space needed by the full table */ if (*tt_len < 0) @@ -876,7 +876,7 @@ batadv_tt_prepare_tvlv_global_data(struct batadv_orig_node *orig_node, (*tt_data)->ttvn = atomic_read(&orig_node->last_ttvn); (*tt_data)->num_vlan = htons(num_vlan); - tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1); + tt_vlan = (*tt_data)->vlan_data; hlist_for_each_entry(vlan, &orig_node->vlan_list, list) { tt_vlan->vid = htons(vlan->vid); tt_vlan->crc = htonl(vlan->tt.crc); @@ -936,8 +936,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, total_entries += vlan_entries; } - change_offset = sizeof(**tt_data); - change_offset += num_vlan * sizeof(*tt_vlan); + change_offset = struct_size(*tt_data, vlan_data, num_vlan); /* if tt_len is negative, allocate the space needed by the full table */ if (*tt_len < 0) @@ -956,7 +955,7 @@ batadv_tt_prepare_tvlv_local_data(struct batadv_priv *bat_priv, (*tt_data)->ttvn = atomic_read(&bat_priv->tt.vn); (*tt_data)->num_vlan = htons(num_vlan); - tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(*tt_data + 1); + tt_vlan = (*tt_data)->vlan_data; hlist_for_each_entry(vlan, &bat_priv->softif_vlan_list, list) { vlan_entries = atomic_read(&vlan->tt.num_entries); if (vlan_entries < 1) @@ -2916,7 +2915,6 @@ static bool batadv_send_tt_request(struct batadv_priv *bat_priv, { struct batadv_tvlv_tt_data *tvlv_tt_data = NULL; struct batadv_tt_req_node *tt_req_node = NULL; - struct batadv_tvlv_tt_vlan_data *tt_vlan_req; struct batadv_hard_iface *primary_if; bool ret = false; int i, size; @@ -2932,7 +2930,7 @@ static bool batadv_send_tt_request(struct batadv_priv *bat_priv, if (!tt_req_node) goto out; - size = sizeof(*tvlv_tt_data) + sizeof(*tt_vlan_req) * num_vlan; + size = struct_size(tvlv_tt_data, vlan_data, num_vlan); tvlv_tt_data = kzalloc(size, GFP_ATOMIC); if (!tvlv_tt_data) goto out; @@ -2944,12 +2942,10 @@ static bool batadv_send_tt_request(struct batadv_priv *bat_priv, /* send all the CRCs within the request. This is needed by intermediate * nodes to ensure they have the correct table before replying */ - tt_vlan_req = (struct batadv_tvlv_tt_vlan_data *)(tvlv_tt_data + 1); for (i = 0; i < num_vlan; i++) { - tt_vlan_req->vid = tt_vlan->vid; - tt_vlan_req->crc = tt_vlan->crc; + tvlv_tt_data->vlan_data[i].vid = tt_vlan->vid; + tvlv_tt_data->vlan_data[i].crc = tt_vlan->crc; - tt_vlan_req++; tt_vlan++; } @@ -3001,7 +2997,6 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, struct batadv_orig_node *res_dst_orig_node = NULL; struct batadv_tvlv_tt_change *tt_change; struct batadv_tvlv_tt_data *tvlv_tt_data = NULL; - struct batadv_tvlv_tt_vlan_data *tt_vlan; bool ret = false, full_table; u8 orig_ttvn, req_ttvn; u16 tvlv_len; @@ -3024,10 +3019,9 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, orig_ttvn = (u8)atomic_read(&req_dst_orig_node->last_ttvn); req_ttvn = tt_data->ttvn; - tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1); /* this node doesn't have the requested data */ if (orig_ttvn != req_ttvn || - !batadv_tt_global_check_crc(req_dst_orig_node, tt_vlan, + !batadv_tt_global_check_crc(req_dst_orig_node, tt_data->vlan_data, ntohs(tt_data->num_vlan))) goto out; @@ -3370,7 +3364,6 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv, struct batadv_orig_node *orig_node = NULL; struct batadv_tvlv_tt_change *tt_change; u8 *tvlv_ptr = (u8 *)tt_data; - u16 change_offset; batadv_dbg(BATADV_DBG_TT, bat_priv, "Received TT_RESPONSE from %pM for ttvn %d t_size: %d [%c]\n", @@ -3383,10 +3376,7 @@ static void batadv_handle_tt_response(struct batadv_priv *bat_priv, spin_lock_bh(&orig_node->tt_lock); - change_offset = sizeof(struct batadv_tvlv_tt_vlan_data); - change_offset *= ntohs(tt_data->num_vlan); - change_offset += sizeof(*tt_data); - tvlv_ptr += change_offset; + tvlv_ptr += struct_size(tt_data, vlan_data, ntohs(tt_data->num_vlan)); tt_change = (struct batadv_tvlv_tt_change *)tvlv_ptr; if (tt_data->flags & BATADV_TT_FULL_TABLE) { @@ -3985,10 +3975,10 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv, u8 flags, void *tvlv_value, u16 tvlv_value_len) { - struct batadv_tvlv_tt_vlan_data *tt_vlan; struct batadv_tvlv_tt_change *tt_change; struct batadv_tvlv_tt_data *tt_data; u16 num_entries, num_vlan; + size_t flex_size; if (tvlv_value_len < sizeof(*tt_data)) return; @@ -3998,17 +3988,18 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv, num_vlan = ntohs(tt_data->num_vlan); - if (tvlv_value_len < sizeof(*tt_vlan) * num_vlan) + flex_size = flex_array_size(tt_data, vlan_data, num_vlan); + if (tvlv_value_len < flex_size) return; - tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1); - tt_change = (struct batadv_tvlv_tt_change *)(tt_vlan + num_vlan); - tvlv_value_len -= sizeof(*tt_vlan) * num_vlan; + tt_change = (struct batadv_tvlv_tt_change *)((void *)tt_data + + flex_size); + tvlv_value_len -= flex_size; num_entries = batadv_tt_entries(tvlv_value_len); - batadv_tt_update_orig(bat_priv, orig, tt_vlan, num_vlan, tt_change, - num_entries, tt_data->ttvn); + batadv_tt_update_orig(bat_priv, orig, tt_data->vlan_data, num_vlan, + tt_change, num_entries, tt_data->ttvn); } /** @@ -4039,8 +4030,8 @@ static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, tt_data = tvlv_value; tvlv_value_len -= sizeof(*tt_data); - tt_vlan_len = sizeof(struct batadv_tvlv_tt_vlan_data); - tt_vlan_len *= ntohs(tt_data->num_vlan); + tt_vlan_len = flex_array_size(tt_data, vlan_data, + ntohs(tt_data->num_vlan)); if (tvlv_value_len < tt_vlan_len) return NET_RX_SUCCESS; From patchwork Tue Oct 15 07:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 18671 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id B2BDA841DF for ; Tue, 15 Oct 2024 09:42:05 +0200 (CEST) ARC-Seal: i=2; cv=fail; a=rsa-sha256; d=open-mesh.org; s=20121; t=1728978125; b=CBcWYGL50mqibCOTPTgKLzaGKTZvMDNvEZC8psJ1QrCNbGTmaiLsSBKSPGDAazljN2+t0 SHRMrB83XKKJmEYNAEpQl/rLgBAvlpvNOm+2dudfx+0Eafoffogdmn3njULUJVLFtfEQ3WD NalZwc85gg6L11JHo6ZUF1n8+wczZw4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728978125; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=cOsPCl6XRS0JcnH2JfXCcShvWpdzVH1AtkG5g8awVGc=; b=O94kL+cOw1QEN4tmK/V23mC0wN4tkaa6WvxxXuJvNtnx/7ombGaJXbL1WYM6fzx6WyYME OwqeIxTSuTWkEkjJYJk1JvQIpBUuCBeOmhKVNMNLiTsTM9Xa/uYuMG89AhAHpaEiDUoo9sk PqZGu1zO7qS1CMqsRyyYQkaqXoNdM+E= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Authentication-Results: open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) by diktynna.open-mesh.org (Postfix) with ESMTPS id AAF7583B8D for ; Tue, 15 Oct 2024 09:39:50 +0200 (CEST) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1728977990; a=rsa-sha256; cv=none; b=j3i4kA/gqnitS6UHLD7ff2yN7krbos3HZsMNLcfVqHR/1owmCauYXdDIgjYjsRfF2JWNQf pfCExN9DcureBQThOJChLgwt8euX5wmJz7CY1hyMwOMhblxhRLjl2tfycbqLXhCFXipmRx 8BhYI4scLyewniIQeccso0kHSjvKbJ8= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; dmarc=pass (policy=none) header.from=simonwunderlich.de; spf=pass (diktynna.open-mesh.org: domain of sw@simonwunderlich.de designates 23.88.38.48 as permitted sender) smtp.mailfrom=sw@simonwunderlich.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728977990; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cOsPCl6XRS0JcnH2JfXCcShvWpdzVH1AtkG5g8awVGc=; b=RYAE0019fUIu47GdGGzRGccSZcKWHvyT+V88RSIrjj5+siP8iPG/9H7J2kzsJijmoQcsF3 kSo8BvkPVLjt/YUiVYOkFKl2VUnD6UvFjaca+OuugICeAMZXaGonqUk90sHM5YI2H8HNIz +wGzbM11GfXBQmHv2zhrKc+V9TiV55A= Received: from kero.packetmixer.de (p5480b09e.dip0.t-ipconnect.de [84.128.176.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with ESMTPSA id 1223CFAA31; Tue, 15 Oct 2024 09:39:50 +0200 (CEST) From: Simon Wunderlich To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann , Simon Wunderlich Subject: [PATCH 3/4] batman-adv: Use string choice helper to print booleans Date: Tue, 15 Oct 2024 09:39:45 +0200 Message-Id: <20241015073946.46613-4-sw@simonwunderlich.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015073946.46613-1-sw@simonwunderlich.de> References: <20241015073946.46613-1-sw@simonwunderlich.de> MIME-Version: 1.0 Message-ID-Hash: VTRKJ4MZU52DGDFORW3WSHAC6Q4P64PD X-Message-ID-Hash: VTRKJ4MZU52DGDFORW3WSHAC6Q4P64PD X-MailFrom: sw@simonwunderlich.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Sven Eckelmann The commit ea4692c75e1c ("lib/string_helpers: Consolidate string helpers implementation") introduced common helpers to print string representations of boolean helpers. These are supposed to be used instead of open coded versions. Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/bat_iv_ogm.c | 4 ++-- net/batman-adv/bridge_loop_avoidance.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 74b49c35ddc1..07ae5dd1f150 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -371,8 +372,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, batadv_ogm_packet->orig, ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->tq, batadv_ogm_packet->ttl, - ((batadv_ogm_packet->flags & BATADV_DIRECTLINK) ? - "on" : "off"), + str_on_off(batadv_ogm_packet->flags & BATADV_DIRECTLINK), hard_iface->net_dev->name, hard_iface->net_dev->dev_addr); diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 5f46ca3d4bb8..449faf5a5487 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1946,16 +1947,15 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, claim = batadv_claim_hash_find(bat_priv, &search_claim); if (!claim) { + bool local = batadv_is_my_client(bat_priv, ethhdr->h_source, vid); + /* possible optimization: race for a claim */ /* No claim exists yet, claim it for us! */ batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): Unclaimed MAC %pM found. Claim it. Local: %s\n", - __func__, ethhdr->h_source, - batadv_is_my_client(bat_priv, - ethhdr->h_source, vid) ? - "yes" : "no"); + __func__, ethhdr->h_source, str_yes_no(local)); batadv_handle_claim(bat_priv, primary_if, primary_if->net_dev->dev_addr, ethhdr->h_source, vid); From patchwork Tue Oct 15 07:39:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 18672 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id C59B183EBB for ; Tue, 15 Oct 2024 09:43:05 +0200 (CEST) ARC-Seal: i=2; cv=fail; a=rsa-sha256; d=open-mesh.org; s=20121; t=1728978185; b=YS7hMPjGU8HBgdPo1PyZfdygbNVZvPYAH731Giih3oBZxSCoehqEQZp/a12P+Gkjc3eip tnsM0TVM24fJXMezOLcU/7JXKRTQgECIGTkUsCU4DuKX86DWmDlkmPjtPZEXoC9xYJcUjSy DLFCdCvC5OUDglIwwy+RTr9Xrr+MQGM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728978185; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=8i0zeFvOhWQBIg9YF1oVE+KxFX2fepdvEeBZtHuYgaY=; b=nOWJFSAFwz97vC1rhY6jQiNWYMLGyFPoYPrTfn+n7uV8S60jzxi6lmaoVbatClCAI09ur 63pu6CUQw9UIClO2v2Rok9Plgyg+aJ6/pdi6paPeQPEgHuc8aYapwzu2SXonTxoQw3Jhvto yc2rzoexKBFQys2ap+4YJWGsMG7nuAo= ARC-Authentication-Results: i=2; open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Authentication-Results: open-mesh.org; dkim=fail; arc=fail (ARC-Seal[1] did not validate); dmarc=fail (Used From Domain Record) header.from=simonwunderlich.de policy.dmarc=none Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 16B9B83B8D for ; Tue, 15 Oct 2024 09:39:52 +0200 (CEST) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1728977992; a=rsa-sha256; cv=none; b=cTms/ZF48y+LzQV0alUV0SGVmiNA/BHsYn7fjBLzTpN20B25lgAJOTtRkDcDMF9ke9QNMS 51lafBoRJnV/PPTAqYpDRCNaBxzUlq+25tVzCElLcsNQE2Z4a/xypdGtiicu7Zch4pzZRT zSCw7NmX0v+POYReviu4YC/ZFgLQ6hw= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=none; dmarc=pass (policy=none) header.from=simonwunderlich.de; spf=pass (diktynna.open-mesh.org: domain of sw@simonwunderlich.de designates 23.88.38.48 as permitted sender) smtp.mailfrom=sw@simonwunderlich.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1728977992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8i0zeFvOhWQBIg9YF1oVE+KxFX2fepdvEeBZtHuYgaY=; b=jsMix2TskX10WWcGhYNfAhzdMwO9DJr9Co/kGeiGMgzLkkI/6u1t1vRCUoiPSvdqqDAYWr RGnqI7tT1TjNximMBS2D6iZTdIFmXvH3xdRtwMJDnX2S4fYcw8iImFjm9pk/p2vFoxJ1xs L57gH5LxNpv9zdEJzoTSgmom2kADLzo= Received: from kero.packetmixer.de (p5480b09e.dip0.t-ipconnect.de [84.128.176.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.simonwunderlich.de (Postfix) with ESMTPSA id E13F7FAA33; Tue, 15 Oct 2024 09:39:50 +0200 (CEST) From: Simon Wunderlich To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Julia Lawall , Sven Eckelmann , Simon Wunderlich Subject: [PATCH 4/4] batman-adv: replace call_rcu by kfree_rcu for simple kmem_cache_free callback Date: Tue, 15 Oct 2024 09:39:46 +0200 Message-Id: <20241015073946.46613-5-sw@simonwunderlich.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015073946.46613-1-sw@simonwunderlich.de> References: <20241015073946.46613-1-sw@simonwunderlich.de> MIME-Version: 1.0 Message-ID-Hash: CSTEUV5M7SQCQ6I26EGZTLEA6PQRMXRL X-Message-ID-Hash: CSTEUV5M7SQCQ6I26EGZTLEA6PQRMXRL X-MailFrom: sw@simonwunderlich.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Julia Lawall Since SLOB was removed and since commit 6c6c47b063b5 ("mm, slab: call kvfree_rcu_barrier() from kmem_cache_destroy()"), it is not necessary to use call_rcu when the callback only performs kmem_cache_free. Use kfree_rcu() directly. The changes were made using Coccinelle. Signed-off-by: Julia Lawall Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/translation-table.c | 47 ++---------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 6815d1262feb..b44c382226a1 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -209,20 +209,6 @@ batadv_tt_global_hash_find(struct batadv_priv *bat_priv, const u8 *addr, return tt_global_entry; } -/** - * batadv_tt_local_entry_free_rcu() - free the tt_local_entry - * @rcu: rcu pointer of the tt_local_entry - */ -static void batadv_tt_local_entry_free_rcu(struct rcu_head *rcu) -{ - struct batadv_tt_local_entry *tt_local_entry; - - tt_local_entry = container_of(rcu, struct batadv_tt_local_entry, - common.rcu); - - kmem_cache_free(batadv_tl_cache, tt_local_entry); -} - /** * batadv_tt_local_entry_release() - release tt_local_entry from lists and queue * for free after rcu grace period @@ -237,7 +223,7 @@ static void batadv_tt_local_entry_release(struct kref *ref) batadv_softif_vlan_put(tt_local_entry->vlan); - call_rcu(&tt_local_entry->common.rcu, batadv_tt_local_entry_free_rcu); + kfree_rcu(tt_local_entry, common.rcu); } /** @@ -255,20 +241,6 @@ batadv_tt_local_entry_put(struct batadv_tt_local_entry *tt_local_entry) batadv_tt_local_entry_release); } -/** - * batadv_tt_global_entry_free_rcu() - free the tt_global_entry - * @rcu: rcu pointer of the tt_global_entry - */ -static void batadv_tt_global_entry_free_rcu(struct rcu_head *rcu) -{ - struct batadv_tt_global_entry *tt_global_entry; - - tt_global_entry = container_of(rcu, struct batadv_tt_global_entry, - common.rcu); - - kmem_cache_free(batadv_tg_cache, tt_global_entry); -} - /** * batadv_tt_global_entry_release() - release tt_global_entry from lists and * queue for free after rcu grace period @@ -283,7 +255,7 @@ void batadv_tt_global_entry_release(struct kref *ref) batadv_tt_global_del_orig_list(tt_global_entry); - call_rcu(&tt_global_entry->common.rcu, batadv_tt_global_entry_free_rcu); + kfree_rcu(tt_global_entry, common.rcu); } /** @@ -408,19 +380,6 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node, batadv_tt_global_size_mod(orig_node, vid, -1); } -/** - * batadv_tt_orig_list_entry_free_rcu() - free the orig_entry - * @rcu: rcu pointer of the orig_entry - */ -static void batadv_tt_orig_list_entry_free_rcu(struct rcu_head *rcu) -{ - struct batadv_tt_orig_list_entry *orig_entry; - - orig_entry = container_of(rcu, struct batadv_tt_orig_list_entry, rcu); - - kmem_cache_free(batadv_tt_orig_cache, orig_entry); -} - /** * batadv_tt_orig_list_entry_release() - release tt orig entry from lists and * queue for free after rcu grace period @@ -434,7 +393,7 @@ static void batadv_tt_orig_list_entry_release(struct kref *ref) refcount); batadv_orig_node_put(orig_entry->orig_node); - call_rcu(&orig_entry->rcu, batadv_tt_orig_list_entry_free_rcu); + kfree_rcu(orig_entry, rcu); } /**