Skip to content

Commit 3aef021

Browse files
Tomas Winklergregkh
authored andcommitted
mei: limit number of bytes in mei header.
The MEI message header provides only 9 bits for storing the message size, limiting to 511. In theory the host buffer (hbuf) can contain up to 1020 bytes (limited by byte = 255 * 4) With the current hardware and hbuf size 512, this is not a real issue, but as hardening approach we enforce the limit. Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Link: https://lore.kernel.org/r/20200211160522.7562-1-tomas.winkler@intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6736041 commit 3aef021

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/misc/mei/client.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
15851585
goto err;
15861586
}
15871587

1588-
hbuf_len = mei_slots2data(hbuf_slots);
1588+
hbuf_len = mei_slots2data(hbuf_slots) & MEI_MSG_MAX_LEN_MASK;
15891589
dr_slots = mei_dma_ring_empty_slots(dev);
15901590
dr_len = mei_slots2data(dr_slots);
15911591

@@ -1718,7 +1718,7 @@ ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb)
17181718
goto out;
17191719
}
17201720

1721-
hbuf_len = mei_slots2data(hbuf_slots);
1721+
hbuf_len = mei_slots2data(hbuf_slots) & MEI_MSG_MAX_LEN_MASK;
17221722
dr_slots = mei_dma_ring_empty_slots(dev);
17231723
dr_len = mei_slots2data(dr_slots);
17241724

‎drivers/misc/mei/hw.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ struct mei_msg_hdr {
209209
u32 extension[0];
210210
} __packed;
211211

212+
/* The length is up to 9 bits */
213+
#define MEI_MSG_MAX_LEN_MASK GENMASK(9, 0)
214+
212215
#define MEI_MSG_HDR_MAX 2
213216

214217
struct mei_bus_message {

0 commit comments

Comments
 (0)