linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/base: cacheinfo: validate device node for all the caches
@ 2015-02-16 14:10 Sudeep Holla
  2015-02-23 15:14 ` Mark Rutland
  2015-02-23 16:32 ` [PATCH v2] " Sudeep Holla
  0 siblings, 2 replies; 5+ messages in thread
From: Sudeep Holla @ 2015-02-16 14:10 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: Sudeep Holla, Lorenzo Pieralisi, Mark Rutland, Greg Kroah-Hartman

On architectures that depend on DT for obtaining cache hierarcy, we need
to validate the device node for all the cache indices, failing to do so
might result in wrong information being exposed to the userspace.

This is quite possible on initial/incomplete versions of the device
trees. In such cases, it's better to bail out if all the required device
nodes are not present.

This patch adds checks for the validation of device node for all the
caches and doesn't initialise the cacheinfo if there's any error.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/base/cacheinfo.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index 6e64563361f0..7015bf05c828 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu)
 		return -ENOENT;
 	}
 
-	while (np && index < cache_leaves(cpu)) {
+	while (index < cache_leaves(cpu)) {
 		this_leaf = this_cpu_ci->info_list + index;
 		if (this_leaf->level != 1)
 			np = of_find_next_cache_node(np);
 		else
 			np = of_node_get(np);/* cpu node itself */
+		if (!np)
+			break;
 		this_leaf->of_node = np;
 		index++;
 	}
+
+	if (index != cache_leaves(cpu)) /* not all OF nodes populated */
+		return -ENOENT;
+
 	return 0;
 }
 
@@ -189,8 +195,10 @@ static int detect_cache_attributes(unsigned int cpu)
 	 * will be set up here only if they are not populated already
 	 */
 	ret = cache_shared_cpu_map_setup(cpu);
-	if (ret)
+	if (ret) {
+		pr_err("failed to setup cache hierarcy from DT\n");
 		goto free_ci;
+	}
 	return 0;
 
 free_ci:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers/base: cacheinfo: validate device node for all the caches
  2015-02-16 14:10 [PATCH] drivers/base: cacheinfo: validate device node for all the caches Sudeep Holla
@ 2015-02-23 15:14 ` Mark Rutland
  2015-02-23 15:45   ` Sudeep Holla
  2015-02-23 16:32 ` [PATCH v2] " Sudeep Holla
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Rutland @ 2015-02-23 15:14 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: linux-kernel, linux-arm-kernel, Lorenzo Pieralisi, Greg Kroah-Hartman

On Mon, Feb 16, 2015 at 02:10:16PM +0000, Sudeep Holla wrote:
> On architectures that depend on DT for obtaining cache hierarcy, we need
> to validate the device node for all the cache indices, failing to do so
> might result in wrong information being exposed to the userspace.
> 
> This is quite possible on initial/incomplete versions of the device
> trees. In such cases, it's better to bail out if all the required device
> nodes are not present.
> 
> This patch adds checks for the validation of device node for all the
> caches and doesn't initialise the cacheinfo if there's any error.
> 
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reported-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/base/cacheinfo.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
> index 6e64563361f0..7015bf05c828 100644
> --- a/drivers/base/cacheinfo.c
> +++ b/drivers/base/cacheinfo.c
> @@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu)
>  		return -ENOENT;
>  	}
>  
> -	while (np && index < cache_leaves(cpu)) {
> +	while (index < cache_leaves(cpu)) {
>  		this_leaf = this_cpu_ci->info_list + index;
>  		if (this_leaf->level != 1)
>  			np = of_find_next_cache_node(np);
>  		else
>  			np = of_node_get(np);/* cpu node itself */
> +		if (!np)
> +			break;
>  		this_leaf->of_node = np;
>  		index++;
>  	}
> +
> +	if (index != cache_leaves(cpu)) /* not all OF nodes populated */
> +		return -ENOENT;
> +
>  	return 0;
>  }
>  
> @@ -189,8 +195,10 @@ static int detect_cache_attributes(unsigned int cpu)
>  	 * will be set up here only if they are not populated already
>  	 */
>  	ret = cache_shared_cpu_map_setup(cpu);
> -	if (ret)
> +	if (ret) {
> +		pr_err("failed to setup cache hierarcy from DT\n");

It would probably be better if this were something like:

pr_warn("Unable to detect cache hierarcy from DT for CPU %d\n",
	cpu);

Otherwise, this looks sane to me, and it would be nice to have this in
ASAP so as to avoid exposing erroneous information to userspace. So:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

>  		goto free_ci;
> +	}
>  	return 0;
>  
>  free_ci:
> -- 
> 1.9.1
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers/base: cacheinfo: validate device node for all the caches
  2015-02-23 15:14 ` Mark Rutland
