Skip to content

Commit 108c8b6

Browse files
committed
Merge tag 'thunderbolt-for-v7.1-rc7' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-linus
Mika writes: thunderbolt: Fixes for v7.1-rc7 This includes more fixes to harden XDomain message handling against possible malicious hosts. All these have been in linux-next with no reported issues. * tag 'thunderbolt-for-v7.1-rc7' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt: thunderbolt: Limit XDomain response copy to actual frame size thunderbolt: Validate XDomain request packet size before type cast thunderbolt: Clamp XDomain response data copy to allocation size thunderbolt: Bound root directory content to block size thunderbolt: Reject zero-length property entries in validator
2 parents e43ffb6 + 4db2bd2 commit 108c8b6

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

drivers/thunderbolt/property.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static bool tb_property_entry_valid(const struct tb_property_entry *entry,
6060
case TB_PROPERTY_TYPE_DIRECTORY:
6161
case TB_PROPERTY_TYPE_DATA:
6262
case TB_PROPERTY_TYPE_TEXT:
63+
if (!entry->length)
64+
return false;
6365
if (entry->length > block_len)
6466
return false;
6567
if (check_add_overflow(entry->value, entry->length, &end) ||
@@ -185,6 +187,10 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block,
185187
if (is_root) {
186188
content_offset = dir_offset + 2;
187189
content_len = dir_len;
190+
if (content_offset + content_len > block_len) {
191+
tb_property_free_dir(dir);
192+
return NULL;
193+
}
188194
} else {
189195
if (dir_len < 4) {
190196
tb_property_free_dir(dir);

drivers/thunderbolt/xdomain.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static const char * const state_names[] = {
5555
struct xdomain_request_work {
5656
struct work_struct work;
5757
struct tb_xdp_header *pkg;
58+
size_t pkg_len;
5859
struct tb *tb;
5960
};
6061

@@ -122,7 +123,9 @@ static bool tb_xdomain_match(const struct tb_cfg_request *req,
122123
static bool tb_xdomain_copy(struct tb_cfg_request *req,
123124
const struct ctl_pkg *pkg)
124125
{
125-
memcpy(req->response, pkg->buffer, req->response_size);
126+
size_t len = min_t(size_t, pkg->frame.size, req->response_size);
127+
128+
memcpy(req->response, pkg->buffer, len);
126129
req->result.err = 0;
127130
return true;
128131
}
@@ -393,6 +396,8 @@ static int tb_xdp_properties_request(struct tb_ctl *ctl, u64 route,
393396
}
394397
}
395398

399+
if (req.offset + len > data_len)
400+
len = data_len - req.offset;
396401
memcpy(data + req.offset, res->data, len * 4);
397402
req.offset += len;
398403
} while (!data_len || req.offset < data_len);
@@ -731,6 +736,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
731736
struct xdomain_request_work *xw = container_of(work, typeof(*xw), work);
732737
const struct tb_xdp_header *pkg = xw->pkg;
733738
const struct tb_xdomain_header *xhdr = &pkg->xd_hdr;
739+
size_t pkg_len = xw->pkg_len;
734740
struct tb *tb = xw->tb;
735741
struct tb_ctl *ctl = tb->ctl;
736742
struct tb_xdomain *xd;
@@ -762,7 +768,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
762768
switch (pkg->type) {
763769
case PROPERTIES_REQUEST:
764770
tb_dbg(tb, "%llx: received XDomain properties request\n", route);
765-
if (xd) {
771+
if (xd && pkg_len >= sizeof(struct tb_xdp_properties)) {
766772
ret = tb_xdp_properties_response(tb, ctl, xd, sequence,
767773
(const struct tb_xdp_properties *)pkg);
768774
}
@@ -816,7 +822,8 @@ static void tb_xdp_handle_request(struct work_struct *work)
816822
tb_dbg(tb, "%llx: received XDomain link state change request\n",
817823
route);
818824

819-
if (xd && xd->state == XDOMAIN_STATE_BONDING_UUID_HIGH) {
825+
if (xd && xd->state == XDOMAIN_STATE_BONDING_UUID_HIGH &&
826+
pkg_len >= sizeof(struct tb_xdp_link_state_change)) {
820827
const struct tb_xdp_link_state_change *lsc =
821828
(const struct tb_xdp_link_state_change *)pkg;
822829

@@ -868,6 +875,7 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
868875
kfree(xw);
869876
return false;
870877
}
878+
xw->pkg_len = size;
871879
xw->tb = tb_domain_get(tb);
872880

873881
schedule_work(&xw->work);

0 commit comments

Comments
 (0)