Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2422283rbb; Wed, 28 Feb 2024 00:57:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHWsDwkztARrBOioqCXmEZ6DQlYg06sPOT34l6VQyNrs5y+BqDpcr8LIJ/Z7asFV5935BT/db0RZg+4xj8JaSeuLtnP2knz844IQ31kg== X-Google-Smtp-Source: AGHT+IGq6DO227PwCGIz2ohiaHIuwoYHAyQKVHENKibyCmoBWpv9gIsmBm8YdFbdOF7f8zyDucGL X-Received: by 2002:aa7:c30c:0:b0:566:64d3:a80d with SMTP id l12-20020aa7c30c000000b0056664d3a80dmr844560edq.19.1709110657168; Wed, 28 Feb 2024 00:57:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709110657; cv=pass; d=google.com; s=arc-20160816; b=s0XMW349EYSx+Dh/K+8VSw7rS+naWXbY7A5H4CzUZCHZYSAvGNQwx5/cQQNLc6ezYt e2/YXiev+X1zmntu7PWnCiOYvIZUwNFCt0O7z7hATqx2F1xqqPgfd1Mr7wvxaK1FsPSe DwM7cyp8I2lQIEtUoYz/fnYtTpDP87tdpH3B+TQAU2COHEm1WjJ35w+gQ4dpyjb4yBML iQaRL35rYU75j/h8uSD8TAGYmK+O5wq3fnK2ZDpNyit0S0ZaYCdoxQX9A3NC1hwqo7l+ uAU8RBiwnsJAz8K5icoxFjFhzAF2adyNxjB9ycfMqJqS9CKBZ5c2ndyad3JKtFqpQ+2x 7Sxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=THwLqqAS9RcFEanJ/N3PZCprSmFGuglzQTg5dGb2gs4=; fh=ZwNz1elH4q2qB3ULrTSqcjmVqJptxhcFWtKuvMBRw/k=; b=mz82RRem8aKBKXXHPEVGFF2G+lgYsTAEzy+USsDgSErt4yGF1MBxksFkt/oLaJ3D19 zmtaFNZUO9ATMxoXpV2c4aZYXWKiBZvs+gofH08T3y4CxR1r+FdMo0SDlf6khd63Y8df n1Lg8rsN8pqNmI2nDc8GV/EVCGdOtT8lS0h3OPxugBXcOnjvAQWkUtm9U+Wli3v6gZiJ jH7nfcxbuBdZZz3VysbhvvnM8z5LItNIc//5nLENZaJ/uTTxFIMt+KiTx1uTRIGDc4Bw j81if+bi0GJ/uljkWJZ8e4X+ivmGewwvQEc7cmCApmvnyQlEOK8o31a0/6PiH6O5JJEF 2gIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=nh7PY4HV; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-4157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g19-20020a0564021ed300b00566421b5894si1262488edg.395.2024.02.28.00.57.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:57:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-4157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=nh7PY4HV; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-wireless+bounces-4157-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B6DDA1F24666 for ; Wed, 28 Feb 2024 08:57:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5736E2E859; Wed, 28 Feb 2024 08:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="nh7PY4HV" X-Original-To: linux-wireless@vger.kernel.org Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B66C2D634 for ; Wed, 28 Feb 2024 08:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709110647; cv=none; b=RozK9vIUAC/3jwOK+FbqK4MYuAAdfz6BPd77h1wM9PQFD+whimmkOVMIWEFdInEdlt4R/RoO2b+HMt0GIjpWJAlzGt6LX/xNmMFlEtdUSVey5ScT5MxS82c/NMwBS16FlIjUOCYI7ko50sRvyuTMArrJ0wHfueKvmp2z6GY+PwE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709110647; c=relaxed/simple; bh=9p/8R5xpQME0ahLYJWI7Np6q91vKG2DNwPpnX1RNd4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fZz9UrJs3SAnJyiPJDouF3MQOGbdF0xfd74IQFDpU4ZWo8IKyLPGCC7hyrmG5GCvS9y0cItSFRJ+v6pr1IzH8SRY/dFk5zS+NEH/CPpjfNtWscWCKgN8rwRPqf1sCnB/YhrQtm86l2DUiKzLkAmdxMvFnL9IL3rBtxWHtZyEIY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=nh7PY4HV; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=THwLqqAS9RcFEanJ/N3PZCprSmFGuglzQTg5dGb2gs4=; t=1709110645; x=1710320245; b=nh7PY4HVNksfSSOnlmoWgrTOhtdHvkcv6RUMoUm5eZQ+5TT RFMfDOOeIFvt8QfsbQRMegva5KhrBlwi2CIbVAQNV2BJChs7b9OiPL2jPy3hBjS+q6hjF9XMSAvvE KVmRpwCytbu+s3U54YuJ8o87naeI60giebAUT+Fg5/4rY9DBdsyxUerNDY6xkxLkLHHQAm8wp2d4l 02zmwMYPRzNluzR5yPeH8au6WsA7g/p2GLjUeBlUFKj6tpsXwBK4h/yY+hu1xza1v5sdauepe5Gkj RvqrCdBoPZ+n3C0/eLXwfxScchSq93RtB0jc7ZF4w4K7frXFYKmWpiFsPkRpljhA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1rfFkg-0000000C0hJ-32dZ; Wed, 28 Feb 2024 09:57:22 +0100 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg , Miriam Rachel Korenblit , Benjamin Berg Subject: [PATCH 2/8] wifi: cfg80211: allow cfg80211_defragment_element() without output Date: Wed, 28 Feb 2024 09:55:42 +0100 Message-ID: <20240228095718.6d6565b9e3f2.Ib441903f4b8644ba04b1c766f90580ee6f54fc66@changeid> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228085718.21171-10-johannes@sipsolutions.net> References: <20240228085718.21171-10-johannes@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Johannes Berg If we just want to determine the length of the fragmented data, we basically need the same logic, and really we want it to be _literally_ the same logic, so it cannot be out of sync in any way. Allow calling cfg80211_defragment_element() without an output buffer, where it then just returns the required output size. Also add this to the tests, just to exercise it, using the pre-calculated length to really do the defragmentation, which checks that this is sufficient. Reviewed-by: Miriam Rachel Korenblit Reviewed-by: Benjamin Berg Signed-off-by: Johannes Berg --- include/net/cfg80211.h | 4 ++-- net/wireless/scan.c | 27 ++++++++++++++++++--------- net/wireless/tests/fragmentation.c | 30 +++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 53653d234d39..2e2be4fd2bb6 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6908,8 +6908,8 @@ bool cfg80211_iter_rnr(const u8 *elems, size_t elems_len, * @elem: the element to defragment * @ies: elements where @elem is contained * @ieslen: length of @ies - * @data: buffer to store element data - * @data_len: length of @data + * @data: buffer to store element data, or %NULL to just determine size + * @data_len: length of @data, or 0 * @frag_id: the element ID of fragments * * Return: length of @data, or -EINVAL on error diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 9377a43aa5f7..5a5dd3ce497f 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2504,16 +2504,22 @@ ssize_t cfg80211_defragment_element(const struct element *elem, const u8 *ies, if (elem->id == WLAN_EID_EXTENSION) { copied = elem->datalen - 1; - if (copied > data_len) - return -ENOSPC; - memmove(data, elem->data + 1, copied); + if (data) { + if (copied > data_len) + return -ENOSPC; + + memmove(data, elem->data + 1, copied); + } } else { copied = elem->datalen; - if (copied > data_len) - return -ENOSPC; - memmove(data, elem->data, copied); + if (data) { + if (copied > data_len) + return -ENOSPC; + + memmove(data, elem->data, copied); + } } /* Fragmented elements must have 255 bytes */ @@ -2532,10 +2538,13 @@ ssize_t cfg80211_defragment_element(const struct element *elem, const u8 *ies, elem_datalen = elem->datalen; - if (copied + elem_datalen > data_len) - return -ENOSPC; + if (data) { + if (copied + elem_datalen > data_len) + return -ENOSPC; + + memmove(data + copied, elem->data, elem_datalen); + } - memmove(data + copied, elem->data, elem_datalen); copied += elem_datalen; /* Only the last fragment may be short */ diff --git a/net/wireless/tests/fragmentation.c b/net/wireless/tests/fragmentation.c index 49a339ca8880..411fae18cd88 100644 --- a/net/wireless/tests/fragmentation.c +++ b/net/wireless/tests/fragmentation.c @@ -2,7 +2,7 @@ /* * KUnit tests for element fragmentation * - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation */ #include #include @@ -27,7 +27,12 @@ static void defragment_0(struct kunit *test) ret = cfg80211_defragment_element((void *)input, input, sizeof(input), - data, sizeof(input), + NULL, 0, + WLAN_EID_FRAGMENT); + KUNIT_EXPECT_EQ(test, ret, 253); + ret = cfg80211_defragment_element((void *)input, + input, sizeof(input), + data, ret, WLAN_EID_FRAGMENT); KUNIT_EXPECT_EQ(test, ret, 253); KUNIT_EXPECT_MEMEQ(test, data, input + 3, 253); @@ -63,7 +68,12 @@ static void defragment_1(struct kunit *test) ret = cfg80211_defragment_element((void *)input, input, sizeof(input), - data, sizeof(input), + NULL, 0, + WLAN_EID_FRAGMENT); + KUNIT_EXPECT_EQ(test, ret, 254 + 7); + ret = cfg80211_defragment_element((void *)input, + input, sizeof(input), + data, ret, WLAN_EID_FRAGMENT); /* this means the last fragment was not used */ KUNIT_EXPECT_EQ(test, ret, 254 + 7); @@ -106,10 +116,15 @@ static void defragment_2(struct kunit *test) ret = cfg80211_defragment_element((void *)input, input, sizeof(input), - data, sizeof(input), + NULL, 0, WLAN_EID_FRAGMENT); /* this means the last fragment was not used */ KUNIT_EXPECT_EQ(test, ret, 254 + 255 + 1); + ret = cfg80211_defragment_element((void *)input, + input, sizeof(input), + data, ret, + WLAN_EID_FRAGMENT); + KUNIT_EXPECT_EQ(test, ret, 254 + 255 + 1); KUNIT_EXPECT_MEMEQ(test, data, input + 3, 254); KUNIT_EXPECT_MEMEQ(test, data + 254, input + 257 + 2, 255); KUNIT_EXPECT_MEMEQ(test, data + 254 + 255, input + 2 * 257 + 2, 1); @@ -134,7 +149,12 @@ static void defragment_at_end(struct kunit *test) ret = cfg80211_defragment_element((void *)input, input, sizeof(input), - data, sizeof(input), + NULL, 0, + WLAN_EID_FRAGMENT); + KUNIT_EXPECT_EQ(test, ret, 254 + 7); + ret = cfg80211_defragment_element((void *)input, + input, sizeof(input), + data, ret, WLAN_EID_FRAGMENT); KUNIT_EXPECT_EQ(test, ret, 254 + 7); KUNIT_EXPECT_MEMEQ(test, data, input + 3, 254); -- 2.43.2