From nobody Fri Sep 20 06:46:56 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X92xF0WsGz5Whr9; Fri, 20 Sep 2024 06:46:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X92xD4cMCz4r8Q; Fri, 20 Sep 2024 06:46:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726814816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8qNTDxZNY+aO4wg8wuz+p3jfWgLQJeiOjyuhSu0vdT4=; b=OrcZRoMHqb3nEFjn2DAZKewKY2bDfsROSrO1TgtdIwXLCzHVzif9vWAS9DtyDoX+eLTQxj 1kFF/SGKrqsMN5Hl/jkbZGvay4gBV8ASxeoH/ssMMu0FnMWH0iT725/uBCK1BC0v/JVuKJ +COII7Lh9WJxbNTuE/hJ8N+KdLcGtpfBVVOnVUEww35gvBAMxxAdNAHbvr5BLmKblGFUWJ VLIibumWH1BrNyvGQnew0dhT5Jg0S3VQBB3gPz9CZihTYBcQI9vj7gd3r1VmWxyHc+Drm7 gHWagvXq22rnMuAWYejnFeRSBm8O6aoJKdzWjGlYTdlYa6YPhwG/9y4nBwJpLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726814816; a=rsa-sha256; cv=none; b=WDw8ldbTNowEwAFQuVKl53HxinLvXdQd7AjDJlMXcbcFLcPEwZh6DlhHKqfCnQdr3bPwS1 9UoMgFENFELLOjgfjgT/4C5lnVo6Q1GWy4YrRBpezmueVb+h9BH2jukS7HZfD0mqyMWiT7 LeR9T3GIt8G0IhkPYOrWs3/wAGaXiEGifcqkCnoX8i8KcZpRpZfph+avlTjm01lHD2pvdy 8pdAGVKS8iVJX4chojdE58cgwMZRrBmeR7frjqZSdD0EnVldh88iWdfuFPDmoJKktObrJ7 Beyq0tOBm1+WGgRkIIVho2NhtoooMIPeHx88xSfIGBzX5Eazapdr6wBSOb05nQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726814816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8qNTDxZNY+aO4wg8wuz+p3jfWgLQJeiOjyuhSu0vdT4=; b=IfccWeAzY6EJqxSD7FwGz9GkoEHmmOk6F278PZSLxPJY1HrFRwvlP69yOW5eSvvcItufo8 am8aR4//D/mc8hnTTemjy1zQ3AnZnIh9X5tzkpCAld3deZU1USDFBTVBcNXgu05t/D3G6H l4oBWpoWZj8Nz8GsT5HmBWjjjkYvFFZIoUt7SUc8LgfSj0gNKKSi6HPYiODh/CV1J7kiIt tbe9BeXLY5XeZlnOFertWY0rPmDplJ57GbfWOjrpIsUIvozIsEcDwcox5uUz80EXSoKBxI 5Y/fbxxD0EfE2lTQR7cVpDpr10MyMPfjBkSFcod4sTvcSAv1gu5PFSUwSWqaUw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X92xD3VkZzfYq; Fri, 20 Sep 2024 06:46:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48K6kuAJ009787; Fri, 20 Sep 2024 06:46:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48K6ku0O009784; Fri, 20 Sep 2024 06:46:56 GMT (envelope-from git) Date: Fri, 20 Sep 2024 06:46:56 GMT Message-Id: <202409200646.48K6ku0O009784@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 7672cbef2c1e - main - pipes: reserve configured percentage of buffers zone to superuser List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7672cbef2c1e1267e42bb3aad6a6da9380f4347f Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7672cbef2c1e1267e42bb3aad6a6da9380f4347f commit 7672cbef2c1e1267e42bb3aad6a6da9380f4347f Author: Konstantin Belousov AuthorDate: 2024-09-15 06:57:34 +0000 Commit: Konstantin Belousov CommitDate: 2024-09-20 06:46:07 +0000 pipes: reserve configured percentage of buffers zone to superuser Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46619 --- sys/kern/sys_pipe.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 7ee2b5c76da3..68b57708d653 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -103,6 +103,7 @@ #include #include #include +#include #include #include #include @@ -206,6 +207,7 @@ static int pipeallocfail; static int piperesizefail; static int piperesizeallowed = 1; static long pipe_mindirect = PIPE_MINDIRECT; +static int pipebuf_reserv = 2; SYSCTL_LONG(_kern_ipc, OID_AUTO, maxpipekva, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &maxpipekva, 0, "Pipe KVA limit"); @@ -219,6 +221,9 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, piperesizefail, CTLFLAG_RD, &piperesizefail, 0, "Pipe resize failures"); SYSCTL_INT(_kern_ipc, OID_AUTO, piperesizeallowed, CTLFLAG_RW, &piperesizeallowed, 0, "Pipe resizing allowed"); +SYSCTL_INT(_kern_ipc, OID_AUTO, pipebuf_reserv, CTLFLAG_RW, + &pipebuf_reserv, 0, + "Superuser-reserved percentage of the pipe buffers space"); static void pipeinit(void *dummy __unused); static void pipeclose(struct pipe *cpipe); @@ -586,8 +591,22 @@ retry: return (ENOMEM); } - error = vm_map_find(pipe_map, NULL, 0, (vm_offset_t *)&buffer, size, 0, - VMFS_ANY_SPACE, VM_PROT_RW, VM_PROT_RW, 0); + vm_map_lock(pipe_map); + if (priv_check(curthread, PRIV_PIPEBUF) != 0 && + (vm_map_max(pipe_map) - vm_map_min(pipe_map)) * + (100 - pipebuf_reserv) / 100 < pipe_map->size + size) { + vm_map_unlock(pipe_map); + if (cpipe->pipe_buffer.buffer == NULL && + size > SMALL_PIPE_SIZE) { + size = SMALL_PIPE_SIZE; + pipefragretry++; + goto retry; + } + return (ENOMEM); + } + error = vm_map_find_locked(pipe_map, NULL, 0, (vm_offset_t *)&buffer, + size, 0, VMFS_ANY_SPACE, VM_PROT_RW, VM_PROT_RW, 0); + vm_map_unlock(pipe_map); if (error != KERN_SUCCESS) { chgpipecnt(cpipe->pipe_pair->pp_owner->cr_ruidinfo, -size, 0); if (cpipe->pipe_buffer.buffer == NULL &&