netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: mctp: fix infinite data from mctp_dump_addrinfo
@ 2025-06-06 11:11 Patrick Williams
  2025-06-07  7:10 ` Jeremy Kerr
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Williams @ 2025-06-06 11:11 UTC (permalink / raw)
  To: Jeremy Kerr, Matt Johnston, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Kuniyuki Iwashima
  Cc: Patrick Williams, netdev, linux-kernel

Some mctp configurations result in the userspace application
`mctp addr show`, which triggers an `mctp_dump_addrinfo`, to
be given infinite data.  This was introduced by commit 2d20773aec14.

In `mctp_dump_addrinfo`, when the userspace buffer doesn't hold
enough space for all of the addresses, the function keeps the current
index in the netlink_callback so that it can resume on subsequent
calls.  There are two indexes held: interface and address.  When a
all the addresses for an interface has been sent, the code reset
the address to zero and relies on `for_each_netdev_dump` for
incrementing the index.  However, `for_each_netdev_dump` (which is
using `xa_for_each_start`) does not set the index for the last
entry[1].  This can lead to the subsequent userspace request re-sending
the entire last interface.

Fix this by explicitly setting the index to ULONG_MAX[2] when all of
the interfaces and addresses have been successfully sent.  This will
cause subsequent userspace request to be past the last interface in the
next `for_each_netdev_dump` call.

The previous failure could be aggravated by on a system using
aspeed-bmc-facebook-harma.dts by running:
```
    mctp addr add 8 dev mctpi2c1
    mctp addr show
```

[1]: https://github.com/torvalds/linux/blob/e271ed52b344ac02d4581286961d0c40acc54c03/lib/xarray.c#L2261
[2]: https://github.com/torvalds/linux/blob/e271ed52b344ac02d4581286961d0c40acc54c03/include/linux/xarray.h#L481

Fixes: 2d20773aec14 ("mctp: no longer rely on net->dev_index_head[]")
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
---
 net/mctp/device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/mctp/device.c b/net/mctp/device.c
index 4d404edd7446..a865445234af 100644
--- a/net/mctp/device.c
+++ b/net/mctp/device.c
@@ -140,9 +140,11 @@ static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb)
 		rc = mctp_dump_dev_addrinfo(mdev, skb, cb);
 		mctp_dev_put(mdev);
 		if (rc < 0)
-			break;
+			goto out;
 		mcb->a_idx = 0;
 	}
+	mcb->ifindex = ULONG_MAX;
+out:
 	rcu_read_unlock();
 
 	return skb->len;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-09 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-06 11:11 [PATCH] net: mctp: fix infinite data from mctp_dump_addrinfo Patrick Williams
2025-06-07  7:10 ` Jeremy Kerr
2025-06-07  7:47   ` Jeremy Kerr
2025-06-09 12:54     ` Patrick Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).