Skip to content

Commit 4d1356a

Browse files
Andrey Shvetsovgregkh
authored andcommitted
staging: most: net: fix buffer overflow
If the length of the socket buffer is 0xFFFFFFFF (max size for an unsigned int), then payload_len becomes 0xFFFFFFF1 after subtracting 14 (ETH_HLEN). Then, mdp_len is set to payload_len + 16 (MDP_HDR_LEN) which overflows and results in a value of 2. These values for payload_len and mdp_len will pass current buffer size checks. This patch checks if derived from skb->len sum may overflow. The check is based on the following idea: For any `unsigned V1, V2` and derived `unsigned SUM = V1 + V2`, `V1 + V2` overflows iif `SUM < V1`. Reported-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Andrey Shvetsov <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3063da9 commit 4d1356a

File tree

1 file changed

+10
-0
lines changed
  • drivers/staging/most/net

1 file changed

+10
-0
lines changed

drivers/staging/most/net/net.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
8282
unsigned int payload_len = skb->len - ETH_HLEN;
8383
unsigned int mdp_len = payload_len + MDP_HDR_LEN;
8484

85+
if (mdp_len < skb->len) {
86+
pr_err("drop: too large packet! (%u)\n", skb->len);
87+
return -EINVAL;
88+
}
89+
8590
if (mbo->buffer_length < mdp_len) {
8691
pr_err("drop: too small buffer! (%d for %d)\n",
8792
mbo->buffer_length, mdp_len);
@@ -129,6 +134,11 @@ static int skb_to_mep(const struct sk_buff *skb, struct mbo *mbo)
129134
u8 *buff = mbo->virt_address;
130135
unsigned int mep_len = skb->len + MEP_HDR_LEN;
131136

137+
if (mep_len < skb->len) {
138+
pr_err("drop: too large packet! (%u)\n", skb->len);
139+
return -EINVAL;
140+
}
141+
132142
if (mbo->buffer_length < mep_len) {
133143
pr_err("drop: too small buffer! (%d for %d)\n",
134144
mbo->buffer_length, mep_len);

0 commit comments

Comments
 (0)