From nobody Wed May 08 13:07:51 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 4VZFn41R3Fz5J5yp; Wed, 08 May 2024 13:07:52 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VZFn35fGNz4Rdr; Wed, 8 May 2024 13:07:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715173671; 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=uV//S0DtZYWbKV8VmCTV/nrujb8RREMvt+x8tDwKnS8=; b=eUCTzU4Mzyi/qgo00sAWOpxTwtK4bRUHbKQ/1MoVz1qTXP47KjPP183yN9SUdldRk42+GU ImQApJL6hfY9BulwGB5ga440HBBL6snQ5R0pqRbBIEuufEyMPVDzdlpRJEzsxyPFL0kEtu qHExCOSbgEl7msaZhIyI+ZEsb+f15kugg5AHlPIHcNkc42HJo1mIMRQ7B2keMMfiirqgbZ h00e3w3ECI5s5Y4XroETbQca3G0mPQ/xTSigsGFxvFEAATokeJoxDUtlKUuOm2XJLoG3Te qSgnW+Ei1OjTD36sqj2vxI+W2hnnQaH0/xj66w8lsF/IXjQSJACcfS0nkYcnyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715173671; a=rsa-sha256; cv=none; b=pklQ2KHaofBMrrDtA/8Uwm2TBNnjdFEn220JQaFLInODo+twfDwYBNtZBqjLmJEMJGCrUj K6GSZfznMNw36TZNU7D57pM7sY2RYgBEfaWpAcV84r+/6v2w5xEliaI1xwtAc8OARxm2rQ tcVQLYg9UCNZWSP/W1wW/7gs4BiX2Tbtc5PzgZPd2opV614kPQSTEm6jWlMoqSWWjJAKFF /ct0bMFrLVe1mWQrnFZEpKn71Bz+SYU3HXDnevDQtIx7fu+p19K5lzt5ZMtxg3loRxFC0r /J27gzlI0vUbDzzh/LKE+ziA9CZjIipbD5tyRAIzb8diCGQQbrrEafgbgukepQ== 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=1715173671; 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=uV//S0DtZYWbKV8VmCTV/nrujb8RREMvt+x8tDwKnS8=; b=cMNYLtbykymVxo88f0YLBsK/O5of7A+IIMo59CvktBVbzAVnnOaEJBXr+N3vvS6YEthhxQ Vqi2+hGgEYH9TrnHfhF7AYwccxgVptlBtpaObcR+BXxGmReHLftXZdYcOcZb0jY6lxcAho GbD7X4WdtKLMBiFZ+l2/tLtCJPv2uIcjE7GtDhODpsWbMi9akIA9LUmJUglyZpeyfGY5UF /g4te5vVAOI+F9h/wsf5SaOMOP6/NdoztWUByycGsiAfJUWIHt8B22z10c0p6H+xsYM6WK kiz5q/YnL2Hg6qO/7VqBk+ncyB7e8invUeePcf36s4/4c3rjD1E37vom5Cc3kQ== 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 4VZFn34fjFzQk7; Wed, 8 May 2024 13:07:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 448D7psi080578; Wed, 8 May 2024 13:07:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 448D7pxe080575; Wed, 8 May 2024 13:07:51 GMT (envelope-from git) Date: Wed, 8 May 2024 13:07:51 GMT Message-Id: <202405081307.448D7pxe080575@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 50af25e87422 - stable/14 - ng_pipe: Do not panic when memory allocations fail 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 50af25e87422f2efa42104ed7ad5142f7b4948be Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=50af25e87422f2efa42104ed7ad5142f7b4948be commit 50af25e87422f2efa42104ed7ad5142f7b4948be Author: Martin Vahlensieck AuthorDate: 2024-04-17 19:01:34 +0000 Commit: Mark Johnston CommitDate: 2024-05-08 13:06:16 +0000 ng_pipe: Do not panic when memory allocations fail Signed-off-by: Martin Vahlensieck Reviewed by: markj MFC after: 2 weeks Pull Request: https://github.com/freebsd/freebsd-src/pull/1181 (cherry picked from commit d44c78074d8738db67a2fa6bf07b630c61eee6ab) --- sys/netgraph/ng_pipe.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/sys/netgraph/ng_pipe.c b/sys/netgraph/ng_pipe.c index d368c142b1ab..42a5991e8dc7 100644 --- a/sys/netgraph/ng_pipe.c +++ b/sys/netgraph/ng_pipe.c @@ -641,12 +641,14 @@ ngp_rcvdata(hook_p hook, item_p item) } /* Populate the packet header */ - ngp_h = uma_zalloc(ngp_zone, M_NOWAIT); - KASSERT((ngp_h != NULL), ("ngp_h zalloc failed (1)")); NGI_GET_M(item, m); - KASSERT(m != NULL, ("NGI_GET_M failed")); - ngp_h->m = m; NG_FREE_ITEM(item); + ngp_h = uma_zalloc(ngp_zone, M_NOWAIT); + if (ngp_h == NULL) { + NG_FREE_M(m); + return (ENOMEM); + } + ngp_h->m = m; if (hinfo->cfg.fifo) hash = 0; /* all packets go into a single FIFO queue */ @@ -659,7 +661,11 @@ ngp_rcvdata(hook_p hook, item_p item) break; if (ngp_f == NULL) { ngp_f = uma_zalloc(ngp_zone, M_NOWAIT); - KASSERT(ngp_h != NULL, ("ngp_h zalloc failed (2)")); + if (ngp_f == NULL) { + NG_FREE_M(ngp_h->m); + uma_zfree(ngp_zone, ngp_h); + return (ENOMEM); + } TAILQ_INIT(&ngp_f->packet_head); ngp_f->hash = hash; ngp_f->packets = 1; @@ -733,7 +739,7 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) { const priv_p priv = NG_NODE_PRIVATE(node); struct hookinfo *dest; struct ngp_fifo *ngp_f, *ngp_f1; - struct ngp_hdr *ngp_h; + struct ngp_hdr *ngp_h, *ngp_dup; struct timeval *when; struct mbuf *m; int plen, error = 0; @@ -768,16 +774,27 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) { } /* - * Either create a duplicate and pass it on, or dequeue - * the original packet... + * Either create a duplicate and pass it on, or + * dequeue the original packet. When any of the + * memory allocations for the duplicate package fail, + * simply do not duplicate it at all. */ + ngp_dup = NULL; if (hinfo->cfg.duplicate && prng32_bounded(100) <= hinfo->cfg.duplicate) { - ngp_h = uma_zalloc(ngp_zone, M_NOWAIT); - KASSERT(ngp_h != NULL, ("ngp_h zalloc failed (3)")); - m = m_dup(m, M_NOWAIT); - KASSERT(m != NULL, ("m_dup failed")); - ngp_h->m = m; + ngp_dup = uma_zalloc(ngp_zone, M_NOWAIT); + if (ngp_dup != NULL) { + ngp_dup->m = m_dup(m, M_NOWAIT); + if (ngp_dup->m == NULL) { + uma_zfree(ngp_zone, ngp_dup); + ngp_dup = NULL; + } + } + } + + if (ngp_dup != NULL) { + ngp_h = ngp_dup; + m = ngp_h->m; } else { TAILQ_REMOVE(&ngp_f->packet_head, ngp_h, ngp_link); hinfo->run.qin_frames--; @@ -983,8 +1000,6 @@ ngp_modevent(module_t mod, int type, void *unused) ngp_zone = uma_zcreate("ng_pipe", max(sizeof(struct ngp_hdr), sizeof (struct ngp_fifo)), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); - if (ngp_zone == NULL) - panic("ng_pipe: couldn't allocate descriptor zone"); break; case MOD_UNLOAD: uma_zdestroy(ngp_zone);