From nobody Wed Nov 18 19:11:22 2026 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 4jVB625vTDz714x5 for ; Wed, 18 Nov 2026 19:11:22 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jVB625KwFz4v1F for ; Wed, 18 Nov 2026 19:11:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795029082; 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=uNnUi2XoRbQQRZvLXYVLiJ5lPVhsmy6x/lnG/ITLWrs=; b=H1dXCvRUutTlMxFZD2haPHJTSqtZ+qNORYTmLajrsusHB2WVSec+F/ydEgP8ThITi3O9wy NM/fBwy8p6Ro4pvtxSbtx2DHyCjwj1GSocwYUDtHHcmLi1JVhojPvTECJgiRum+1QlTBgs aUfQnzYwrE5djdB+VxH3wyx2w1goNefS3BZWPFfWdQNCmGRdELwyo2dk16rgQIR8CL77EB z6u7QaQuzDXi1+/xG/cmTBucTtkEDimFoFqmlhBiu7v7wiWLa6Sz9yf4FfnA42AMwDBRRV ON7UB7DOYwU7s4s7Q4ZJ3byZHnGOsLCcWD0yepHARaVndwRzXB9ImNMHhMORng== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795029082; b=GW7CiN5FMf1RuVnB6iJbUv/WnEtVM//hxZq+30cg/IT/gkoruF/FHk7RbP2LVRZhbxyQur 40eW3oEV+rrlGex31A7oJcXSI/RonjIbGnS+ENIT1DEUOiYRsEceUWnr3XXP67KN08h1kz QSzJXvg0K6Tzaa4sNDMKAHhQspqldRCslkIZlfdJMjhPmxq3wftXV8HrXjj3rNeASiKxUe mU/4YF1NQs5OCUlDdWAjxHgoXEAlxftq46/4fRGWpqVhQViNyj5oXlKow6qnUvMmBjPsvE stVcltKpBpJd7LNjdVeqwRkEETAwxV2QKYQSOGH8VcRyeODGSjFxu8q1pxstNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795029082; 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=uNnUi2XoRbQQRZvLXYVLiJ5lPVhsmy6x/lnG/ITLWrs=; b=ayH4i+wWKBiLtTRbNXbOElRqk3/LbxnFfZOV+MA1UX+A+eUcOMgmA8x6jmN6fixFUH3f0U oceld57dBVfApkLLLdKYMU711Yd43kzrMAxXOASsRA960LEz8Q8ubIPMQJ9XJhyUUN377Y ChAZ5eCEU5KySlRl+bnWQGWHQOhjr1OVne7zpcU5GIRR0ElQGUj5FbG3aSl2s0NqNLDcVW 1dGeaAKw4oVuKdrn2jmUtWXBkH4Nzi0vnXzfTO4Hc2C9PmefDOchG3gxguJM5rgFyMKpZw CbqsSzMSPR2dPDRHhRh2Nkm8JHLQgKA6WKZOKed1l55F+2dCUSGbQfVhq2ehQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jVB6250kLzQdg for ; Wed, 18 Nov 2026 19:11:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 136df by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 19:11:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Pouria Mousavizadeh Tehrani Subject: git: c15a606d2f44 - main - route/fib_algo: Fix nexthop reference leak on FLM_BATCH List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pouria X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c15a606d2f4443e3f3ba775532f0f499efaff3b7 Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 19:11:22 +0000 Message-Id: <6afdf85a.136df.6747ab9d@gitrepo.freebsd.org> The branch main has been updated by pouria: URL: https://cgit.FreeBSD.org/src/commit/?id=c15a606d2f4443e3f3ba775532f0f499efaff3b7 commit c15a606d2f4443e3f3ba775532f0f499efaff3b7 Author: Pouria Mousavizadeh Tehrani AuthorDate: 2026-11-18 19:00:11 +0000 Commit: Pouria Mousavizadeh Tehrani CommitDate: 2026-11-18 19:09:00 +0000 route/fib_algo: Fix nexthop reference leak on FLM_BATCH handle_rtable_change_cb() references the new nexthop before calling the algorithm. If the algorithm asks to batch the change by returning FLM_BATCH, queue_rtable_change() references the same nexthop again for the queued entry, while apply_rtable_changes() only unreferences the old nexthop of each entry. Reference new nhop once in handle_rtable_change_cb(), before deciding whether the change is queued or passed to the algorithm, and do not reference it again in fill_change_entry(). This also leaves the queue reallocation as the only way for queue_rtable_change() to fail. Currently, dxr is the only algorithm returning FLM_BATCH. Fixes: 6b8ef0d428c9 ("Add batched update support for the fib algo.") MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D61577 --- sys/net/route/fib_algo.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c index edeac703fedc..92de90183257 100644 --- a/sys/net/route/fib_algo.c +++ b/sys/net/route/fib_algo.c @@ -734,7 +734,11 @@ apply_rtable_changes(struct fib_data *fd) return (result == FLM_SUCCESS); } -static bool +/* + * Fills in queue entry @ce with the change described by @rc. + * The caller holds the reference to the new nexthop. + */ +static void fill_change_entry(struct fib_data *fd, struct fib_change_entry *ce, struct rib_cmd_info *rc) { int plen = 0; @@ -755,12 +759,6 @@ fill_change_entry(struct fib_data *fd, struct fib_change_entry *ce, struct rib_c ce->plen = plen; ce->nh_old = rc->rc_nh_old; ce->nh_new = rc->rc_nh_new; - if (ce->nh_new != NULL) { - if (fib_ref_nhop(fd, ce->nh_new) == 0) - return (false); - } - - return (true); } static bool @@ -787,7 +785,9 @@ queue_rtable_change(struct fib_data *fd, struct rib_cmd_info *rc) q->size = q_size; } - return (fill_change_entry(fd, &q->entries[q->count++], rc)); + fill_change_entry(fd, &q->entries[q->count++], rc); + + return (true); } /* @@ -827,21 +827,6 @@ handle_rtable_change_cb(struct rib_head *rnh, struct rib_cmd_info *rc, return; } - /* - * Algo requested updates to be delivered in batches. - * Add the current change to the queue and return. - */ - if (fd->fd_batch) { - if (immediate_sync) { - if (!queue_rtable_change(fd, rc) || !apply_rtable_changes(fd)) - rebuild_fd(fd, "batch sync failed"); - } else { - if (!queue_rtable_change(fd, rc)) - schedule_fd_rebuild(fd, "batch queue failed"); - } - return; - } - /* * Maintain guarantee that every nexthop returned by the dataplane * lookup has > 0 refcount, so can be safely referenced within current @@ -857,6 +842,21 @@ handle_rtable_change_cb(struct rib_head *rnh, struct rib_cmd_info *rc, } } + /* + * Algo requested updates to be delivered in batches. + * Add the current change to the queue and return. + */ + if (fd->fd_batch) { + if (immediate_sync) { + if (!queue_rtable_change(fd, rc) || !apply_rtable_changes(fd)) + rebuild_fd(fd, "batch sync failed"); + } else { + if (!queue_rtable_change(fd, rc)) + schedule_fd_rebuild(fd, "batch queue failed"); + } + return; + } + result = fd->fd_flm->flm_change_rib_item_cb(rnh, rc, fd->fd_algo_data); switch (result) {