From nobody Sat Oct 05 07:11:06 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 4XLGmC15LJz5XrRR; Sat, 05 Oct 2024 07:11:07 +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 4XLGmB6gkwz4Mgn; Sat, 5 Oct 2024 07:11:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112266; 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=QeWyt4fiK2xTbky0JOshv2gULmM3hf9wxJqHtjo76Fc=; b=OWpNtf1t4EczACI7UWfxuLyDkUJ912GSmwh7euj9hT9jiSiViMADvZsFcHUuR1Q/3gKNM0 AZhsX1g/g+nYd2vuHbpx6eFgA9sMzA+CuNn96wDrMitr13DAXgVQz/sxr7ePIPHhImppuT ae2BRfRUa7AxI5mUXJ9gKSAy6DEC6ttouGZ4RMOkKF/8LFZLwzZ4XxmbQUtxNLnfbI21+O GtfINP5HOHaJpn8CxY/ynND24Hz7HcVT8PuxdmNn68C6TzGW0oWnvfVdJtUOYUsuh+sn8T tmdpgKBEvrLJF/ckzUUmNZ1sKMdrqKrKYsWnH+oBqdgZ422bRa4Y/GioiYtgnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112266; 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=QeWyt4fiK2xTbky0JOshv2gULmM3hf9wxJqHtjo76Fc=; b=DEnpMqtrzCv0k8ljpQrTUURlvjT93ssG8KTNFwn/HibKaszY1xd/Ib2+cCNUiYhl7FH+SF V/Vbo0uOPBBw3IEjwGuugN8LVkvpEN+acP9iAqDO90Trmi7/iHo8u0qOfUmhKsFQZY3lQV seRxoIiCriMx3p8BZ2U+lfjWDoIxmizOwBl8vlh8ft3BoFBwbIyioaYqMHiNbfseDoEBsQ ZTIXDtXGQyDdgEpISqqIYAm2jmdEzsjH/0snL4F0lqI55rU/YIfIfKVT6fn923yCoTn74z R5PpO+CjjWmI4gAVgwfULov6GaqUg/SBB4sfzL/+E9TqbkdUI1uJnAO9qQ2O3g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112266; a=rsa-sha256; cv=none; b=sns+bwB6lLh3NDXcR/6VzRUBORfE1+h3wF4W+KQTmB+bbS32npOT7twZMbyKYbUgxeUK5d 7MsblQx781Y3n/Fy6THii4/BCtL1LXe0RejEpMhlU5fXqtlVemtvjMihQLgvLTqPuu3OXy BUbRkww+S2PCOxG1KxFlnmd4Jq/hY5rKRLasnL8xbWW2Kp56NtmcnYZEcIFyb/tS6eDR8K KJJGXU8bokWT40rVOZUiebufxYKXqtGBm/OkjesUOLa+CSklcoWgBbNzYNq59EOfgdZNoH ZE336qG/uOGz7JsMLX2rYwZ4Z1FRyuGjD6MGe+SBWHeyDgehmEIGU7UrCNB3KQ== 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 4XLGmB6F43z17j3; Sat, 5 Oct 2024 07:11:06 +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 4957B69R000769; Sat, 5 Oct 2024 07:11:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957B6Is000766; Sat, 5 Oct 2024 07:11:06 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:06 GMT Message-Id: <202410050711.4957B6Is000766@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: b7eecc86c3bd - stable/14 - kernel: add RLIMIT_PIPEBUF 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: b7eecc86c3bdf124ca64e2cdc65e05a2093614a7 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b7eecc86c3bdf124ca64e2cdc65e05a2093614a7 commit b7eecc86c3bdf124ca64e2cdc65e05a2093614a7 Author: Konstantin Belousov AuthorDate: 2024-09-10 03:57:58 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:54 +0000 kernel: add RLIMIT_PIPEBUF (cherry picked from commit 3458bbd397783f3bb62713c54ae87f19eeb98dc0) --- sys/kern/kern_resource.c | 7 +++++++ sys/kern/sys_pipe.c | 16 ++++++++++++++++ sys/sys/pipe.h | 1 + sys/sys/resource.h | 3 ++- sys/sys/resourcevar.h | 2 ++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index ac086618b8b1..f3755d625572 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1610,3 +1610,10 @@ chgumtxcnt(struct uidinfo *uip, int diff, rlim_t max) return (chglimit(uip, &uip->ui_umtxcnt, diff, max, "umtxcnt")); } + +int +chgpipecnt(struct uidinfo *uip, int diff, rlim_t max) +{ + + return (chglimit(uip, &uip->ui_pipecnt, diff, max, "pipecnt")); +} diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 4c6f010a03f6..dc8b9ca2c9af 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -376,6 +376,7 @@ pipe_paircreate(struct thread *td, struct pipepair **p_pp) #endif rpipe = &pp->pp_rpipe; wpipe = &pp->pp_wpipe; + pp->pp_owner = crhold(td->td_ucred); knlist_init_mtx(&rpipe->pipe_sel.si_note, PIPE_MTX(rpipe)); knlist_init_mtx(&wpipe->pipe_sel.si_note, PIPE_MTX(wpipe)); @@ -409,6 +410,7 @@ pipe_paircreate(struct thread *td, struct pipepair **p_pp) fail: knlist_destroy(&rpipe->pipe_sel.si_note); knlist_destroy(&wpipe->pipe_sel.si_note); + crfree(pp->pp_owner); #ifdef MAC mac_pipe_destroy(pp); #endif @@ -575,9 +577,20 @@ retry: size = round_page(size); buffer = (caddr_t) vm_map_min(pipe_map); + if (!chgpipecnt(cpipe->pipe_pair->pp_owner->cr_ruidinfo, + size, lim_cur(curthread, RLIMIT_PIPEBUF))) { + if (cpipe->pipe_buffer.buffer == NULL && + size > SMALL_PIPE_SIZE) { + size = SMALL_PIPE_SIZE; + goto 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); if (error != KERN_SUCCESS) { + chgpipecnt(cpipe->pipe_pair->pp_owner->cr_ruidinfo, -size, 0); if (cpipe->pipe_buffer.buffer == NULL && size > SMALL_PIPE_SIZE) { size = SMALL_PIPE_SIZE; @@ -1646,6 +1659,8 @@ pipe_free_kmem(struct pipe *cpipe) if (cpipe->pipe_buffer.buffer != NULL) { atomic_subtract_long(&amountpipekva, cpipe->pipe_buffer.size); + chgpipecnt(cpipe->pipe_pair->pp_owner->cr_uidinfo, + -cpipe->pipe_buffer.size, 0); vm_map_remove(pipe_map, (vm_offset_t)cpipe->pipe_buffer.buffer, (vm_offset_t)cpipe->pipe_buffer.buffer + cpipe->pipe_buffer.size); @@ -1732,6 +1747,7 @@ pipeclose(struct pipe *cpipe) */ if (ppipe->pipe_present == PIPE_FINALIZED) { PIPE_UNLOCK(cpipe); + crfree(cpipe->pipe_pair->pp_owner); #ifdef MAC mac_pipe_destroy(pp); #endif diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h index 61fb57480605..0f35316432eb 100644 --- a/sys/sys/pipe.h +++ b/sys/sys/pipe.h @@ -136,6 +136,7 @@ struct pipepair { struct pipe pp_wpipe; struct mtx pp_mtx; struct label *pp_label; + struct ucred *pp_owner; /* to dec pipe usage count */ }; #define PIPE_MTX(pipe) (&(pipe)->pipe_pair->pp_mtx) diff --git a/sys/sys/resource.h b/sys/sys/resource.h index 5100501fb2b8..3b582e83d553 100644 --- a/sys/sys/resource.h +++ b/sys/sys/resource.h @@ -116,8 +116,9 @@ struct __wrusage { #define RLIMIT_SWAP 12 /* swap used */ #define RLIMIT_KQUEUES 13 /* kqueues allocated */ #define RLIMIT_UMTXP 14 /* process-shared umtx */ +#define RLIMIT_PIPEBUF 15 /* pipes/fifos buffers */ -#define RLIM_NLIMITS 15 /* number of resource limits */ +#define RLIM_NLIMITS 16 /* number of resource limits */ #define RLIM_INFINITY ((rlim_t)(((__uint64_t)1 << 63) - 1)) #define RLIM_SAVED_MAX RLIM_INFINITY diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h index 49119651665e..8449201dee67 100644 --- a/sys/sys/resourcevar.h +++ b/sys/sys/resourcevar.h @@ -123,6 +123,7 @@ struct uidinfo { long ui_ptscnt; /* (b) number of pseudo-terminals */ long ui_kqcnt; /* (b) number of kqueues */ long ui_umtxcnt; /* (b) number of shared umtxs */ + long ui_pipecnt; /* (b) consumption of pipe buffers */ uid_t ui_uid; /* (a) uid */ u_int ui_ref; /* (b) reference count */ #ifdef RACCT @@ -144,6 +145,7 @@ int chgsbsize(struct uidinfo *uip, u_int *hiwat, u_int to, rlim_t maxval); int chgptscnt(struct uidinfo *uip, int diff, rlim_t maxval); int chgumtxcnt(struct uidinfo *uip, int diff, rlim_t maxval); +int chgpipecnt(struct uidinfo *uip, int diff, rlim_t max); int kern_proc_setrlimit(struct thread *td, struct proc *p, u_int which, struct rlimit *limp); struct plimit