Skip to contentSkip to conversation

MCTP fixes

PATCH Applied Matt Johnston 2 participants 5 messages Apr 1, 2022

Subsystems (3)
lore
Share & tools
lore

Matt Johnston

author maintainer
#0 lore raw

cover MCTP fixes

Hi,

The following are fixes for the mctp core and mctp-i2c driver.

Thanks,
Matt

Matt Johnston (3):
mctp: Fix check for dev_hard_header() result mctp i2c: correct mctp_i2c_header_create result
mctp: Use output netdev to allocate skb headroom

 drivers/net/mctp/mctp-i2c.c |  2 +-
 include/net/mctp.h          |  2 --
 net/mctp/af_mctp.c          | 46 ++++++++++++++++++++++++++-----------
 net/mctp/route.c            | 16 +++++++++----
 4 files changed, 46 insertions(+), 20 deletions(-)
Signature · 1 line
2.32.0
author maintainer
#1 lore raw

PATCH 1/3 mctp: Fix check for dev_hard_header() result

dev_hard_header() returns the length of the header, so we need to test for negative errors rather than non-zero.

Fixes 889b7da23abf ("mctp: Add initial routing framework")
---
 net/mctp/route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mctp/route.c +1 -1
index d5e7db83fe9d..ee548c46c78f 100644
@@ -512,7 +512,7 @@ static int mctp_route_output(struct mctp_route *route, struct sk_buff *skb)
 
 	rc = dev_hard_header(skb, skb->dev, ntohs(skb->protocol),
 			     daddr, skb->dev->dev_addr, skb->len);
-	if (rc) {
+	if (rc < 0) {
 		kfree_skb(skb);
 		return -EHOSTUNREACH;
 	}
Signature · 1 line
2.32.0
author maintainer
#2 lore raw

PATCH 2/3 mctp i2c: correct mctp_i2c_header_create result

In reply to Matt Johnston

header_ops.create should return the length of the header, instead mctp_i2c_head_create() returned 0.
This didn't cause any problem because the MCTP stack accepted 0 as success.

Fixes f5b8abf9fc3d ("mctp i2c: MCTP I2C binding driver")
---
 drivers/net/mctp/mctp-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mctp/mctp-i2c.c +1 -1
index baf7afac7857..53846c6b56ca 100644
@@ -553,7 +553,7 @@ static int mctp_i2c_header_create(struct sk_buff *skb, struct net_device *dev,
 	hdr->source_slave = ((llsrc << 1) & 0xff) | 0x01;
 	mhdr->ver = 0x01;
 
-	return 0;
+	return sizeof(struct mctp_i2c_hdr);
 }
 
 static int mctp_i2c_tx_thread(void *data)
Signature · 1 line
2.32.0
author maintainer
#3 lore raw

PATCH 3/3 mctp: Use output netdev to allocate skb headroom

In reply to Matt Johnston

Previously the skb was allocated with headroom MCTP_HEADER_MAXLEN, but that isn't sufficient if we are using devs that are not MCTP specific.

This also adds a check that the smctp_halen provided to sendmsg for extended addressing is the correct size for the netdev.

Fixes 833ef3b91de6 ("mctp: Populate socket implementation")
---
 include/net/mctp.h |  2 --
 net/mctp/af_mctp.c | 46 +++++++++++++++++++++++++++++++++-------------
 net/mctp/route.c   | 14 +++++++++++---
 3 files changed, 44 insertions(+), 18 deletions(-)
include/net/mctp.h +0 -2
index d37268fe6825..82800d521c3d 100644
@@ -36,8 +36,6 @@ struct mctp_hdr {
 #define MCTP_HDR_TAG_SHIFT	0
 #define MCTP_HDR_TAG_MASK	GENMASK(2, 0)
 
-#define MCTP_HEADER_MAXLEN	4
-
 #define MCTP_INITIAL_DEFAULT_NET	1
 
 static inline bool mctp_address_unicast(mctp_eid_t eid)
net/mctp/af_mctp.c +33 -13

77 lines not on this page · raw message

net/mctp/route.c +11 -3
index ee548c46c78f..3b24b8d18b5b 100644
@@ -503,6 +503,11 @@ static int mctp_route_output(struct mctp_route *route, struct sk_buff *skb)
 
 	if (cb->ifindex) {
 		/* direct route; use the hwaddr we stashed in sendmsg */
+		if (cb->halen != skb->dev->addr_len) {
+			/* sanity check, sendmsg should have already caught this */
+			kfree_skb(skb);
+			return -EMSGSIZE;
+		}
 		daddr = cb->haddr;
 	} else {
 		/* If lookup fails let the device handle daddr==NULL */
@@ -756,7 +761,7 @@ static int mctp_do_fragment_route(struct mctp_route *rt, struct sk_buff *skb,
 {
 	const unsigned int hlen = sizeof(struct mctp_hdr);
 	struct mctp_hdr *hdr, *hdr2;
-	unsigned int pos, size;
+	unsigned int pos, size, headroom;
 	struct sk_buff *skb2;
 	int rc;
 	u8 seq;
@@ -770,6 +775,9 @@ static int mctp_do_fragment_route(struct mctp_route *rt, struct sk_buff *skb,
 		return -EMSGSIZE;
 	}
 
+	/* keep same headroom as the original skb */
+	headroom = skb_headroom(skb);
+
 	/* we've got the header */
 	skb_pull(skb, hlen);
 
@@ -777,7 +785,7 @@ static int mctp_do_fragment_route(struct mctp_route *rt, struct sk_buff *skb,
 		/* size of message payload */
 		size = min(mtu - hlen, skb->len - pos);
 
-		skb2 = alloc_skb(MCTP_HEADER_MAXLEN + hlen + size, GFP_KERNEL);
+		skb2 = alloc_skb(headroom + hlen + size, GFP_KERNEL);
 		if (!skb2) {
 			rc = -ENOMEM;
 			break;
@@ -793,7 +801,7 @@ static int mctp_do_fragment_route(struct mctp_route *rt, struct sk_buff *skb,
 			skb_set_owner_w(skb2, skb->sk);
 
 		/* establish packet */
-		skb_reserve(skb2, MCTP_HEADER_MAXLEN);
+		skb_reserve(skb2, headroom);
 		skb_reset_network_header(skb2);
 		skb_put(skb2, hlen + size);
 		skb2->transport_header = skb2->network_header + hlen;
Signature · 1 line
2.32.0
#4 lore raw
In reply to Matt Johnston
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 8 lines · On Fri, 1 Apr 2022 10:48:41 +0800 you wrote:

Hi,

The following are fixes for the mctp core and mctp-i2c driver.

Thanks,
Matt

[...]

Here is the summary with links:
- [net,1/3] mctp: Fix check for dev_hard_header() result

    https://git.kernel.org/netdev/net/c/60be976ac451
  - [net,2/3] mctp i2c: correct mctp_i2c_header_create result
    https://git.kernel.org/netdev/net/c/8ce40a2fd350
  - [net,3/3] mctp: Use output netdev to allocate skb headroom
    https://git.kernel.org/netdev/net/c/4a9dda1c1da6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html