Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1899277pxb; Thu, 16 Sep 2021 19:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGMjPV5F7K+9r8su4vKLGfvwdGGfFHyxtaxXPQnXTvRo6sxKpLNMsCiVouipdFd8xR3KTO X-Received: by 2002:a6b:ba42:: with SMTP id k63mr6639509iof.37.1631845966085; Thu, 16 Sep 2021 19:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631845966; cv=none; d=google.com; s=arc-20160816; b=yi9szVvtqOd/7FmFY05eEe9s1xst1W3fLtSVEgKP0qZGrBJd8KzWTb9rcSaRCG8auk NhM5++fIqI+8EDERm9Ba/gMHSXrC7ZkxoMdwzXul/u92XNjenI+m9mRGZDOjGhXfJvnG gCW+KJwgYVBiCANhlG6smDidXZB55ieSFtnGu6bp6tR9kgahtmot6WW4uS2mvAhDp18l MWeZpBTATjJZdTHuShiUCGzRJqZzLD3TOp9dN5SuECWjt2T+Ff4PNV/p1pNIRicCTXCw k4ULHzwcgcZtSlxF6y6AV9UcjSpmVWx+nXnedRI5WhmzM6p2Mnyj4IFv0U3xBJS5V2u4 YENw== 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=t2Ey+agezt2X68UcZ6FTJ8wikMZQHWJSfTP/2SoRALo=; b=c8fvLassfGHSpNqn9FJYpuQPWKje5ziJXHxmfKKdGxQvng+CUFQuE9s+ca+DmVS4sB 0e9mvX/8YzEbRvoc/5JoeM6+/wjYwyJuLKjDlsv0VBsnMbMZiNOJ9SWmQKqUdCfXG38g imEvXfspS8IYOKQnNPXTCDgQ7hXgwBvH5O/+8+cUdTToQYa84otuXRw/j6a48FHQbsdK 5RjvH8U1XVqL6SsivciTtO7St5ciM06fQrtYtmYIOr0mLdB3pKEmsDbKbu1sGQN1rfXW n3CSFOiXNn7tONNGTvJd+qA8eovXP/GRJPGSM/QfnEmuWGJMLCb55AkdB3ICZaJRhLxH PrDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jVU0PMU9; 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 b3si3791132iot.102.2021.09.16.19.32.34; Thu, 16 Sep 2021 19:32:46 -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=jVU0PMU9; 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 S1345295AbhIPRNZ (ORCPT + 99 others); Thu, 16 Sep 2021 13:13:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:36118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349528AbhIPRF7 (ORCPT ); Thu, 16 Sep 2021 13:05:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D617161B2F; Thu, 16 Sep 2021 16:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631810148; bh=d6LoCSuTnfwIgOGiuZ/lv40mgJX33fKMA5AkF0j1eIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jVU0PMU9i1soyRMP5oAKpvASM8Ao3UBmVxnPFc6O/eAJK8O6MSSVJ2gnBxx9xaI6d GBS4cCViszmXMbG/PDdbJkD5oFRstH5aTrTBF6ojbsDEgsjnpEo8BrC8TpYkm/F25k pIGpMDyEpJ6pTORPubY03f22i5qbWSZr2siJslWA= 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.14 035/432] soc: aspeed: lpc-ctrl: Fix boundary check for mmap Date: Thu, 16 Sep 2021 17:56:24 +0200 Message-Id: <20210916155812.007168786@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155810.813340753@linuxfoundation.org> References: <20210916155810.813340753@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/soc/aspeed/aspeed-lpc-ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/soc/aspeed/aspeed-lpc-ctrl.c +++ b/drivers/soc/aspeed/aspeed-lpc-ctrl.c @@ -51,7 +51,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 */