Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp257810pxj; Thu, 10 Jun 2021 21:25:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6VgGISQDFainGlvx1gzlRfuUDvNw0p1dlwGpZTqjcZJpMV0hzIyi5YtBR7LxwD84Ad/uc X-Received: by 2002:a17:906:b34e:: with SMTP id cd14mr1725596ejb.69.1623385530450; Thu, 10 Jun 2021 21:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623385530; cv=none; d=google.com; s=arc-20160816; b=dfqHlCm9mQpPK0JBNDQ93r8RlBSaP90MD1nqAGpV0tiC5dTudsGgyP7+If/dytz3QH iwAgx68akdAU02vhtyDYl8GbQ3FGAuMu/QkPJaWeb0BaboyAUNfso7IiXA3oJNA/hSk9 U+2KTWcZ5s+7wDRnuysGazlHI9x/0lH1EU7KwRwUdiPYHntpz+vWD5sbsNg7MMKfLv58 55qkDLJcJNrLVXSPry+Des8qqYXV7+lypy+H0Caen1+nSPWqTTolwcQc4vvvHDKlXIGo A6zIK9hPD4VyW97v7+gS2MQQCetFSM1itUS8EII9xkBnAABf2A54sFDmhg73EdiewQYD G9Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=u8CAIEOVayhZTrnjGiDuxt/GCJebmOaHutXzQ2Vkmx4=; b=ZQPukTll9QJnyQ8Z+Yy8sjOHR/dLH2BMRnZieheWtGOlPw1jQX5kx4jIjk/FFWkZBD S/A2OK/NRuPQQTGRapAHc6yBvXUMHJrPjyggmnwTwAO4OYH5lOt/GmJL1MakgPgm/Szu PIep73tOF6g2P/cceap7fuc43YGLpsR/x5oHTDwtEuW+49HJ12BTtY//maBxSQL9gtgR xRkXiVrGRJ+JQJn60nEVbxkPAaDzREcgvwxhIKzsP2rPFitTZ9A6ExUONQL6duLrYkaq avdySno/S8gdXuRtuL+ZWpwExGpr8Kn+q36aJEuA8/IVVNZEI+FzqHqDw0vcKEtlo/2s FMsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si4343984ejm.271.2021.06.10.21.25.06; Thu, 10 Jun 2021 21:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbhFKEY4 (ORCPT + 99 others); Fri, 11 Jun 2021 00:24:56 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:56426 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230353AbhFKEY4 (ORCPT ); Fri, 11 Jun 2021 00:24:56 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R851e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=yaohuiwang@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Uc0K0DG_1623385376; Received: from localhost(mailfrom:yaohuiwang@linux.alibaba.com fp:SMTPD_---0Uc0K0DG_1623385376) by smtp.aliyun-inc.com(127.0.0.1); Fri, 11 Jun 2021 12:22:57 +0800 From: Yaohui Wang To: dave.hansen@linux.intel.com Cc: luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, linux-kernel@vger.kernel.org, Ben Luo , Yahui Wang Subject: [PATCH v2 2/2] mm: fix boundary judgment issues in kernel/resource.c Date: Fri, 11 Jun 2021 12:21:47 +0800 Message-Id: <20210611042147.80744-3-yaohuiwang@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210611042147.80744-1-yaohuiwang@linux.alibaba.com> References: <20210611042147.80744-1-yaohuiwang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The original boundary judgment may ignore @end if @end equals @start. For example, if we call ioremap(phys, 1), then @end == @start, and the memory check will not be applied on the page where @end lives, which is unexpected. In kernel/resource.c:find_next_iomem_res, the mem region is a closed interval (i.e. [@start..@end]). So @start == @end should be allowed. In kernel/resource.c:__walk_iomem_res_desc, the mem region is a closed interval (i.e. [@start..@end]). So @start == @end should be allowed. Signed-off-by: Ben Luo Signed-off-by: Yahui Wang --- kernel/resource.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 16e0c7e8e..b29c8c720 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -353,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, if (!res) return -EINVAL; - if (start >= end) + if (start > end) return -EINVAL; read_lock(&resource_lock); @@ -408,7 +408,7 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end, struct resource res; int ret = -EINVAL; - while (start < end && + while (start <= end && !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) { ret = (*func)(&res, arg); if (ret) -- 2.25.1