From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: Vikash Garodia <quic_vgarodia@quicinc.com>,
Stanimir Varbanov <stanimir.k.varbanov@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/4] media: venus: hfi_parser: avoid OOB access beyond payload word count
Date: Tue, 12 Nov 2024 11:17:46 +0000 [thread overview]
Message-ID: <f6e661da-6a8f-4555-881e-264e8518f50c@linaro.org> (raw)
In-Reply-To: <c9783a99-724a-cdf0-7e76-7cbf2c77d63f@quicinc.com>
On 12/11/2024 08:05, Vikash Garodia wrote:
> You did not printed the last iteration without the proposed fix. In the last
> iteration (Myword 1), it would access the data beyond allocated size of somebuf.
> So we can see how the fix protects from OOB situation.
Right but the loop _can't_ be correct. What's the point in fixing an OOB
in a loop that doesn't work ?
This is the loop:
#define BUF_SIZE 0x20 // BUF_SIZE doesn't really matter
char somebuf[BUF_SIZE];
u32 *word = somebuf[0];
u32 words = ARRAY_SIZE(somebuf);
while (words > 1) {
data = word + 1; // this
word++; // and this
words--;
}
On the first loop
word = somebuf[0];
data = somebuf[3];
On the second loop
word = somebuf[3]; // the same value as *data in the previous loop
and that's just broken because on the second loop *word == *data in the
first loop !
That's what my program showed you
word 4 == 0x03020100 data=0x07060504
// word == data from previous loop
word 3 == 0x07060504 data=0x0b0a0908
// word == data from previous loop
word 2 == 0x0b0a0908 data=0x0f0e0d0c
The step size, the number of bytes this loop increments is fundamentally
wrong because
a) Its a fixed size [1]
b) *word in loop(n+1) == *data in loop(n)
Which cannot ever parse more than one data item - in effect never loop -
in one go.
> For the functionality part, packet from firmware would come as <prop type>
> followed by <payload for that prop> i.e
> *word = HFI_PROPERTY_PARAM_CODEC_SUPPORTED
> *data = payload --> hence here data is pointed to next u32 to point and parse
> payload for HFI_PROPERTY_PARAM_CODEC_SUPPORTED.
> likewise for other properties in the same packet
[1]
But we've established that word increments by one word.
We wouldn't fix this loop by just making it into
while (words > 1) {
data = word + 1;
word = data + 1;
words -= 2;
}
Because the consumers of the data have different step sizes, different
number of bytes they consume for the structs they cast.
=>
case HFI_PROPERTY_PARAM_CODEC_SUPPORTED:
parse_codecs(core, data);
// consumes sizeof(struct hfi_codec_supported)
struct hfi_codec_supported {
u32 dec_codecs;
u32 enc_codecs;
};
case HFI_PROPERTY_PARAM_MAX_SESSIONS_SUPPORTED:
parse_max_sessions(core, data);
// consumes sizeof(struct hfi_max_sessions_supported)
struct hfi_max_sessions_supported {
u32 max_sessions;
};
case HFI_PROPERTY_PARAM_CODEC_MASK_SUPPORTED:
parse_codecs_mask(&codecs, &domain, data);
// consumes sizeof(struct hfi_codec_mask_supported)
struct hfi_codec_mask_supported {
u32 codecs;
u32 video_domains;
};
case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
parse_raw_formats(core, codecs, domain, data);
// consumes sizeof(struct hfi_uncompressed_format_supported)
struct hfi_uncompressed_format_supported {
u32 buffer_type;
u32 format_entries;
struct hfi_uncompressed_plane_info plane_info;
};
case HFI_PROPERTY_PARAM_CAPABILITY_SUPPORTED:
parse_caps(core, codecs, domain, data);
struct hfi_capabilities {
u32 num_capabilities;
struct hfi_capability data[];
};
where
hfi_platform.h:#define MAX_CAP_ENTRIES 32
I'll stop there.
This routine needs a rewrite.
---
bod
next prev parent reply other threads:[~2024-11-12 11:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 8:54 [PATCH 0/4] Venus driver fixes to avoid possible OOB accesses Vikash Garodia
2024-11-05 8:54 ` [PATCH 1/4] media: venus: hfi_parser: add check to avoid out of bound access Vikash Garodia
2024-11-05 10:51 ` Bryan O'Donoghue
2024-11-06 7:25 ` Vikash Garodia
2024-11-06 10:23 ` Bryan O'Donoghue
2024-11-07 8:24 ` Vikash Garodia
2024-11-05 13:55 ` Dmitry Baryshkov
2024-11-07 8:17 ` Vikash Garodia
2024-11-07 10:41 ` Dmitry Baryshkov
2024-11-07 12:07 ` Bryan O'Donoghue
2024-11-07 13:02 ` Vikash Garodia
2024-11-07 13:22 ` Dmitry Baryshkov
2024-11-07 13:35 ` Vikash Garodia
2024-11-07 13:54 ` Dmitry Baryshkov
2024-11-08 11:43 ` Bryan O'Donoghue
2024-11-11 14:02 ` Vikash Garodia
2024-11-11 14:04 ` Vikash Garodia
2024-11-05 8:54 ` [PATCH 2/4] media: venus: hfi_parser: avoid OOB access beyond payload word count Vikash Garodia
2024-11-05 11:15 ` Bryan O'Donoghue
2024-11-11 14:36 ` Vikash Garodia
2024-11-11 23:43 ` Bryan O'Donoghue
2024-11-12 8:05 ` Vikash Garodia
2024-11-12 11:17 ` Bryan O'Donoghue [this message]
2024-11-12 12:58 ` Vikash Garodia
2024-11-12 13:00 ` Bryan O'Donoghue
2024-11-05 8:54 ` [PATCH 3/4] media: venus: hfi: add check to handle incorrect queue size Vikash Garodia
2024-11-05 11:23 ` Bryan O'Donoghue
2024-11-05 8:54 ` [PATCH 4/4] media: venus: hfi: add a check to handle OOB in sfr region Vikash Garodia
2024-11-05 11:27 ` Bryan O'Donoghue
2024-11-05 13:58 ` Dmitry Baryshkov
2024-11-06 7:21 ` Vikash Garodia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6e661da-6a8f-4555-881e-264e8518f50c@linaro.org \
--to=bryan.odonoghue@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=quic_vgarodia@quicinc.com \
--cc=stable@vger.kernel.org \
--cc=stanimir.k.varbanov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®