Commit 33f5d1a9 authored by Matt Johnston's avatar Matt Johnston Committed by Jakub Kicinski

mctp i2c: Fix hard head TX bounds length check

We should be testing the length before fitting into the u8 byte_count.
This is just a sanity check, the MCTP stack should have limited to MTU
which is checked, and we check consistency later in mctp_i2c_xmit().

Found by Smatch
mctp_i2c_header_create() warn: impossible condition
    '(hdr->byte_count > 255) => (0-255 > 255)'
Signed-off-by: default avatarMatt Johnston <matt@codeconstruct.com.au>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 06bf1ce6
...@@ -537,6 +537,9 @@ static int mctp_i2c_header_create(struct sk_buff *skb, struct net_device *dev, ...@@ -537,6 +537,9 @@ static int mctp_i2c_header_create(struct sk_buff *skb, struct net_device *dev,
struct mctp_hdr *mhdr; struct mctp_hdr *mhdr;
u8 lldst, llsrc; u8 lldst, llsrc;
if (len > MCTP_I2C_MAXMTU)
return -EMSGSIZE;
lldst = *((u8 *)daddr); lldst = *((u8 *)daddr);
llsrc = *((u8 *)saddr); llsrc = *((u8 *)saddr);
...@@ -547,8 +550,6 @@ static int mctp_i2c_header_create(struct sk_buff *skb, struct net_device *dev, ...@@ -547,8 +550,6 @@ static int mctp_i2c_header_create(struct sk_buff *skb, struct net_device *dev,
hdr->dest_slave = (lldst << 1) & 0xff; hdr->dest_slave = (lldst << 1) & 0xff;
hdr->command = MCTP_I2C_COMMANDCODE; hdr->command = MCTP_I2C_COMMANDCODE;
hdr->byte_count = len + 1; hdr->byte_count = len + 1;
if (hdr->byte_count > MCTP_I2C_MAXBLOCK)
return -EMSGSIZE;
hdr->source_slave = ((llsrc << 1) & 0xff) | 0x01; hdr->source_slave = ((llsrc << 1) & 0xff) | 0x01;
mhdr->ver = 0x01; mhdr->ver = 0x01;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment