From nobody Sat Oct 05 07:11:16 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 4XLGmN3Gdvz5Xrd0; Sat, 05 Oct 2024 07:11:16 +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 4XLGmN14Qkz4Mf0; Sat, 5 Oct 2024 07:11:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112276; 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=iau3Lmk/wrzWdhOd7q1yop8AyFIm29YpRN+d4jC8DuM=; b=a6y6Laartk07Z6mDT+4gvn9gv5X7laBgLa9pl8dkk+yn1/00qHWT6V70eMCRsaJRVgmzA0 zDHce7nqF+U0d+R5taVzT2PiyEWWSHSI5M/+wlNRbx/jGuUH30zL/S8r0w+xxPJktMLiFn 4oKzpWz7dek1I8mmmXUanJBBu4D2+MttUREmVlETPnxHmJXvE7kPXft/UvAVrPo0czfLHI hFQ3hOvlgANZEJmKj8GJdzXRCbTXlXEy3/a0j9o2mMIBKOSHQiLa8K1gWNaAzJKV82+pS6 DN6Dt702hAFbnc+OZlMoqVwR8NhmURNU68I8CMXyVk2DnOjtGGTRmCOJCB7x4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112276; 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=iau3Lmk/wrzWdhOd7q1yop8AyFIm29YpRN+d4jC8DuM=; b=pYBe3K+U9jKD9f0s4wHnrpPAGBVICP22a4AtmJa+Q06T32nu3jcBwCCTLrHBCgaHYsvnzt p77G0ZecdCjKWc9GhJxN3/tyU/gun807clRZ7wbWxol/DXWxyHgDKFwUTBVQbuXcoWwj2J ugnCNSVmTSsEbDhxYadXisQ1kvR0PXbAZ/agOOeneDiie9DF1TpeGJjCsFeUUbVJvoh6GS 1XF/GiOFyrYVGprpFi9C0IKCFeFNR45YXJ0Eeb8S0BQJdzvm28yvicI6xpftXHKSE1BBTf WgAGkawI8YpnXoYK/0+SFeEV9SKCNQEnwmp7av7jTmmD8gCIQ8kRyMX2jbd3TQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112276; a=rsa-sha256; cv=none; b=Fdmbxe3OMugWlUAdcTMklQUG49+6/7c4ghFyL25KY9cvj8mdEUK2QrboEarfzvR3L4V/FD PVONNt2LQAxtR3h14AmI42NFoaXmPqkw2jRqEtPIreE9ndf9KD/sMTbjjmaliz1hUdX+OJ pjzt+YEyNlUGmJRyi1voUp+brFAe41rBDrVriipvVBgTAFZ+b2xOXbKP3Uw195W7WQCT+1 uVs+kvjowYp/+rcSK/dcxfK19QYHvxLemhhsYJJRKYgS4C69V7XOK7AiRaOw6foofmJHJs Jo1h/jlFZScMk/nynZp02VEmgpOaViGgzOSPn+e2H35+vw93HH9/gbDJMvK4Kg== 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 4XLGmN0bcPz185v; Sat, 5 Oct 2024 07:11:16 +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 4957BGr5001097; Sat, 5 Oct 2024 07:11:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957BGaU001094; Sat, 5 Oct 2024 07:11:16 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:16 GMT Message-Id: <202410050711.4957BGaU001094@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: d532d9926ee7 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: d532d9926ee74a05b03db9064196b3831c082bee Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d532d9926ee74a05b03db9064196b3831c082bee commit d532d9926ee74a05b03db9064196b3831c082bee Author: Konstantin Belousov AuthorDate: 2024-09-15 06:57:34 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:55 +0000 pipes: reserve configured percentage of buffers zone to superuser (cherry picked from commit 7672cbef2c1e1267e42bb3aad6a6da9380f4347f) --- 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 dc8b9ca2c9af..2e5eafee9fa6 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -104,6 +104,7 @@ #include #include #include +#include #include #include #include @@ -207,6 +208,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"); @@ -220,6 +222,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); @@ -587,8 +592,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 &&