Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565241lkm; Mon, 20 Sep 2021 18:51:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVlky6wcqzi2CyUlsd2cJ1IREPDNODN77IiLgRfn0ofwdL4VJ0q9xPA0PQbiwbWJ0F8HzK X-Received: by 2002:a02:1081:: with SMTP id 123mr21202745jay.83.1632189006040; Mon, 20 Sep 2021 18:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189006; cv=none; d=google.com; s=arc-20160816; b=TWnFV392HZOWX7sXvk+LX1w4+p3lGjNvg9bCweWAD/42ZDngzs7DdC7lzvGcxwnCds 0zVzhqFsAMG3Z+O6EBsSeMtBvyv1gwMVYhHOH6hkqFSuaJbsJe1W516qb84WorV941G3 t/QUFC10y6e+42mn8U9VfxPH1ZXLjfSy9zgnpDo/m4IPhPC52Xb6e5/3PVlQATHWDtj1 P4VQs6jwjtdGDfMdFZk+lG6loe50xWbr4hTxCMcu+PVv0cd5C9rLmIPVQluhiaTOXrZ4 cpgGkuMd+LUp8krASHjGCD9mDEB/a79vn4g/U9NFBnnxkvoU1wCZxmKLLwLmd6nNKV7p gqXQ== 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=yaxaeCtsi9HfFtE6i1gDRWODuXvDWzZoy5VldXJCjbQ=; b=RscDJbqiur5TdXeIqSD84OVFvwmSy1BpD3kNuH8LwIVMkC2/jBoa/BMm44On+DOFrB a3jT+L9BN2LUk7WiWChm6tym/pFcdD1bGpDeH9LnpxlMWgbjSd9ogThjdVYyQZ7jSbUI 6EyfMkJQBrB/Y/csFjOs1okSEdeIrgxSUHzM/BvMhA0hOqn8Mi+dGizib3fICquWJt9H gB0uLK4wmejXtJRhXnrQzg3tdQs6qMjiCb7Fy3X9Y3Psp201IWmmDY9GquHJ3T+aan5v 0IXSCGcQoHj6RlBHvo9EPdcTiSfo6EU+mREVh8OshlZzrjeTD36qiKBO87QuO/DMjccG 3g4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ads+7+DG; 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 n22si14513065ioo.36.2021.09.20.18.49.54; Mon, 20 Sep 2021 18:50:06 -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=ads+7+DG; 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 S1349653AbhITRtB (ORCPT + 99 others); Mon, 20 Sep 2021 13:49:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:52812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348345AbhITRqx (ORCPT ); Mon, 20 Sep 2021 13:46:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A92961B7C; Mon, 20 Sep 2021 17:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157837; bh=mNINtN00EoE5fNjTY0n3xsXJqBYhlUF+h6yxqaYywuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ads+7+DGwAGq5b04hFQA2hVF+n+ov2sDRmU8hzwuI/C7V6wt3zKwH/9/4gSJr+Jg+ jKjTy1CGvsL2JyIT36h2WqlyHgYIwthxjYuZa8io2UGHRDfwfE8uOmxheLppDs5cLk iP2OCfcjStc75wfz+mr9S2FK4BUf9LH5QXFQxP0M= 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 4.19 141/293] soc: aspeed: lpc-ctrl: Fix boundary check for mmap Date: Mon, 20 Sep 2021 18:41:43 +0200 Message-Id: <20210920163938.108245817@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 b49a0e69a7b1a68c8d3f64097d06dabb770fec96 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: 6c4e97678501 ("drivers/misc: Add Aspeed LPC 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/misc/aspeed-lpc-ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/misc/aspeed-lpc-ctrl.c +++ b/drivers/misc/aspeed-lpc-ctrl.c @@ -50,7 +50,7 @@ static int aspeed_lpc_ctrl_mmap(struct f unsigned long vsize = vma->vm_end - vma->vm_start; pgprot_t prot = vma->vm_page_prot; - if (vma->vm_pgoff + vsize > lpc_ctrl->mem_base + lpc_ctrl->mem_size) + if (vma->vm_pgoff + vma_pages(vma) > lpc_ctrl->mem_size >> PAGE_SHIFT) return -EINVAL; /* ast2400/2500 AHB accesses are not cache coherent */