From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 887723B14CC for ; Wed, 16 Sep 2026 20:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789589389; cv=none; b=iqNK0zLiENiB5qYYFV42S/FHJ2gILLAn40TJS/CXYDikUqRhx8QZfAaxE+QLvu7gNDw1qROXe3Wa5EFdrnIsMrd8QLz/cT32J/qvVO2QgEX+OMEw2ycjkjbPpil6at9P7L18oVoSE9mqV4exQjuUvIsYxjdaDXQ/zPN/xZax7dY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789589389; c=relaxed/simple; bh=AUyvQEyTcYR4cUIQjR8EoKPlRNb2meKDjXUWfR8feCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=efE6bnt2sXIQ8l0xJmYsBT4pWUChoag5foqbIW0qD+mgUyHUjwvQQAD4MOxn+4rabKLZJJbjWXy7el9G7wgEcL75mUjA02ATSt3k/jq/eze5MY8/W6x15Xv54/3F356E0NAL/vpj8ifdomiDk4yNY+tX1prc+B3C3ZuKRcUVn+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Th7i0hkw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Th7i0hkw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97D0C1F000FF; Wed, 16 Sep 2026 20:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789589373; bh=nTLBlnS7KSim6dm2/kS1rWHSYnvAdlQorV82rskd/dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Th7i0hkwIYtJDk6eKbV0PL+TC12QsvfV8a93N6eYyBpGXz+mtOfnjLZ7S0shgHqV/ VNzA3/2S59tcROVTIrWD8o+15LxS8vDPoI4/XGu5FY63usE9/ZEOmvbAuop1bEwesL oF4VOZHBZdC1xFDsOMj60Fzdpeo27QeJEie6h3mVSVUcE+nT7XoHf3sF5sQ/1XElmG CJkPUhYCDqf5B35g2Pmwh1eBuBHm0znVyfdmBfdQ7olSawfqA3u5uoRSA82c8JWl44 7xjDmIEqlGaEeOmlBf8skMsAbZ6Rj6LJjYl9yocZIuJP2Np1fgoMu3LFdF54kpZsY3 Fn1icuXTIBnwQ== From: Sasha Levin To: stable@vger.kernel.org Cc: XingWang Xiang , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18.y] genetlink: pin family module during policy dump Date: Wed, 16 Sep 2026 16:09:31 -0400 Message-ID: <20260916200931.2474712-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026091631-uneven-moneywise-f841@gregkh> References: <2026091631-uneven-moneywise-f841@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: XingWang Xiang [ Upstream commit 6a1094c34d176827b2b173e163dcc964a13af93f ] The generic netlink controller's policy dump keeps pointers to the target family's operation and policy tables in its callback state. A dump may be split across multiple skbs and remain pending after the initial request. Netlink pins the module which owns the dump callback, but in this case that is the controller's owner rather than the target family's owner. The target family can consequently be unregistered and its module unloaded while a policy dump is pending. Advancing the dump then dereferences policy memory from the unloaded module. Take a reference to the target family's module when the dump starts. Drop it from the error and done paths. This matches the lifetime for which the dump context retains the family and policy pointers. Fixes: d07dcf9aadd6 ("netlink: add infrastructure to expose policies to userspace") Cc: stable@vger.kernel.org Signed-off-by: XingWang Xiang Link: https://patch.msgid.link/20260902084317.4092542-1-v3rdant.xiang@gmail.com Signed-off-by: Jakub Kicinski [ Adjusted context to retain kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL) instead of kmalloc_obj(*ctx->op_iter). ] Signed-off-by: Sasha Levin --- net/netlink/genetlink.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 978c129c60950..81b4494e2db74 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -1514,6 +1514,7 @@ struct ctrl_dump_policy_ctx { struct netlink_policy_dump_state *state; const struct genl_family *rt; struct genl_op_iter *op_iter; + struct module *owner; u32 op; u16 fam_id; u8 dump_map:1, @@ -1556,6 +1557,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) return -ENOENT; ctx->rt = rt; + ctx->owner = rt->module; + if (!try_module_get(ctx->owner)) + return -ENOENT; if (tb[CTRL_ATTR_OP]) { struct genl_split_ops doit, dump; @@ -1566,7 +1570,7 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) err = genl_get_cmd_both(ctx->op, rt, &doit, &dump); if (err) { NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]); - return err; + goto err_put_owner; } if (doit.policy) { @@ -1584,16 +1588,20 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) goto err_free_state; } - if (!ctx->state) - return -ENODATA; + if (!ctx->state) { + err = -ENODATA; + goto err_put_owner; + } ctx->dump_map = 1; return 0; } ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL); - if (!ctx->op_iter) - return -ENOMEM; + if (!ctx->op_iter) { + err = -ENOMEM; + goto err_put_owner; + } genl_op_iter_init(rt, ctx->op_iter); ctx->dump_map = genl_op_iter_next(ctx->op_iter); @@ -1625,6 +1633,8 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) netlink_policy_dump_free(ctx->state); err_free_op_iter: kfree(ctx->op_iter); +err_put_owner: + module_put(ctx->owner); return err; } @@ -1761,6 +1771,7 @@ static int ctrl_dumppolicy_done(struct netlink_callback *cb) kfree(ctx->op_iter); netlink_policy_dump_free(ctx->state); + module_put(ctx->owner); return 0; } -- 2.53.0