From nobody Fri Sep 20 12:43:55 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 4X9BsF41T8z5X5pk; Fri, 20 Sep 2024 12:44:01 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X9BsF1Lxzz40Pf; Fri, 20 Sep 2024 12:44:01 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7a99fd5beb6so260456185a.0; Fri, 20 Sep 2024 05:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726836239; x=1727441039; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=8Sxg+X2VlMtfQptfCLmBdM1zHS+BKpeeOjjXRp/24mk=; b=Md/LHX6+ZvuH+ykVeX+UfCG3jwh3OmDkh0Tg0LbUKdbBr+OEJb35pus3PDVrFmNVDZ qyu9J61fmVAoK9OIZV7mXFmngjxR+ebButKHVC8LYhACv2MPfEHz4baz7KzAJE8nORgM QIqpsRxHVFyW3bjPrrHJU8HPtRNeRPLrWv2NA1aM2c1HUAhcx1bwS/xIzHrzrz1AxVQ4 JsZrEbO4ItbSVPmq1byyWhPcBHIb690BBbPwBBD63aIAh5eeJnSdhsh/9tM2nN1pMsNg gero7vzkCeRlHZcFCkB0DgDGuzf25CCkKKFPYsb6LwEVpCqjk3eAu4i3GKSN4Fdh0Q8D AhDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726836239; x=1727441039; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Sxg+X2VlMtfQptfCLmBdM1zHS+BKpeeOjjXRp/24mk=; b=Dq/m5corzZ6U/nPgIcJINecz0QGywqynKEi0o/6XPqKeyADF9uyYugFl7WUIrMbYth 5TCFJ+UqItwAhDVw26W+71LmjqmQ98hO5wRpbjwKRXb09zPtn2h2wmvhNJuMgJX/qMCF 6rsP3SObHR7kkgGaNEWxLu/eibkw3/llyyEOqDOZmoJJOTK6/La2tHRVeHS5xlpKPB/4 sa3NFIKk0dBTZp2RINTG4U3LIGaM9AyurEZeirX/r+o3BUKx9mcFKOy89SdwjXzgxkk5 SsfRATSsbO2ZmXR6aiKpLtrao68QAituSJYtuFZi2inc1NMXO6PIHpZd7LtTjXB8M2e0 yw5w== X-Forwarded-Encrypted: i=1; AJvYcCUOAXVO1Acr8cgKmGk7IiRb3ywCeSJGY2FZH4FnghtGww+iY+464jKjpS8S9mOsAzI+zFAyOq2gWQ8z0wFK+JUmRG2pSEU=@freebsd.org, AJvYcCXcHV5nillDTu+ltyNjbRax5/92HJVv7rWd27yguvYVaSozh/607H6OG6w2Zcn07uXyH/FubH72KJZY9N0Dhlujuddx@freebsd.org X-Gm-Message-State: AOJu0Yx2XMqHZFeNDmnQiSkgjhUlj66nedh2dsztjZMIBmmDsITuO+1s TRdsCnxyv81KAJs47V6UjMKku6HxbKyYgd/JEeCEyyNhKEktt6hTF8/VUDkg X-Google-Smtp-Source: AGHT+IHRxrIOYT8BE/3Ood6fW97Gyf1oNjjhlj/NVt8Hl8uE8WwmKZ0FXGDo6TH22wlyIR5eIXhMTA== X-Received: by 2002:a05:620a:1a16:b0:7a1:e341:d543 with SMTP id af79cd13be357-7acaf5b86d5mr1092657585a.28.1726836239483; Fri, 20 Sep 2024 05:43:59 -0700 (PDT) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7acb08dec14sm171855885a.123.2024.09.20.05.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 05:43:58 -0700 (PDT) Date: Fri, 20 Sep 2024 08:43:55 -0400 From: Mark Johnston To: Konstantin Belousov Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 7672cbef2c1e - main - pipes: reserve configured percentage of buffers zone to superuser Message-ID: References: <202409200646.48K6ku0O009784@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202409200646.48K6ku0O009784@gitrepo.freebsd.org> X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4X9BsF1Lxzz40Pf X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated On Fri, Sep 20, 2024 at 06:46:56AM +0000, Konstantin Belousov wrote: > 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; > + } Don't we need a chgpipecnt() call here too? It looks like the previous increment is leaked. > + 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 &&