From nobody Wed Apr 24 13:17:11 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 4VPffH3Pr8z5HL01; Wed, 24 Apr 2024 13:17:11 +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 4VPffH2bdwz4LWn; Wed, 24 Apr 2024 13:17:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713964631; 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=lZcOXL59KsefQIMUd9MK//Yhh0K1ciwYRVjirGY9XaY=; b=AUQUrQ92dml2u6kUtzTTY+vzimb/YP7xQPPELHBhusb0rnWePJECEYgkG7Lf9wHo3v5u2g Xywuoc1CWcxFluXicf4b+Z+aybOqsautNiUg/xLGixDR+gRSXzq7wXi8k+wT71IxWs56g9 9L/eLtkzV0/+n86WVDpMaXhxdU+zApJN0CI/0j6X8K9trVhGSSFhI8k7C+lZCGats9qmIL zgdeBgaSRG4j3qNNi/fSclvsGlQkwHpWOIu6eIMzZHL6raec9w6WEY/nVfyXO8TT8kwTMu G2iw7oMIjJNIHSoD6UsA0MttaOrNPG1IRL7GM5dqHdKfj30HhVfTgFsad43fxw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713964631; a=rsa-sha256; cv=none; b=WCNedQQkOJQ6sPbHXC5qt5Y/wuwDazXC3+nYyjFVfux8qjSNejiNuMcR4Uj3xcBCv/Uh/r ghKaS3YchdsEKuXSMMcNVhMY5M6MQcgy6ukCNwi7c2kZCvCcpK/gzOHKhiUIPmIvxKfM2p IdDWvkw8v7kDJbnW3llMDH8MjVjNOszDAMhSmvF44IxfHyesDOnmXjlT7MqlY5CtlqFNjC 1l5ZN1QqSrRsVqPGggbES641wSAn0kTb2BKomOppYYGhjt3cH7916B7cz5YN0AX8pl/ocH Pd4LiOzkVzze9pQ6GAgyItmjEAmdnmS5ygeNbkonUYVJ3LZwbL7JRhBc4FDUVQ== 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=1713964631; 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=lZcOXL59KsefQIMUd9MK//Yhh0K1ciwYRVjirGY9XaY=; b=oEOvpj8G8h9wVreo40HhGx59hMNWVHHXZTbSevgPYrFNVZKPFouAbiW3oo5aAwR1/7DId4 xbGNKA2yhet0ebc6azyllEmb1e6hxyGkVIx9GkzsL+5j4OfxblbTrDUs2IhQmiSIYWadQX o6/tMEQk8GgKWli/z/Kh9V3VAqQfCI6IembcaLDq3QZxQwublt8jrstaZX3E4rDK5tLgYg u2n8pSYCpybSwEItI5htWnbblQ+HvH6G5WLqwUr9zQMz+/LbGuuPv/hjU+dFJMEgJdsn42 2PJGIHwHemz7uqxeKB8agZvlWb6sHNl7OAJrYLjKkCDnWW5hAODDYRxlzr1oeA== 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 4VPffH27P2zGqG; Wed, 24 Apr 2024 13:17:11 +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 43ODHB6L053340; Wed, 24 Apr 2024 13:17:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43ODHBiZ053337; Wed, 24 Apr 2024 13:17:11 GMT (envelope-from git) Date: Wed, 24 Apr 2024 13:17:11 GMT Message-Id: <202404241317.43ODHBiZ053337@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d44c78074d87 - main - 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/main X-Git-Reftype: branch X-Git-Commit: d44c78074d8738db67a2fa6bf07b630c61eee6ab Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d44c78074d8738db67a2fa6bf07b630c61eee6ab commit d44c78074d8738db67a2fa6bf07b630c61eee6ab Author: Martin Vahlensieck AuthorDate: 2024-04-17 19:01:34 +0000 Commit: Mark Johnston CommitDate: 2024-04-24 12:44:50 +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 --- 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);