Message ID | 20241105-venus_oob-v1-1-8d4feedfe2bb@quicinc.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Venus driver fixes to avoid possible OOB accesses | expand |
On 05/11/2024 08:54, Vikash Garodia wrote: > There is a possibility that init_codecs is invoked multiple times during > manipulated payload from video firmware. In such case, if codecs_count > can get incremented to value more than MAX_CODEC_NUM, there can be OOB > access. Keep a check for max accessible memory before accessing it. > > Cc: stable@vger.kernel.org > Fixes: 1a73374a04e5 ("media: venus: hfi_parser: add common capability parser") > Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com> > --- > drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c > index 3df241dc3a118bcdeb2c28a6ffdb907b644d5653..27d0172294d5154f4839e8cef172f9a619dfa305 100644 > --- a/drivers/media/platform/qcom/venus/hfi_parser.c > +++ b/drivers/media/platform/qcom/venus/hfi_parser.c > @@ -23,6 +23,8 @@ static void init_codecs(struct venus_core *core) > return; > > for_each_set_bit(bit, &core->dec_codecs, MAX_CODEC_NUM) { > + if (core->codecs_count >= MAX_CODEC_NUM) > + return; > cap = &caps[core->codecs_count++]; > cap->codec = BIT(bit); > cap->domain = VIDC_SESSION_TYPE_DEC; > @@ -30,6 +32,8 @@ static void init_codecs(struct venus_core *core) > } > > for_each_set_bit(bit, &core->enc_codecs, MAX_CODEC_NUM) { > + if (core->codecs_count >= MAX_CODEC_NUM) > + return; > cap = &caps[core->codecs_count++]; > cap->codec = BIT(bit); > cap->domain = VIDC_SESSION_TYPE_ENC; > I don't see how codecs_count could be greater than the control, since you increment by one on each loop but >= is fine too I suppose. Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
On Tue, Nov 05, 2024 at 02:24:54PM +0530, Vikash Garodia wrote: > There is a possibility that init_codecs is invoked multiple times during > manipulated payload from video firmware. In such case, if codecs_count > can get incremented to value more than MAX_CODEC_NUM, there can be OOB > access. Keep a check for max accessible memory before accessing it. No. Please make sure that init_codecs() does a correct thing, so that core->codecs_count isn't incremented that much (or even better that init_codecs() doesn't do anything if it is executed second time). > > Cc: stable@vger.kernel.org > Fixes: 1a73374a04e5 ("media: venus: hfi_parser: add common capability parser") > Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com> > --- > drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c > index 3df241dc3a118bcdeb2c28a6ffdb907b644d5653..27d0172294d5154f4839e8cef172f9a619dfa305 100644 > --- a/drivers/media/platform/qcom/venus/hfi_parser.c > +++ b/drivers/media/platform/qcom/venus/hfi_parser.c > @@ -23,6 +23,8 @@ static void init_codecs(struct venus_core *core) > return; > > for_each_set_bit(bit, &core->dec_codecs, MAX_CODEC_NUM) { > + if (core->codecs_count >= MAX_CODEC_NUM) > + return; > cap = &caps[core->codecs_count++]; > cap->codec = BIT(bit); > cap->domain = VIDC_SESSION_TYPE_DEC; > @@ -30,6 +32,8 @@ static void init_codecs(struct venus_core *core) > } > > for_each_set_bit(bit, &core->enc_codecs, MAX_CODEC_NUM) { > + if (core->codecs_count >= MAX_CODEC_NUM) > + return; > cap = &caps[core->codecs_count++]; > cap->codec = BIT(bit); > cap->domain = VIDC_SESSION_TYPE_ENC; > > -- > 2.34.1 >
On 11/5/2024 4:21 PM, Bryan O'Donoghue wrote: > On 05/11/2024 08:54, Vikash Garodia wrote: >> There is a possibility that init_codecs is invoked multiple times during >> manipulated payload from video firmware. In such case, if codecs_count >> can get incremented to value more than MAX_CODEC_NUM, there can be OOB >> access. Keep a check for max accessible memory before accessing it. >> >> Cc: stable@vger.kernel.org >> Fixes: 1a73374a04e5 ("media: venus: hfi_parser: add common capability parser") >> Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com> >> --- >> drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c >> b/drivers/media/platform/qcom/venus/hfi_parser.c >> index >> 3df241dc3a118bcdeb2c28a6ffdb907b644d5653..27d0172294d5154f4839e8cef172f9a619dfa305 100644 >> --- a/drivers/media/platform/qcom/venus/hfi_parser.c >> +++ b/drivers/media/platform/qcom/venus/hfi_parser.c >> @@ -23,6 +23,8 @@ static void init_codecs(struct venus_core *core) >> return; >> for_each_set_bit(bit, &core->dec_codecs, MAX_CODEC_NUM) { >> + if (core->codecs_count >= MAX_CODEC_NUM) >> + return; >> cap = &caps[core->codecs_count++]; >> cap->codec = BIT(bit); >> cap->domain = VIDC_SESSION_TYPE_DEC; >> @@ -30,6 +32,8 @@ static void init_codecs(struct venus_core *core) >> } >> for_each_set_bit(bit, &core->enc_codecs, MAX_CODEC_NUM) { >> + if (core->codecs_count >= MAX_CODEC_NUM) >> + return; >> cap = &caps[core->codecs_count++]; >> cap->codec = BIT(bit); >> cap->domain = VIDC_SESSION_TYPE_ENC; >> > > I don't see how codecs_count could be greater than the control, since you > increment by one on each loop but >= is fine too I suppose. Assume the payload from malicious firmware is packed like below HFI_PROPERTY_PARAM_CODEC_SUPPORTED HFI_PROPERTY_PARAM_CODEC_SUPPORTED HFI_PROPERTY_PARAM_CODEC_SUPPORTED ..... for 32 or more instances of above type Regards, Vikash > > Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
On 06/11/2024 07:25, Vikash Garodia wrote: >>> cap = &caps[core->codecs_count++]; >>> cap->codec = BIT(bit); >>> cap->domain = VIDC_SESSION_TYPE_ENC; >>> >> I don't see how codecs_count could be greater than the control, since you >> increment by one on each loop but >= is fine too I suppose. > Assume the payload from malicious firmware is packed like below > HFI_PROPERTY_PARAM_CODEC_SUPPORTED > HFI_PROPERTY_PARAM_CODEC_SUPPORTED > HFI_PROPERTY_PARAM_CODEC_SUPPORTED > ..... > for 32 or more instances of above type But you do this cap = &caps[core->codecs_count++]; for each bit. Anyway consider Dmitry's input re only calling this function once instead. --- bod
diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c index 3df241dc3a118bcdeb2c28a6ffdb907b644d5653..27d0172294d5154f4839e8cef172f9a619dfa305 100644 --- a/drivers/media/platform/qcom/venus/hfi_parser.c +++ b/drivers/media/platform/qcom/venus/hfi_parser.c @@ -23,6 +23,8 @@ static void init_codecs(struct venus_core *core) return; for_each_set_bit(bit, &core->dec_codecs, MAX_CODEC_NUM) { + if (core->codecs_count >= MAX_CODEC_NUM) + return; cap = &caps[core->codecs_count++]; cap->codec = BIT(bit); cap->domain = VIDC_SESSION_TYPE_DEC; @@ -30,6 +32,8 @@ static void init_codecs(struct venus_core *core) } for_each_set_bit(bit, &core->enc_codecs, MAX_CODEC_NUM) { + if (core->codecs_count >= MAX_CODEC_NUM) + return; cap = &caps[core->codecs_count++]; cap->codec = BIT(bit); cap->domain = VIDC_SESSION_TYPE_ENC;
There is a possibility that init_codecs is invoked multiple times during manipulated payload from video firmware. In such case, if codecs_count can get incremented to value more than MAX_CODEC_NUM, there can be OOB access. Keep a check for max accessible memory before accessing it. Cc: stable@vger.kernel.org Fixes: 1a73374a04e5 ("media: venus: hfi_parser: add common capability parser") Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com> --- drivers/media/platform/qcom/venus/hfi_parser.c | 4 ++++ 1 file changed, 4 insertions(+)