linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: David Laight <David.Laight@ACULAB.COM>,
	Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mulu He <muluhe@codeaurora.org>,
	Tingwei Zhang <tingwei@codeaurora.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@st.com>,
	"linux-stm32@st-md-mailman.stormreply.com"
	<linux-stm32@st-md-mailman.stormreply.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@linaro.org>, Leo Yan <leo.yan@linaro.org>
Cc: Rajendra Nayak <rnayak@codeaurora.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Sibi Sankar <sibis@codeaurora.org>,
	Vivek Gautam <vivek.gautam@codeaurora.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] stm class: Fix out of bound access from bitmap allocation
Date: Mon, 8 Apr 2019 11:52:23 +0100	[thread overview]
Message-ID: <f3a699e5-a6c4-83f4-fff3-20515e8caa06@arm.com> (raw)
In-Reply-To: <2d5e435bf7b344fb835fc58ac36e1c19@AcuMS.aculab.com>

On 08/04/2019 11:33, David Laight wrote:
> From: Robin Murphy
>> Sent: 08 April 2019 11:24
>> On 07/04/2019 05:31, Sai Prakash Ranjan wrote:
>>> On 4/5/2019 6:44 PM, David Laight wrote:
>>>> From: Sai Prakash Ranjan
>>>>>
>>>>> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
>>>>> index 93ce3aa740a9..21a5838f6e67 100644
>>>>> --- a/drivers/hwtracing/stm/core.c
>>>>> +++ b/drivers/hwtracing/stm/core.c
>>>>> @@ -168,7 +168,7 @@ static int stp_master_alloc(struct stm_device
>>>>> *stm, unsigned int idx)
>>>>>        struct stp_master *master;
>>>>>        size_t size;
>>>>>
>>>>> -    size = ALIGN(stm->data->sw_nchannels, 8) / 8;
>>>>> +    size = ALIGN(stm->data->sw_nchannels, STM_MASTER_SZ) /
>>>>> STM_MASTER_SZ;
>>>>
>>>> I'm not sure that using STP_MASTER_SZ improves readability at all.
>>>>
>>>
>>> I thought it was better to have a macro than directly specifying
>>> sizeof(unsigned long), anyways I can change it.
>>>
>>>> Is there something that gives the size of a bitmap for 'n' items?
>>>>
>>>
>>> Not sure if there is something.
>>
>> If you were to ask the question "how does the bitmap code itself know
>> what the total size of a bitmap is?", that would quickly lead you
>> towards BITS_TO_LONGS() ;)
>>
>> And given that stp_master::chan_map is already an appropriate type, that
>> suggests simplifying the entire calculation down to something neat and
>> tidy like:
>>
>> size = offsetof(struct stp_master, chan_map[BITS_TO_LONGS(stm->data->sw_nchannels)]);
> 
> Except that is invalid.
> You can't use offsetof() with something that isn't a compile time constant.

Oh, I see the standard does actually say that, although there seem to be 
enough non-constant uses in the kernel to suggest that it still works in 
practice.

However, while writing the above I was still trying to remember the 
other thing I'd seen for handling precisely this variable-sized-struct 
situation, which I've now found again, namely struct_size(). I guess now 
I understand why that isn't implemented in terms of offsetof(), thanks 
for the nudge :)

Robin.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-04-08 10:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 12:22 [PATCH] stm class: Fix out of bound access from bitmap allocation Sai Prakash Ranjan
2019-04-05 13:14 ` David Laight
2019-04-07  4:31   ` Sai Prakash Ranjan
2019-04-08 10:23     ` Robin Murphy
2019-04-08 10:33       ` David Laight
2019-04-08 10:52         ` Robin Murphy [this message]
2019-04-08 11:13           ` David Laight
2019-04-16 15:00 ` Alexander Shishkin
2019-04-17  3:33   ` Sai Prakash Ranjan

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=f3a699e5-a6c4-83f4-fff3-20515e8caa06@arm.com \
    --to=robin.murphy@arm.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.torgue@st.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mike.leach@linaro.org \
    --cc=muluhe@codeaurora.org \
    --cc=rnayak@codeaurora.org \
    --cc=saiprakash.ranjan@codeaurora.org \
    --cc=sibis@codeaurora.org \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tingwei@codeaurora.org \
    --cc=vivek.gautam@codeaurora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).