Various core fixes spotted by LLMs
cover Various core fixes spotted by LLMs
A batch of core fixes for various issues identified by LLMs.
---
Leon Romanovsky (3):
RDMA/core: Preserve the selected source GID on failed AH modification RDMA/core: Free unpublished port statistics after initial-read failure RDMA/core: Reject LAG selection when source MAC lookup fails
drivers/infiniband/core/lag.c | 12 ++++++++---- drivers/infiniband/core/sysfs.c | 9 +++++++-- drivers/infiniband/core/verbs.c | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-)
---
base-commit: 66196a559be5963b1ced18418c876caf9bfb76e6
change-id: 20261015-ib-core-fixes-fa78b7068672
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>
PATCH 1/3 RDMA/core: Preserve the selected source GID on failed AH modification
From: Leon Romanovsky <[email protected]>
When an address-handle modification fails, the core replaces its source-GID reference. The old address then loses the reference which keeps its source entry alive.
--- drivers/infiniband/core/verbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/verbs.c +2 -1
@@ -1011,7 +1011,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) ah->device->ops.modify_ah(ah, ah_attr) : -EOPNOTSUPP ; - ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr); +if (!ret) + ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr);rdma_unfill_sgid_attr (ah_attr, old_sgid_attr);return ret; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH rdma-next 1/3] RDMA/core: Preserve the selected source GID on failed AH modification
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] rdma: memory leak and UAF due to missing sgid_attr refcount in rvt_modify_ah() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rdma: memory leak and UAF due to missing sgid_attr refcount in rvt_modify_ah() --
commit cfb0c41a87200fc5df90876398650807044c23ad
Author: Leon Romanovsky <[email protected]>
RDMA/core: Preserve the selected source GID on failed AH modification
When an address-handle modification fails, the core replaces its source-GID reference. This commit ensures the selected source GID is preserved by only updating ah->sgid_attr when the modification is successful.
drivers/infiniband/core/verbs.c int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) · line 1016
Quoted 12 lines
drivers/infiniband/core/verbs.c +2
-1@@ -1011,7 +1011,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) ah->device->ops.modify_ah(ah, ah_attr) : -EOPNOTSUPP ; - ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr); +if (!ret) + ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr);rdma_unfill_sgid_attr (ah_attr, old_sgid_attr);
[Severity: High]
Does this sequence expose a memory leak and use-after-free in providers that do a shallow copy of ah_attr?
For example, in drivers/infiniband/sw/rdmavt/ah.c:rvt_modify_ah(), the structure is shallowly copied:
ah->attr = *ah_attr;
This causes a memory leak of the old sgid_attr reference because rdma_put_gid_attr() is not called on the old pointer, and it adopts the new sgid_attr without incrementing its refcount.
When rdma_modify_ah() finishes, it calls rdma_unfill_sgid_attr() which drops the temporary refcount that rvt_modify_ah() copied but didn't pin. This leaves the driver's ah->attr exposed to a dangling pointer.
Later, rvt_destroy_ah() will unconditionally call:
rdma_destroy_ah_attr(&ah->attr);
This calls rdma_put_gid_attr() on the unheld pointer, resulting in a refcount underflow and use-after-free.
This path is concretely reachable via the hfi1 provider (for instance, hfi1_modify_qp0_ah() uses rdma_modify_ah() with IB_AH_GRH enabled).
Should providers like rdmavt be updated to use rdma_replace_ah_attr() to properly manage these refcounts?
Quoted 2 lines
drivers/infiniband/core/verbs.c +0
-0return ret; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/3 RDMA/core: Free unpublished port statistics after initial-read failure
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
An initial port counter read can fail after allocating its statistics buffer and wrapper. Free these both allocations.
--- drivers/infiniband/core/sysfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/infiniband/core/sysfs.c +7 -2
@@ -996,8 +996,8 @@ static int setup_hw_port_stats(struct ib_port *port, data->stats->num_counters);if (ret != data->stats->num_counters) {if (WARN_ON (ret >=0 )) -return -EINVAL ; -return ret; + ret = -EINVAL ; + goto err_free_data; } data->stats->timestamp = jiffies;
@@ -1031,6 +1031,11 @@ static int setup_hw_port_stats(struct ib_port *port, port->hw_stats_data = data;return 0 ; + +err_free_data: +rdma_free_hw_stats_struct (data->stats); +kfree (data); +return ret; } struct rdma_hw_stats *ib_get_hw_stats_port(struct ib_device *ibdev,
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH rdma-next 2/3] RDMA/core: Free unpublished port statistics after initial-read failure
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
From: Leon Romanovsky <[email protected]>
An initial port counter read can fail after allocating its statistics buffer and wrapper. Free these both allocations.
Fixes 467f432a521a ("RDMA/core: Split port and device counter sysfs attributes")Signed-off-by Leon Romanovsky <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH rdma-next 2/3] RDMA/core: Free unpublished port statistics after initial-read failure
In reply to Leon RomanovskyQuoted 15 lines · Leon Romanovsky
From: Leon Romanovsky <[email protected]>
An initial port counter read can fail after allocating its statistics buffer and wrapper. Free these both allocations.
Fixes 467f432a521a ("RDMA/core: Split port and device counter sysfsattributes")
Signed-off-by Leon Romanovsky <[email protected]>LGTM,
Reviewed-by Kalesh AP <[email protected]>
Signature · 2 lines
Regards, Kalesh AP
PATCH 3/3 RDMA/core: Reject LAG selection when source MAC lookup fails
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
GID deletion can clear the source device association after LAG lookup retains the bonding master. Ignoring the resulting L2 lookup failure copies uninitialized source MAC bytes into the synthetic hash packet.
Read the source MAC before allocating the packet and propagate lookup errors to the caller, so failed lookups cannot influence slave selection.
--- drivers/infiniband/core/lag.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/core/lag.c +8 -4
@@ -19,6 +19,11 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,u8 smac[ETH_ALEN ];bool is_ipv4;int hdr_len; +int ret; + + ret =rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac); +if (ret) +return ERR_PTR (ret); is_ipv4 =ipv6_addr_v4mapped ((struct in6_addr *)ah_attr->grh.dgid.raw); hdr_len =ETH_HLEN +sizeof (struct udphdr ) +LL_RESERVED_SPACE (netdev);
@@ -26,7 +31,7 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev, skb =alloc_skb (hdr_len, flags);if (!skb) -return NULL ; +return ERR_PTR (-ENOMEM ); skb->dev = netdev;skb_reserve (skb, hdr_len);
@@ -70,7 +75,6 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,skb_reset_mac_header (skb); eth =eth_hdr (skb); skb->protocol = eth->h_proto =htons (is_ipv4 ?ETH_P_IP :ETH_P_IPV6 ); -rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac);memcpy (eth->h_source, smac,ETH_ALEN );memcpy (eth->h_dest, ah_attr->roce.dmac,ETH_ALEN );
@@ -86,8 +90,8 @@ static struct net_device *rdma_get_xmit_slave_udp(struct ib_device *device,struct sk_buff *skb; skb =rdma_build_skb (master, ah_attr, flags); -if (!skb) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (skb)) +return ERR_CAST (skb);rcu_read_lock (); slave = netdev_get_xmit_slave(master, skb,
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH rdma-next 3/3] RDMA/core: Reject LAG selection when source MAC lookup fails
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] rdma: KMSAN uninit-value in rdma_build_skb due to partial header init --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] rdma: KMSAN uninit-value in rdma_build_skb due to partial header init --
commit fe2a587fde347fe9ebd760de282337658857e55d
Author: Leon Romanovsky <[email protected]>
RDMA/core: Reject LAG selection when source MAC lookup fails
GID deletion can clear the source device association after LAG lookup retains the bonding master. Ignoring the resulting L2 lookup failure copies uninitialized source MAC bytes into the synthetic hash packet. This commit reads the source MAC before allocating the packet and propagates lookup errors to the caller.
Quoted 4 lines
drivers/infiniband/core/lag.c +0
-0
[ ... ]
drivers/infiniband/core/lag.c static struct sk_buff *rdma_build_skb(struct net_device *netdev, · line 34
Quoted 6 lines
drivers/infiniband/core/lag.c +1
-1@@ -26,7 +31,7 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev, skb =alloc_skb (hdr_len, flags);if (!skb) -return NULL ; +return ERR_PTR (-ENOMEM );
[Severity: Medium]
Does this code expose uninitialized kernel memory to flow dissectors?
Since alloc_skb() leaves the data buffer uninitialized, bitfield assignments performed later in rdma_build_skb():
if (is_ipv4) {
skb_push(skb, sizeof(struct iphdr));
skb_reset_network_header(skb);
iph = ip_hdr(skb);
iph->frag_off = 0;
iph->version = 4;
iph->protocol = IPPROTO_UDP;
iph->ihl = 0x5;compile down to read-modify-write instructions. These instructions will read uninitialized adjacent bits (such as the IPv6 priority field in the corresponding ipv6 branch) which immediately triggers KMSAN uninit-value warnings.
Furthermore, fields like iph->tos, iph->ttl, and the UDP checksum remain completely uninitialized. When this SKB is passed to netdev_get_xmit_slave() and into __skb_flow_dissect(), a BPF flow dissector attached in the network namespace could read these uninitialized fields, potentially leaking kernel memory.
Quoted 3 lines
drivers/infiniband/core/lag.c +0
-0skb->dev = netdev;skb_reserve (skb, hdr_len);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 8 lines · Leon Romanovsky
A batch of core fixes for various issues identified by LLMs.
Signed-off-by Leon Romanovsky <[email protected]>---
Leon Romanovsky (3):
RDMA/core: Preserve the selected source GID on failed AH modification RDMA/core: Free unpublished port statistics after initial-read failure RDMA/core: Reject LAG selection when source MAC lookup fails
After some deliberation, I applied these patches anyway. Sashiko pointed out an issue unrelated to the patches.
Thanks
Quoted 14 lines
drivers/infiniband/core/lag.c | 12 ++++++++---- drivers/infiniband/core/sysfs.c | 9 +++++++-- drivers/infiniband/core/verbs.c | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-)---
base-commit:66196a559be5963b1ced18418c876caf9bfb76e6
change-id: 20261015-ib-core-fixes-fa78b7068672Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>
Quoted 1 line · Leon Romanovsky
A batch of core fixes for various issues identified by LLMs.
Applied, thanks!
[1/3] RDMA/core: Preserve the selected source GID on failed AH modification
https://git.kernel.org/rdma/rdma/c/d01ee4c8419319 [2/3] RDMA/core: Free unpublished port statistics after initial-read failure https://git.kernel.org/rdma/rdma/c/d74bdcfa89fa45 [3/3] RDMA/core: Reject LAG selection when source MAC lookup fails https://git.kernel.org/rdma/rdma/c/fdfd099222d9de
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>