@ 2015-02-23 15:45   ` Sudeep Holla
  0 siblings, 0 replies; 5+ messages in thread
From: Sudeep Holla @ 2015-02-23 15:45 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Sudeep Holla, linux-kernel, linux-arm-kernel, Lorenzo Pieralisi,
	Greg Kroah-Hartman



On 23/02/15 15:14, Mark Rutland wrote:
> On Mon, Feb 16, 2015 at 02:10:16PM +0000, Sudeep Holla wrote:
>> On architectures that depend on DT for obtaining cache hierarcy, we need
>> to validate the device node for all the cache indices, failing to do so
>> might result in wrong information being exposed to the userspace.
>>
>> This is quite possible on initial/incomplete versions of the device
>> trees. In such cases, it's better to bail out if all the required device
>> nodes are not present.
>>
>> This patch adds checks for the validation of device node for all the
>> caches and doesn't initialise the cacheinfo if there's any error.
>>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Reported-by: Mark Rutland <mark.rutland@arm.com>
>> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
>> ---
>>   drivers/base/cacheinfo.c | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
>> index 6e64563361f0..7015bf05c828 100644
>> --- a/drivers/base/cacheinfo.c
>> +++ b/drivers/base/cacheinfo.c

[...]

>> @@ -189,8 +195,10 @@ static int detect_cache_attributes(unsigned int cpu)
>>   	 * will be set up here only if they are not populated already
>>   	 */
>>   	ret = cache_shared_cpu_map_setup(cpu);
>> -	if (ret)
>> +	if (ret) {
>> +		pr_err("failed to setup cache hierarcy from DT\n");
>
> It would probably be better if this were something like:
>
> pr_warn("Unable to detect cache hierarcy from DT for CPU %d\n",
> 	cpu);
>

Agreed, will update and send v2.

> Otherwise, this looks sane to me, and it would be nice to have this in
> ASAP so as to avoid exposing erroneous information to userspace. So:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
>

Thanks.

Regards,
Sudeep


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] drivers/base: cacheinfo: validate device node for all the caches
  2015-02-16 14:10 [PATCH] drivers/base: cacheinfo: validate device node for all the caches Sudeep Holla
  2015-02-23 15:14 ` Mark Rutland
@ 2015-02-23 16:32 ` Sudeep Holla
  2015-03-10  9:52   ` Sudeep Holla
  1 sibling, 1 reply; 5+ messages in thread
From: Sudeep Holla @ 2015-02-23 16:32 UTC (permalink / raw)
  To: linux-kernel, Greg Kroah-Hartman
  Cc: Sudeep Holla, linux-arm-kernel, devicetree, Mark Rutland,
	Lorenzo Pieralisi

On architectures that depend on DT for obtaining cache hierarcy, we need
to validate the device node for all the cache indices, failing to do so
might result in wrong information being exposed to the userspace.

This is quite possible on initial/incomplete versions of the device
trees. In such cases, it's better to bail out if all the required device
nodes are not present.

This patch adds checks for the validation of device node for all the
caches and doesn't initialise the cacheinfo if there's any error.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reported-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/base/cacheinfo.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

v1->v2:
 - Updated log information as suggested by Mark
 - Added Mark's ACK

Hi Greg,

Can you please pick this fix for the next rc ?

Without this there's possibility that erroneous information is exposed
to userspace on architecture depending on DT especially if DT lacks
cache hierarcy information.

Regards,
Sudeep

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index 6e64563361f0..9c2ba1c97c42 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -62,15 +62,21 @@ static int cache_setup_of_node(unsigned int cpu)
 		return -ENOENT;
 	}
 
-	while (np && index < cache_leaves(cpu)) {
+	while (index < cache_leaves(cpu)) {
 		this_leaf = this_cpu_ci->info_list + index;
 		if (this_leaf->level != 1)
 			np = of_find_next_cache_node(np);
 		else
 			np = of_node_get(np);/* cpu node itself */
+		if (!np)
+			break;
 		this_leaf->of_node = np;
 		index++;
 	}
+
+	if (index != cache_leaves(cpu)) /* not all OF nodes populated */
+		return -ENOENT;
+
 	return 0;
 }
 
@@ -189,8 +195,11 @@ static int detect_cache_attributes(unsigned int cpu)
 	 * will be set up here only if they are not populated already
 	 */
 	ret = cache_shared_cpu_map_setup(cpu);
-	if (ret)
+	if (ret) {
+		pr_warn("Unable to detect cache hierarcy from DT for CPU %d\n",
+			cpu);
 		goto free_ci;
+	}
 	return 0;
 
 free_ci:
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] drivers/base: cacheinfo: validate device node for all the caches
  2015-02-23 16:32 ` [PATCH v2] " Sudeep Holla
@ 2015-03-10  9:52   ` Sudeep Holla
  0 siblings, 0 replies; 5+ messages in thread
From: Sudeep Holla @ 2015-03-10  9:52 UTC (permalink / raw)
  To: linux-kernel, Greg Kroah-Hartman
  Cc: Sudeep Holla, linux-arm-kernel, devicetree, Mark Rutland,
	Lorenzo Pieralisi

Hi Greg,

On 23/02/15 16:32, Sudeep Holla wrote:
> On architectures that depend on DT for obtaining cache hierarcy, we need
> to validate the device node for all the cache indices, failing to do so
> might result in wrong information being exposed to the userspace.
>
> This is quite possible on initial/incomplete versions of the device
> trees. In such cases, it's better to bail out if all the required device
> nodes are not present.
>
> This patch adds checks for the validation of device node for all the
> caches and doesn't initialise the cacheinfo if there's any error.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reported-by: Mark Rutland <mark.rutland@arm.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>   drivers/base/cacheinfo.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
>
> v1->v2:
>   - Updated log information as suggested by Mark
>   - Added Mark's ACK
>
> Hi Greg,
>
> Can you please pick this fix for the next rc ?
>
> Without this there's possibility that erroneous information is exposed
> to userspace on architecture depending on DT especially if DT lacks
> cache hierarchy information.
>

There are many arm64 DT without cache hierarchy which exposes wrong
cacheinfo to the user space. It would be good to get this included
as bug fix for 4.0

Regards,
Sudeep


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-10  9:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-16 14:10 [PATCH] drivers/base: cacheinfo: validate device node for all the caches Sudeep Holla
2015-02-23 15:14 ` Mark Rutland
2015-02-23 15:45   ` Sudeep Holla
2015-02-23 16:32 ` [PATCH v2] " Sudeep Holla
2015-03-10  9:52   ` Sudeep Holla

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).