Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8d0b893

Browse files
Vikash-GarodiaHans Verkuil
authored andcommitted
media: venus: hfi: add checks to handle capabilities from firmware
The hfi parser, parses the capabilities received from venus firmware and copies them to core capabilities. Consider below api, for example, fill_caps - In this api, caps in core structure gets updated with the number of capabilities received in firmware data payload. If the same api is called multiple times, there is a possibility of copying beyond the max allocated size in core caps. Similar possibilities in fill_raw_fmts and fill_profile_level functions. Cc: [email protected] Fixes: 1a73374 ("media: venus: hfi_parser: add common capability parser") Signed-off-by: Vikash Garodia <[email protected]> Signed-off-by: Stanimir Varbanov <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent b18e36d commit 8d0b893

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/media/platform/qcom/venus/hfi_parser.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ static void fill_profile_level(struct hfi_plat_caps *cap, const void *data,
8686
{
8787
const struct hfi_profile_level *pl = data;
8888

89+
if (cap->num_pl + num >= HFI_MAX_PROFILE_COUNT)
90+
return;
91+
8992
memcpy(&cap->pl[cap->num_pl], pl, num * sizeof(*pl));
9093
cap->num_pl += num;
9194
}
@@ -111,6 +114,9 @@ fill_caps(struct hfi_plat_caps *cap, const void *data, unsigned int num)
111114
{
112115
const struct hfi_capability *caps = data;
113116

117+
if (cap->num_caps + num >= MAX_CAP_ENTRIES)
118+
return;
119+
114120
memcpy(&cap->caps[cap->num_caps], caps, num * sizeof(*caps));
115121
cap->num_caps += num;
116122
}
@@ -137,6 +143,9 @@ static void fill_raw_fmts(struct hfi_plat_caps *cap, const void *fmts,
137143
{
138144
const struct raw_formats *formats = fmts;
139145

146+
if (cap->num_fmts + num_fmts >= MAX_FMT_ENTRIES)
147+
return;
148+
140149
memcpy(&cap->fmts[cap->num_fmts], formats, num_fmts * sizeof(*formats));
141150
cap->num_fmts += num_fmts;
142151
}
@@ -159,6 +168,9 @@ parse_raw_formats(struct venus_core *core, u32 codecs, u32 domain, void *data)
159168
rawfmts[i].buftype = fmt->buffer_type;
160169
i++;
161170

171+
if (i >= MAX_FMT_ENTRIES)
172+
return;
173+
162174
if (pinfo->num_planes > MAX_PLANES)
163175
break;
164176

0 commit comments

Comments
 (0)