Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1945415ybv; Fri, 14 Feb 2020 08:39:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwfYC8kJbsf28pC5b/3otGJMwvJX9/0FZwYkW98OnZKdUZbiNrS95Ix4ZPRUsvlDNTnbXIT X-Received: by 2002:aca:50cd:: with SMTP id e196mr2466206oib.178.1581698383655; Fri, 14 Feb 2020 08:39:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698383; cv=none; d=google.com; s=arc-20160816; b=sLVaPpec+KXZG/+f0Md+0AkLbD/vJjroQE2KIy3bhhHxVIDC0f3SXwOQMUekjvDKfX tIIvMUYP5GscLC0qJ7t/vAxxFar8RVrXQVE/mrOetggUiJD706IojByJLjF+NcxQdyLj wIiD93ufc6k2wI81Wquljpa4U5wecbmJu/nvenJ+ml3FK9KBUZf7tEgoPzxiKiH+wilL oQ0VqrlF2bGL5Aloec0uZYH3yyhdDactDCFL14HsTk1p9hpGfQf55SVMK18rp7BW3Fb3 2+TgiqW/MP15J4nMLQ+I4oB5JPyLcztIBUCmW0fCnTrOwN/MS7bxrCbTNkFaNcwdtffd ooiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PTFgtqwcygOX4w2Kwvi9pgQi79eSuL/uPWWg3OlGxko=; b=mWBywG2uhi1f0pC6EB+Wuxl5DUK0Vlun+smjzfMEDgDlrw/wHcz2ksrTEejOldDQGF cMcS/4Z8Sa6fJpQRz0gelhSpyHYq5F8aF8JwnzZjxsItaAb+SeWdumM9iV+J7rsSmQsf 9wlT3PggyEMSSNb5m20eR4NmBgaZyeXxeGWkmymE5FTPhQYuruY1rPRa2Fgetbg3fmyp Iqa3VIV6fw3AsPUlF79OPYdx+Um3vl6PRV8vi6BbeHgl5IVh2ar0HdtYzgzd/ZOm+wPH 45YZJsW7JSGT2x8NVHtcYoW6dVb81sLm1u7IlG5e9xMz4y9yVtGI3FXHhPvg3sG9FOup k5TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d58xFUMs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11si3326866ota.300.2020.02.14.08.39.31; Fri, 14 Feb 2020 08:39:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d58xFUMs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391318AbgBNQi5 (ORCPT + 99 others); Fri, 14 Feb 2020 11:38:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:59576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405600AbgBNQXV (ORCPT ); Fri, 14 Feb 2020 11:23:21 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A0AB24779; Fri, 14 Feb 2020 16:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697400; bh=8T3vqaaSmx9hj90CiV7mq+7OZq8LbOFVfXwRqZ8ERpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d58xFUMs0ECP08h4p8RVP/Z0m+g6sTCUtEiH0ntzykFbywkLpMCDu5I7bsIfdXDC/ 1w+Su2pLRFKL1zJWobjcwZol2auR3MfL16NLLPtBZws+aE4d8l8Twj8flBkdG9BzkC cLVy6P7TiwtFRw9If60BwOMASiuK0OoBVcaMHPts= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Simon Schwartz , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.9 094/141] driver core: platform: Prevent resouce overflow from causing infinite loops Date: Fri, 14 Feb 2020 11:20:34 -0500 Message-Id: <20200214162122.19794-94-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Simon Schwartz [ Upstream commit 39cc539f90d035a293240c9443af50be55ee81b8 ] 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 Link: https://lore.kernel.org/r/2201ce63a2a171ffd2ed14e867875316efcf71db.camel@theschwartz.xyz Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/base/platform.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index f90b1b9bbad0d..6cdc198965f5a 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -68,7 +69,7 @@ void __weak arch_setup_pdev_archdata(struct platform_device *pdev) struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num) { - int i; + u32 i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; @@ -153,7 +154,7 @@ struct resource *platform_get_resource_byname(struct platform_device *dev, unsigned int type, const char *name) { - int i; + u32 i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; @@ -350,7 +351,8 @@ EXPORT_SYMBOL_GPL(platform_device_add_properties); */ int platform_device_add(struct platform_device *pdev) { - int i, ret; + u32 i; + int ret; if (!pdev) return -EINVAL; @@ -437,7 +439,7 @@ EXPORT_SYMBOL_GPL(platform_device_add); */ void platform_device_del(struct platform_device *pdev) { - int i; + u32 i; if (pdev) { device_remove_properties(&pdev->dev); -- 2.20.1