From nobody Fri Apr 8 16:10:25 2022 X-Original-To: dev-commits-src-main@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 45B1A12BA8E6; Fri, 8 Apr 2022 16:10:26 +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 4KZjry0yv2z4qNk; Fri, 8 Apr 2022 16:10:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649434226; 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=cerNVp7rR0AghRLYOXVAJKqFuzb8eXlG11vq7NWQt4k=; b=XIznhMAZ+Ij45G1rBamFOuis6Vpb6bQmhUyyIOB7BY3RskKVs2qvAgAnRsySr5zUQjGPDk xMY63ps4KxHQE4KrJz39/ql4UjMVmG2vdwXSPdTZW+Wf6i/t8o5NSlwKbsauffgFa3zLDv Y7FpV5k8hVVungDP7WOliqnCtu/r8BoUyCULSwhD/oD3TVjWC3CeAzbfWRW8cGI58nHIhb e/qcArzg0kPzXg1zCvbBLxuT8XizyDU1nnUXFHPqgCvGtAVgSctUK/qHuHYPCGoU1I1/TC 8OjHmpX2jZlRDH6n9BNZM9Xcqx+3/xkTVzJsBBn4opnrANXlF5Cn9yvbgJPr2g== 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 F318427E4C; Fri, 8 Apr 2022 16:10:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 238GAPwR092115; Fri, 8 Apr 2022 16:10:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 238GAPgc092114; Fri, 8 Apr 2022 16:10:25 GMT (envelope-from git) Date: Fri, 8 Apr 2022 16:10:25 GMT Message-Id: <202204081610.238GAPgc092114@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: 990a6d18b0cb - main - net: Fix memory leaks in lltable_calc_llheader() error paths List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 990a6d18b0cb1eee9e18a4220150d549b9bee753 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649434226; 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=cerNVp7rR0AghRLYOXVAJKqFuzb8eXlG11vq7NWQt4k=; b=oX12s37a7Of9UoEXjko6A43EbpR4NO6vguhJQfQf05OOth+mKe74wkG9TH6OV1ix0PFX5q 98gRE+279rbG6FhCV3N20EVqQKTOZqfQ7gPDLPL0WQ5onpM9ZBTgCcR41PgA30xd8l7oUw YzfcZZS8rUIaXGMfCBYJaEWjZuPFJiZ3Vc5vIjSjklw3/bAc9HZ/+TEMHcq3G4hl8olDQZ 4S2p9hLuxqFT8R271OBKVivw3zAaOKY7nVtFvI+5o/1furO6QydK5HJKpgB5yKUj5PZdt/ ak6Ga1WDyEr/9dSM3Ae1ANTOpCn3JNTjC7zBFVUj3sQ0//aEbZ4XCsfoo4z+cg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649434226; a=rsa-sha256; cv=none; b=EIQqwamwcqnnHXny5uUsTjIGizRYgJ5zx7/CbkI9gZmtpPNmSfSz6giwWbmVONNsX+2s/n 2fLvWCGXlCh9X7SA3WA33jsAbF4q5u9x4Qu18fqU3brU4ESoY3FbTVNNF8TTfnNz7DDQz0 2cCpzHuOgkKuw/ZoIhz+q+jdZADAf1UxiUdrpu/Y9SX9z+fzULyeb0oRLLtdlaqsfbZkE9 wP7WZ2YiYvvQm2CFXGtDUSWL99qBUZ/X4xdeeCnXP//EgsAAMPmzFa5lcnJhs5b4b9ImpT J+4jaRPYanl1NNmnsFn+8SYmAlWk1iMNMdCWVZ1gvWGD/uFYblan0v3H9O8lgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=990a6d18b0cb1eee9e18a4220150d549b9bee753 commit 990a6d18b0cb1eee9e18a4220150d549b9bee753 Author: Mark Johnston AuthorDate: 2022-04-08 15:47:25 +0000 Commit: Mark Johnston CommitDate: 2022-04-08 15:47:25 +0000 net: Fix memory leaks in lltable_calc_llheader() error paths Also convert raw epoch_call() calls to lltable_free_entry() calls, no functional change intended. There's no need to asynchronously free the LLEs in that case to begin with, but we might as well use the lltable interfaces consistently. Noticed by code inspection; I believe lltable_calc_llheader() failures do not generally happen in practice. Reviewed by: bz MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34832 --- sys/net/if_llatbl.c | 4 +++- sys/netinet/in.c | 2 +- sys/netinet6/in6.c | 2 +- sys/netinet6/nd6.c | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/net/if_llatbl.c b/sys/net/if_llatbl.c index b82bc9fc104c..d2fb58974d3f 100644 --- a/sys/net/if_llatbl.c +++ b/sys/net/if_llatbl.c @@ -926,8 +926,10 @@ lla_rt_output(struct rt_msghdr *rtm, struct rt_addrinfo *info) linkhdrsize = sizeof(linkhdr); if (lltable_calc_llheader(ifp, dst->sa_family, LLADDR(dl), - linkhdr, &linkhdrsize, &lladdr_off) != 0) + linkhdr, &linkhdrsize, &lladdr_off) != 0) { + lltable_free_entry(llt, lle); return (EINVAL); + } lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize, lladdr_off); if ((rtm->rtm_flags & RTF_ANNOUNCE)) diff --git a/sys/netinet/in.c b/sys/netinet/in.c index a504f54a026e..e427b9e92db3 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1563,7 +1563,7 @@ in_lltable_alloc(struct lltable *llt, u_int flags, const struct sockaddr *l3addr linkhdrsize = LLE_MAX_LINKHDR; if (lltable_calc_llheader(ifp, AF_INET, IF_LLADDR(ifp), linkhdr, &linkhdrsize, &lladdr_off) != 0) { - NET_EPOCH_CALL(in_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx); + in_lltable_free_entry(llt, lle); return (NULL); } lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize, diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 3c03c2996d9b..c273d74b565c 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -2325,7 +2325,7 @@ in6_lltable_alloc(struct lltable *llt, u_int flags, linkhdrsize = LLE_MAX_LINKHDR; if (lltable_calc_llheader(ifp, AF_INET6, IF_LLADDR(ifp), linkhdr, &linkhdrsize, &lladdr_off) != 0) { - NET_EPOCH_CALL(in6_lltable_destroy_lle_unlocked, &lle->lle_epoch_ctx); + in6_lltable_free_entry(llt, lle); return (NULL); } lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize, diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 6a9e2a4fdd7c..69da61aa9c5c 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -2036,8 +2036,10 @@ nd6_cache_lladdr(struct ifnet *ifp, struct in6_addr *from, char *lladdr, if (lladdr != NULL) { linkhdrsize = sizeof(linkhdr); if (lltable_calc_llheader(ifp, AF_INET6, lladdr, - linkhdr, &linkhdrsize, &lladdr_off) != 0) + linkhdr, &linkhdrsize, &lladdr_off) != 0) { + lltable_free_entry(LLTABLE6(ifp), ln); return; + } lltable_set_entry_addr(ifp, ln, linkhdr, linkhdrsize, lladdr_off); }