aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2026-05-22 14:41:16 +0000
committerEd Maste <emaste@FreeBSD.org>2026-05-23 16:22:36 +0000
commit1dbc104148845434575d1931d47876ae0ca1542f (patch)
treec3e44392b8ab2b0ac0da0e7dabe1c2074156e504
parent50caa0ea0c16499c40e785b5aa37053b180b2830 (diff)
netlink: Check for NULL return from npt_alloc()
Reviewed by: glebius, pouria Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57171
-rw-r--r--sys/netlink/netlink_message_parser.c2
-rw-r--r--sys/netlink/route/iface_drivers.c3
-rw-r--r--sys/netlink/route/rt.c4
3 files changed, 9 insertions, 0 deletions
diff --git a/sys/netlink/netlink_message_parser.c b/sys/netlink/netlink_message_parser.c
index 54aceb660a98..65de7cc645a0 100644
--- a/sys/netlink/netlink_message_parser.c
+++ b/sys/netlink/netlink_message_parser.c
@@ -122,6 +122,8 @@ nlmsg_report_cookie_u32(struct nl_pstate *npt, uint32_t val)
{
struct nlattr *nla = npt_alloc(npt, sizeof(*nla) + sizeof(uint32_t));
+ if (nla == NULL)
+ return;
nla->nla_type = NLMSGERR_ATTR_COOKIE;
nla->nla_len = sizeof(*nla) + sizeof(uint32_t);
memcpy(nla + 1, &val, sizeof(uint32_t));
diff --git a/sys/netlink/route/iface_drivers.c b/sys/netlink/route/iface_drivers.c
index 4f1540740ead..31d2523a479b 100644
--- a/sys/netlink/route/iface_drivers.c
+++ b/sys/netlink/route/iface_drivers.c
@@ -155,6 +155,9 @@ _nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp)
sizeof(ifindex) + NL_ITEM_ALIGN(ifname_len + 1);
struct nlattr *nla_cookie = npt_alloc(npt, nla_len);
+ if (nla_cookie == NULL)
+ return;
+
/* Nested TLV */
nla_cookie->nla_len = nla_len;
nla_cookie->nla_type = NLMSGERR_ATTR_COOKIE;
diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c
index 09717c976021..8159409c9f67 100644
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -896,6 +896,10 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
int num_nhops = attrs->rta_multipath->num_nhops;
struct weightened_nhop *wn = npt_alloc(npt, sizeof(*wn) * num_nhops);
+ if (wn == NULL) {
+ *perror = ENOMEM;
+ return (NULL);
+ }
for (int i = 0; i < num_nhops; i++) {
struct rta_mpath_nh *mpnh = &attrs->rta_multipath->nhops[i];