Received: by 10.192.165.148 with SMTP id m20csp2541525imm; Sun, 22 Apr 2018 09:11:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Pq7qcYQvCs4my/EX3g1z0ZDDfE5LsNECAwpzqQayI9i5IT7TlI/sTc2KFgbQgtHKoXNH9 X-Received: by 10.99.111.130 with SMTP id k124mr14144750pgc.301.1524413460649; Sun, 22 Apr 2018 09:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413460; cv=none; d=google.com; s=arc-20160816; b=RUWFk9kykSBrBPSVYOSnFPDeDQZwYkH7IKHlbVLsdSh5VmbTWZZunkO4UgsNsUm9m0 VknsXsmQS+5IFPs7aM+4L9L9lAuJRLzjBczwr9MV+E/rvX+DPFirAd85lYJPGraPVllQ hiOJkES83tFrlQXunwn1PIay6pA0zp0fLt5TMtFuDJcAy4VhX3CwOW0kAw3VPmwIgDK6 gHsdxfY7D9ieJZC2q/lJc6k+q6LJ8LRBVhykn968zy2WDmRgWS0yFuOjKGmBgLmWiJgx L7iKALLD6De8U2da6AcRo9uyWZiqiurse4Jh+Ybw95pu18Q7tybX6wYsBgWWv7FsfasF heIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hR+YIDytll4nG0ek4xHRwy3gU2coG6VYA4UcEhF/i4w=; b=ZM2NpUhwWXHyAAhaVTIVL87jVo4zU8xgmIVL1erxJu1i9FUqRXVL37eWkgxhA/ira9 DCL5IArITDAfMagJFaBAHGyZT3imogG9q8PuBoWmib99IiAu1degMuofMS5S91ItDgVw 8KGr+guSDOPyMrMEEp+TUxKjMRI3be4MX9YVDGW+ztc2ptuTuilygV4j3X9lgYDYehp7 0j8VAArfp9Po9hTQ0dyjTcLoTCe7JxzxVMZw2vjXk0aIXM5JvF4XSlWdaey/Ij6wAUFb wT2O/dG43dr28yWOxg/teIgaKCJBw3wzJPr6sJqtjMznH6d4y/tpxdHulUPzNqDVyCeS lLhw== ARC-Authentication-Results: i=1; mx.google.com; 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 u3-v6si10161319plb.593.2018.04.22.09.10.46; Sun, 22 Apr 2018 09:11:00 -0700 (PDT) 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; 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 S1753918AbeDVQJq (ORCPT + 99 others); Sun, 22 Apr 2018 12:09:46 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45186 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753769AbeDVN43 (ORCPT ); Sun, 22 Apr 2018 09:56:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A7B03CC4; Sun, 22 Apr 2018 13:56:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Michael Henders , Andrew Morton , Ram Pai , Bjorn Helgaas , Linus Torvalds Subject: [PATCH 4.16 014/196] resource: fix integer overflow at reallocation Date: Sun, 22 Apr 2018 15:50:34 +0200 Message-Id: <20180422135104.884692485@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 60bb83b81169820c691fbfa33a6a4aef32aa4b0b upstream. We've got a bug report indicating a kernel panic at booting on an x86-32 system, and it turned out to be the invalid PCI resource assigned after reallocation. __find_resource() first aligns the resource start address and resets the end address with start+size-1 accordingly, then checks whether it's contained. Here the end address may overflow the integer, although resource_contains() still returns true because the function validates only start and end address. So this ends up with returning an invalid resource (start > end). There was already an attempt to cover such a problem in the commit 47ea91b4052d ("Resource: fix wrong resource window calculation"), but this case is an overseen one. This patch adds the validity check of the newly calculated resource for avoiding the integer overflow problem. Bugzilla: http://bugzilla.opensuse.org/show_bug.cgi?id=1086739 Link: http://lkml.kernel.org/r/s5hpo37d5l8.wl-tiwai@suse.de Fixes: 23c570a67448 ("resource: ability to resize an allocated resource") Signed-off-by: Takashi Iwai Reported-by: Michael Henders Tested-by: Michael Henders Reviewed-by: Andrew Morton Cc: Ram Pai Cc: Bjorn Helgaas Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/resource.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/kernel/resource.c +++ b/kernel/resource.c @@ -651,7 +651,8 @@ static int __find_resource(struct resour alloc.start = constraint->alignf(constraint->alignf_data, &avail, size, constraint->align); alloc.end = alloc.start + size - 1; - if (resource_contains(&avail, &alloc)) { + if (alloc.start <= alloc.end && + resource_contains(&avail, &alloc)) { new->start = alloc.start; new->end = alloc.end; return 0;