Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1668058pxb; Thu, 16 Sep 2021 12:29:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyD/nYPQDxKL49PhCe8iN9a9uqn//uAUDToQcVPWmanNNbx2Xndrt1/FwYkmS6wGnQYiWr X-Received: by 2002:a17:906:5950:: with SMTP id g16mr8210468ejr.391.1631820559971; Thu, 16 Sep 2021 12:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631820559; cv=none; d=google.com; s=arc-20160816; b=wIw6H6HkEL/BdElPCXWbX9QpKKnlLRa17XGkmJ0BqArn2ficukJ/DGIcajZBPHsCHU KiOS3knjQaArjbDXvhJcNw63dFOW+imKbps9gLFL3kDOUYnlKKxbdklBxOrjTkTgxAOT 62ykL78V0gS5Cs2khNOCFkU6KlJu/UEq/5N1tdiKBNIlzTrD4pjwyJVYwJYPrsh3eQON Btnn9OKWkDlLh+xIPUOnWMkja9Er5rL/Fg385N+8nHjZ5//4m+s+6tLnurFspKvoxHyB Xd+5th/OHZvaLb9R7XcE79HsVk1QqdS4v9pMHook1PiQOlIv/geCSaHR8dFwPIVCoiqW w1qg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ddy5UbL9GRm7lxImvjl26UbAgoc/x6ztjXJDAYd5WGY=; b=RD+7ow0GSDMAF09B06+a0lcy6inuc+LbT2d10J1hkThgx72cJ1o1bczr9xG6NP6K+O cpB75kBImRbzOKoXY+UconCviT+r4wJY2a1iMy8wOQHk7A6M03Bmy+EUClQIsifCpGtW fmWTpw/8vsZUVuL0ucVc9DLvFpaiiAGfHA5jFl9lBBVWJiC4bOMNUKyCGK6KAi3URy0r ppaiQ7ynOxGXGsygYD8fwPR9bMT5sJSGWNw5I5lAs6RUw7wvpLyHi+vOg/rCFrO7urwT Oy1SFp7Nmo5vYWyCkeXW2cwCyH+kRm7sfghS0P7ylkKc8Yra20SYYSaQB68hZzxI3wO6 thcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EraNnlEv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si4235170edo.451.2021.09.16.12.28.55; Thu, 16 Sep 2021 12:29:19 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EraNnlEv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234171AbhIPQGk (ORCPT + 99 others); Thu, 16 Sep 2021 12:06:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:45040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240664AbhIPQFx (ORCPT ); Thu, 16 Sep 2021 12:05:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CC3AA61250; Thu, 16 Sep 2021 16:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808272; bh=9ys4q/Cq6uxiYo0LVkXwRkBOrR9jLBigOEKO29P6kHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EraNnlEvjWlKGCqj68RVYDaGJtq0kBd6PSRa3eIDjDBgvwjlggs9gDBq88u5uKa9F 6YCcz5cnLxJnMHiZPT82IombYNk+Jb1m70pdw8GgX7L5uPlmsyaMTjttMJG1P7RStP nk27Q6N7A0fgo+i7t/Xh9OqiSj5ALQaC0T9JlghQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Iwona Winiarska , Andrew Jeffery , Joel Stanley , Joel Stanley Subject: [PATCH 5.10 025/306] soc: aspeed: p2a-ctrl: Fix boundary check for mmap Date: Thu, 16 Sep 2021 17:56:10 +0200 Message-Id: <20210916155754.803480552@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Iwona Winiarska commit 8b07e990fb254fcbaa919616ac77f981cb48c73d upstream. The check mixes pages (vm_pgoff) with bytes (vm_start, vm_end) on one side of the comparison, and uses resource address (rather than just the resource size) on the other side of the comparison. This can allow malicious userspace to easily bypass the boundary check and map pages that are located outside memory-region reserved by the driver. Fixes: 01c60dcea9f7 ("drivers/misc: Add Aspeed P2A control driver") Cc: stable@vger.kernel.org Signed-off-by: Iwona Winiarska Reviewed-by: Andrew Jeffery Tested-by: Andrew Jeffery Reviewed-by: Joel Stanley Signed-off-by: Joel Stanley Signed-off-by: Greg Kroah-Hartman --- drivers/soc/aspeed/aspeed-p2a-ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/soc/aspeed/aspeed-p2a-ctrl.c +++ b/drivers/soc/aspeed/aspeed-p2a-ctrl.c @@ -110,7 +110,7 @@ static int aspeed_p2a_mmap(struct file * vsize = vma->vm_end - vma->vm_start; prot = vma->vm_page_prot; - if (vma->vm_pgoff + vsize > ctrl->mem_base + ctrl->mem_size) + if (vma->vm_pgoff + vma_pages(vma) > ctrl->mem_size >> PAGE_SHIFT) return -EINVAL; /* ast2400/2500 AHB accesses are not cache coherent */