Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1622441ybv; Fri, 21 Feb 2020 00:28:22 -0800 (PST) X-Google-Smtp-Source: APXvYqze1fjUA9FJXD9nBk/h/RUQEYLWZsk9PSLy1KX/TeKGRFKqlqtNDFl3QGFh7f0qLZcJNzkf X-Received: by 2002:aca:4309:: with SMTP id q9mr1062190oia.158.1582273702326; Fri, 21 Feb 2020 00:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273702; cv=none; d=google.com; s=arc-20160816; b=cwDWs59eZPkEhsBmmuuK2YRIvlEdir3qXShcpTSxh6FLrgZeBrMvL2InOAX7o0HbYq Qna1uEMUski26Az4QZ1dD2rsAhIikKcfBR3CyulFQUTGc6n3WroggftPmfgUXTftVBtx ecz1RQp0kF5lBBCjQb2Xngt0mT6TH72CY0z91EB3Up9zESDGB6PabKh1S6kxzcXrsa36 sNywv2vYCBMP1b/3mc+KAAfLfiX+0Eo9ij1VtpDAAsujMzE7563YghZUZr91xSBtwyPA yu+ZtVg0DMen0xgGiw615oVQUZO5SftPSW2qepQ4uVlxHwRsf0hZRN8txH40RPvMM0kV i8qw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k+ZOzEKRXsg3Gcm9QM19x2+ysKENq6HeZLFDBlYBzrM=; b=mHBUzMmJJJsCHFMpkOpFILPLXz9MCemuQ/WeXdlkqj1Y9aPQvYX6LVm8tgPdk1voXP 2VmKIjErZ6MHJUDZAJzTx1O/eEhnOnB5ntU5vqxqI/ZyL8JK2DGHQWejPE/z4toi9eV1 BNbMSgAx1367loTB3ioYhBhVKa157NuXoazJcxeTNjoXXWHNRSSQuRIaXzagJj/OI2sf KE12NKajQs0Up2CjrE+XsusxoY0AE5HSz/WOUgVd5AeoCtkI3pBL7S3kODDPFyTvwWLv vWIFzj6ix//yAUsm0x1i01wmuLoIoimbANIGFd+gNviwGf0rtkgEREFCAJhlf11K4LcD zweg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o4f7Ckuo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si1212214otv.190.2020.02.21.00.28.10; Fri, 21 Feb 2020 00:28:22 -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=o4f7Ckuo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730756AbgBUIVu (ORCPT + 99 others); Fri, 21 Feb 2020 03:21:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:33092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731228AbgBUIVn (ORCPT ); Fri, 21 Feb 2020 03:21:43 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D894220578; Fri, 21 Feb 2020 08:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273303; bh=RJwtUpJBdRYkUiccppQNybQRCLhpCuqZmZrx0SpYbAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o4f7CkuoVN219vTuDYKf7Mfgjmog7ltgTgVm+2wpDOlE6aQADHU7zY7C2+tuMx4lp kUGs8h/IzpR36x+TBJj7rcRZpcsRdl0eCf6fD/DtMrCgAAfuG3rfrVtzLeR7CtNwZU jarn+3KZJSdIEQ49SNu8EZf1kbRZDwvDSYUgzki4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Simon Schwartz , Sasha Levin Subject: [PATCH 4.19 119/191] driver core: platform: Prevent resouce overflow from causing infinite loops Date: Fri, 21 Feb 2020 08:41:32 +0100 Message-Id: <20200221072305.177045015@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 e9be1f56929af..1d3a50ac21664 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -67,7 +68,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]; @@ -162,7 +163,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]; @@ -359,7 +360,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; @@ -446,7 +448,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