Article View: linux.kernel.netdev
Article #86Re: [PATCH] selftests/net: test tcp_rmem lower bound
From: Eric Dumazet
Date: Wed, 07 Oct 2026 06:14
Date: Wed, 07 Oct 2026 06:14
144 lines
9947 bytes
9947 bytes
On 10/7/26 07:45, Sahaj Chaudhari wrote:
> Exercise a tcp_rmem default below 4096 and verify that it is rejected.
> A tiny default can make TCP receive-window accounting space zero and
> trigger a divide-by-zero when the receive buffer grows.
>
> Run the test in a fresh network namespace and verify that rejection
> leaves the setting unchanged.
>
> Signed-off-by: Sahaj Chaudhari <sahaj123.sc@gmail.com>
> ---
> tools/testing/selftests/net/.gitignore | 1 +
> tools/testing/selftests/net/Makefile | 1 +
> tools/testing/selftests/net/tcp_rmem_min.c | 78 ++++++++++++++++++++++
> 3 files changed, 80 insertions(+)
> create mode 100644 tools/testing/selftests/net/tcp_rmem_min.c
>
> diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore
> index dacd36ed8455..44de061e3eef 100644
> --- a/tools/testing/selftests/net/.gitignore
> +++ b/tools/testing/selftests/net/.gitignore
> @@ -48,6 +48,7 @@ tcp_fastopen_backup_key
> tcp_inq
> tcp_mmap
> tcp_port_share
> +tcp_rmem_min
> tfo
> timestamping
> tls
> diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> index 590b33e16d9f..595f0e6c38b0 100644
> --- a/tools/testing/selftests/net/Makefile
> +++ b/tools/testing/selftests/net/Makefile
> @@ -198,6 +198,7 @@ TEST_GEN_PROGS := \
> so_incoming_cpu \
> tap \
> tcp_port_share \
> + tcp_rmem_min \
> tls \
> udp_splice_checksum \
> # end of TEST_GEN_PROGS
> diff --git a/tools/testing/selftests/net/tcp_rmem_min.c b/tools/testing/selftests/net/tcp_rmem_min.c
> new file mode 100644
> index 000000000000..dd2305d7e599
> --- /dev/null
> +++ b/tools/testing/selftests/net/tcp_rmem_min.c
> @@ -0,0 +1,78 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#define _GNU_SOURCE
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <sched.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include "kselftest.h"
> +
> +#define TCP_RMEM_PATH "/proc/sys/net/ipv4/tcp_rmem"
> +
> +static int read_tcp_rmem(char *buf, size_t size)
> +{
> + int fd = open(TCP_RMEM_PATH, O_RDONLY | O_CLOEXEC);
> + ssize_t len;
> +
> + if (fd < 0)
> + return -1;
> +
> + len = read(fd, buf, size - 1);
> + close(fd);
> + if (len < 0)
> + return -1;
> +
> + buf[len] = '\0';
> + return 0;
> +}
> +
> +int main(void)
> +{
> + /* tcp_rmem is min, default, max; keep min valid and lower the default. */
> + static const char invalid_default[] = "4096 1 6291456";
> + char before[128], after[128];
> + ssize_t len;
> + int fd, write_errno;
> +
> + ksft_print_header();
> + ksft_set_plan(1);
> +
> + if (unshare(CLONE_NEWNET)) {
> + if (errno == EPERM || errno == EACCES)
> + ksft_exit_skip("network namespace unavailable\n");
> + ksft_exit_fail_perror("unshare(CLONE_NEWNET)");
> + }
> +
> + if (read_tcp_rmem(before, sizeof(before)))
> + ksft_exit_fail_perror("read tcp_rmem before write");
> +
> + fd = open(TCP_RMEM_PATH, O_WRONLY | O_CLOEXEC);
> + if (fd < 0)
> + ksft_exit_fail_perror("open tcp_rmem");
> +
> + len = write(fd, invalid_default, sizeof(invalid_default) - 1);
> + write_errno = errno;
> + close(fd);
> +
> + if (len >= 0) {
> + ksft_test_result_fail("tcp_rmem accepted a default below 4096\n");
> + ksft_finished();
> + }
> + if (write_errno != EINVAL && write_errno != ERANGE) {
> + errno = write_errno;
> + ksft_exit_fail_perror("write tcp_rmem");
> + }
> +
> + if (read_tcp_rmem(after, sizeof(after)))
> + ksft_exit_fail_perror("read tcp_rmem after rejected write");
> + if (strcmp(before, after)) {
I do not think we want one selftest per sysctl range check.
net/ has more than 500 sysctls, most of them with bounds. A test
asserting that tcp_rmem's lower bound is 4096 only restates the table,
and proc_dointvec_minmax() itself is already covered by
tools/testing/selftests/sysctl.
This does not scale: each of these adds a binary, a CI slot and
something to maintain. This one already breaks if tcp_rmem[0] is not
4096 (PAGE_SIZE > 4K, or tuned host), because elements are stored one
by one and the rejected write still changes the min.
What would be useful is a single generic test: in a fresh netns, walk
the writable /proc/sys/net entries, set each to the extreme values the
kernel accepts, run some loopback TCP/UDP traffic, and check that
nothing splats. No bounds to duplicate, new sysctls covered for free,
and it would have caught the divide by zero fixed in commit
83a945a529d6 ("tcp: do not let tcp_rmem be set below 4096").
Thanks.
pw-bot: cr
Technical Details
Message-ID:
<9b4b59ac-6e64-4dd2-88c1-c3f7844bbd36@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342218-linux-kernel-netdev=dewy.ruReferences:
<20261007054508.1059927-1-sahaj123.sc@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342218-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH] selftests/net: test tcp_rmem lower bound Date: Wed, 7 Oct 2026 08:14:56 +0200 Organization: Usenet Network Message-ID: <9b4b59ac-6e64-4dd2-88c1-c3f7844bbd36@kernel.org> References: <20261007054508.1059927-1-sahaj123.sc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="588931"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:g8CCPSFPt758iMYVMjaWiXmpaWk= sha256:tQCsJaTDTzaGWNHUYxL0jWGaQ6aVzMW4xiJMo6Pk++g= sha1:eAwhDSsNVOwywMvXaQDlxn/MmUc= sha256:/C44cGIP3aIu6aDnkBtbwbnN2BzOAKBVh+1ltzX1lBY= Content-Language: en-US List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D36E810F0F1; Wed, 7 Oct 2026 09:15:16 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.641 X-Spam-Status: No, score=-3.641 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lUVO7rktAesh; Wed, 7 Oct 2026 09:15:10 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-342218-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 1629110F0E6; Wed, 7 Oct 2026 09:15:07 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id F39E92E471; Wed, 7 Oct 2026 06:15:05 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F73D3F5BFA; Wed, 7 Oct 2026 06:15:05 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Szg3DE3a" X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 64C363F4DE2; Wed, 7 Oct 2026 06:15:03 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791353705; cv=none; b=ovkTghis6gF1r7RAgTNpEpiqEj40n5XvsFXJDieMLaLZFTAiTVZYeNc6FRVEaRjNALk/Gk+XskJGv9yIvoKu5dMThYTtJSz7hnjQ6Ow7yHrP/XQjazq7AGXOomGBgumXu4i2IWpTpcuJ1Q8zSerKlJaSU/8NyJvO+WZKskhmkZ0= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791353705; c=relaxed/simple; bh=jz3JTIH9cnjR89bcm1Z7dcWOKNi8RvAZjX96fTjgyp8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=We5gXBHmjMkWcKEUw6xu9cZ9YFwN9Wy1GHWd9RZto/LP0o858OgJCyLJlyJhS7AojCsoijhta+cEXMvj6NKHA6xEK7XPyqX7eFpTcc5GD9/tRoq4Bc78uY48S/3xG3dIGn5P2Dm9Lck1bQFDtttD2RAFX/gHd+c8p8Ep4TJ7C7w= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Szg3DE3a; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB32B1F0089B; Wed, 7 Oct 2026 06:14:58 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791353703; bh=t8A8MODsa9K7Ase1/BF1LKsGRvpJ5GDk5tI8fsiCzEI=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=Szg3DE3aF5rNJK1zY7kGdYrXHmzlC+QmV8uzUOAPa5s4TG3S9qskUbYuSh7k4jDTx HoOyitgdeawWcAg9EuEOIRMCRW6haMT0SKyTaQVkukayNzVrFE6VY/FA1lZlvc3jEg SQxf2sMq5ieANg+Mniew8Db+sfADqzsMA/uT45BaFxXML0XK+JlYb+I53RepfBe+FL ZhcqMxgBL7aXEs57hWfGJQKnvjoC2rEml5Jr0tInnwNHjllzko3cctoS/HQ+J/3AkQ SwtuQWmTBZSI4jwmg1mWcwWV/EHd5aluXRZPqdn/CdEYDpHh7xStTHr5R86r2VCKo0 TLwcpXJcYioMA== X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-User-Agent: Mozilla Thunderbird X-Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <20261007054508.1059927-1-sahaj123.sc@gmail.com>