All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <keescook@chromium.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Stanimir Varbanov <stanimir.varbanov@linaro.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][venus-for-next-v5.14] media: venus: hfi_cmds: Fix packet size calculation
Date: Wed, 2 Jun 2021 15:34:06 -0500	[thread overview]
Message-ID: <e40f4067-82e2-31ff-0694-375a59f949de@embeddedor.com> (raw)
In-Reply-To: <202106021254.39A1561075@keescook>



On 6/2/21 14:55, Kees Cook wrote:
> On Tue, Jun 01, 2021 at 01:46:16PM -0500, Gustavo A. R. Silva wrote:
>> Now that a one-element array was replaced with a flexible-array member
>> in struct hfi_sys_set_property_pkt, use the struct_size() helper to
>> correctly calculate the packet size.
>>
>> Fixes: 701e10b3fd9f ("media: venus: hfi_cmds.h: Replace one-element array with flexible-array member")
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>> ---
>> BTW... it seems that a similar problem is present in
>> https://lore.kernel.org/linux-hardening/20210211001044.GA69612@embeddedor/ 
>> and that is what is causing the regression. I will send v2 of that
>> patch, shortly. Thanks.
>>
>>  drivers/media/platform/qcom/venus/hfi_cmds.c | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c
>> index 11a8347e5f5c..c86279e5d6e8 100644
>> --- a/drivers/media/platform/qcom/venus/hfi_cmds.c
>> +++ b/drivers/media/platform/qcom/venus/hfi_cmds.c
>> @@ -27,7 +27,7 @@ void pkt_sys_idle_indicator(struct hfi_sys_set_property_pkt *pkt, u32 enable)
>>  {
>>  	struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1];
>>  
>> -	pkt->hdr.size = sizeof(*pkt) + sizeof(*hfi) + sizeof(u32);
>> +	pkt->hdr.size = struct_size(pkt, data, 2) + sizeof(*hfi);
> 
> I think this should be "1" not "2".
> 
> (i.e. there is a single "data" item, followed by an entire *hfi (which
> starts immediate after data[0]).

Yeah; I see your point. Here I just wanted to preserve the exact same size
as the original code, which turns out has a "benign" off-by-one issue.

I'll fix it up and respin.

Thanks!
--
Gustavo

> 
>>  	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
>>  	pkt->num_properties = 1;
>>  	pkt->data[0] = HFI_PROPERTY_SYS_IDLE_INDICATOR;
>> @@ -39,7 +39,7 @@ void pkt_sys_debug_config(struct hfi_sys_set_property_pkt *pkt, u32 mode,
>>  {
>>  	struct hfi_debug_config *hfi;
>>  
>> -	pkt->hdr.size = sizeof(*pkt) + sizeof(*hfi) + sizeof(u32);
>> +	pkt->hdr.size = struct_size(pkt, data, 2) + sizeof(*hfi);
> 
> Same here.
> 
>>  	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
>>  	pkt->num_properties = 1;
>>  	pkt->data[0] = HFI_PROPERTY_SYS_DEBUG_CONFIG;
>> @@ -50,7 +50,7 @@ void pkt_sys_debug_config(struct hfi_sys_set_property_pkt *pkt, u32 mode,
>>  
>>  void pkt_sys_coverage_config(struct hfi_sys_set_property_pkt *pkt, u32 mode)
>>  {
>> -	pkt->hdr.size = sizeof(*pkt) + sizeof(u32);
>> +	pkt->hdr.size = struct_size(pkt, data, 2);
> 
> This looks correct.
> 
>>  	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
>>  	pkt->num_properties = 1;
>>  	pkt->data[0] = HFI_PROPERTY_SYS_CONFIG_COVERAGE;
>> @@ -116,7 +116,7 @@ void pkt_sys_power_control(struct hfi_sys_set_property_pkt *pkt, u32 enable)
>>  {
>>  	struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1];
>>  
>> -	pkt->hdr.size = sizeof(*pkt) + sizeof(*hfi) + sizeof(u32);
>> +	pkt->hdr.size = struct_size(pkt, data, 2) + sizeof(*hfi);
> 
> Also 1.
> 
>>  	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
>>  	pkt->num_properties = 1;
>>  	pkt->data[0] = HFI_PROPERTY_SYS_CODEC_POWER_PLANE_CTRL;
>> -- 
>> 2.27.0
>>
> 

  reply	other threads:[~2021-06-02 20:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 18:46 [PATCH][venus-for-next-v5.14] media: venus: hfi_cmds: Fix packet size calculation Gustavo A. R. Silva
2021-06-02 19:55 ` Kees Cook
2021-06-02 20:34   ` Gustavo A. R. Silva [this message]
2021-06-02 22:02     ` Gustavo A. R. Silva

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=e40f4067-82e2-31ff-0694-375a59f949de@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=stanimir.varbanov@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.