mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	driver core: platform: Prevent resouce overflow from causing infinite loops
num_resources in the platform_device struct is declared as a u32. The for loops that iterate over num_resources use an int as the counter, which can cause infinite loops on architectures with smaller ints. Change the loop counters to u32. Signed-off-by: Simon Schwartz <kern.simon@theschwartz.xyz> Link: https://lore.kernel.org/r/2201ce63a2a171ffd2ed14e867875316efcf71db.camel@theschwartz.xyz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									5bf33f04eb
								
							
						
					
					
						commit
						39cc539f90
					
				
					 1 changed files with 6 additions and 4 deletions
				
			
		| 
						 | 
					@ -27,6 +27,7 @@
 | 
				
			||||||
#include <linux/limits.h>
 | 
					#include <linux/limits.h>
 | 
				
			||||||
#include <linux/property.h>
 | 
					#include <linux/property.h>
 | 
				
			||||||
#include <linux/kmemleak.h>
 | 
					#include <linux/kmemleak.h>
 | 
				
			||||||
 | 
					#include <linux/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "base.h"
 | 
					#include "base.h"
 | 
				
			||||||
#include "power/power.h"
 | 
					#include "power/power.h"
 | 
				
			||||||
| 
						 | 
					@ -48,7 +49,7 @@ EXPORT_SYMBOL_GPL(platform_bus);
 | 
				
			||||||
struct resource *platform_get_resource(struct platform_device *dev,
 | 
					struct resource *platform_get_resource(struct platform_device *dev,
 | 
				
			||||||
				       unsigned int type, unsigned int num)
 | 
									       unsigned int type, unsigned int num)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						u32 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < dev->num_resources; i++) {
 | 
						for (i = 0; i < dev->num_resources; i++) {
 | 
				
			||||||
		struct resource *r = &dev->resource[i];
 | 
							struct resource *r = &dev->resource[i];
 | 
				
			||||||
| 
						 | 
					@ -255,7 +256,7 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
 | 
				
			||||||
					      unsigned int type,
 | 
										      unsigned int type,
 | 
				
			||||||
					      const char *name)
 | 
										      const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						u32 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < dev->num_resources; i++) {
 | 
						for (i = 0; i < dev->num_resources; i++) {
 | 
				
			||||||
		struct resource *r = &dev->resource[i];
 | 
							struct resource *r = &dev->resource[i];
 | 
				
			||||||
| 
						 | 
					@ -501,7 +502,8 @@ EXPORT_SYMBOL_GPL(platform_device_add_properties);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int platform_device_add(struct platform_device *pdev)
 | 
					int platform_device_add(struct platform_device *pdev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i, ret;
 | 
						u32 i;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!pdev)
 | 
						if (!pdev)
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
| 
						 | 
					@ -590,7 +592,7 @@ EXPORT_SYMBOL_GPL(platform_device_add);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void platform_device_del(struct platform_device *pdev)
 | 
					void platform_device_del(struct platform_device *pdev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						u32 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!IS_ERR_OR_NULL(pdev)) {
 | 
						if (!IS_ERR_OR_NULL(pdev)) {
 | 
				
			||||||
		device_del(&pdev->dev);
 | 
							device_del(&pdev->dev);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue