Skip to content

Commit 9cf89ad

Browse files
vpelletiergregkh
authored andcommitted
usb: gadget: f_fs: Assorted buffer overflow checks.
commit 83e526f2a2fa4b2e82b6bd3ddbb26b70acfa8947 upstream. OS descriptor head, when flagged as provided, is accessed without checking if it fits in provided buffer. Verify length before access. Also, there are other places where buffer length it checked after accessing offsets which are potentially past the end. Check buffer length before as well to fail cleanly. Signed-off-by: Vincent Pelletier <plr.vincent@gmail.com> Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e4c1e66 commit 9cf89ad

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • drivers/usb/gadget/function

drivers/usb/gadget/function/f_fs.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,8 @@ static int __ffs_data_do_os_desc(enum ffs_os_desc_type type,
20792079
if (len < sizeof(*d) || h->interface >= ffs->interfaces_count)
20802080
return -EINVAL;
20812081
length = le32_to_cpu(d->dwSize);
2082+
if (len < length)
2083+
return -EINVAL;
20822084
type = le32_to_cpu(d->dwPropertyDataType);
20832085
if (type < USB_EXT_PROP_UNICODE ||
20842086
type > USB_EXT_PROP_UNICODE_MULTI) {
@@ -2087,6 +2089,11 @@ static int __ffs_data_do_os_desc(enum ffs_os_desc_type type,
20872089
return -EINVAL;
20882090
}
20892091
pnl = le16_to_cpu(d->wPropertyNameLength);
2092+
if (length < 14 + pnl) {
2093+
pr_vdebug("invalid os descriptor length: %d pnl:%d (descriptor %d)\n",
2094+
length, pnl, type);
2095+
return -EINVAL;
2096+
}
20902097
pdl = le32_to_cpu(*(u32 *)((u8 *)data + 10 + pnl));
20912098
if (length != 14 + pnl + pdl) {
20922099
pr_vdebug("invalid os descriptor length: %d pnl:%d pdl:%d (descriptor %d)\n",
@@ -2171,6 +2178,9 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
21712178
}
21722179
}
21732180
if (flags & (1 << i)) {
2181+
if (len < 4) {
2182+
goto error;
2183+
}
21742184
os_descs_count = get_unaligned_le32(data);
21752185
data += 4;
21762186
len -= 4;
@@ -2243,7 +2253,8 @@ static int __ffs_data_got_strings(struct ffs_data *ffs,
22432253

22442254
ENTER();
22452255

2246-
if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC ||
2256+
if (unlikely(len < 16 ||
2257+
get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC ||
22472258
get_unaligned_le32(data + 4) != len))
22482259
goto error;
22492260
str_count = get_unaligned_le32(data + 8);

0 commit comments

Comments
 (0)