Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566060lkm; Mon, 20 Sep 2021 18:52:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKDOYZZFBcrzOW1YzJD3Zr2RuvQnDhEyfJ/GJ2LY3Hi97hdTLdA1lDzyaEYAe6YFXgwpky X-Received: by 2002:a5e:870f:: with SMTP id y15mr6218925ioj.80.1632189047147; Mon, 20 Sep 2021 18:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189047; cv=none; d=google.com; s=arc-20160816; b=d/ZK/rptEKdBuEFZJuuftLyBX8D9pc17FZrjsjxisxEhsIhcLO6CHEvQ/umrc6AGSf CuAe8HYgz/4MGrdldo5T6pGFqJ6FLVKksqoH1bdu+8jierYWbambyyRxEH+iP/uwfXCs UPyXLwQD0KIrjouhlyQ8NdWsj4wwzYpqmKxeHtvFpvVsZC0+7qwSMT37wqYMK1pc0xTl RKdhEuS3OZCMFFGfs9EiZrC98AICpr7grhhQfndfcs5zi+o5cLRli6EjibzT+3TE2oMn cY132GcnxorzHbW4Ce0YIwib6V1NTwvaDH9Chcqx3ABH3UPfjIWk8OrFsN7s9UjZA1xy tgMA== 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=ltfSJ838UV9iSKpT9HM3gzgsnKM6TpUpNQhEJtA7LhDJy4HM3kBXs/rFtRYdQ6dxVU D2/cs3vmhd1ihMg7n2oI9XN+KoWXuBQviXTLyZcFyVNNykNZEkrqr2RFsEAS8//ifv5A IOC67aCVwE7x995MagXLmjC0LRM4taigJu4BiglsQ6OThK2cJJoYheeMfM5rzCqR6v7F 2XoJK4ElOUmqzLokSgYQ/E67JwtdPAWxIvQjl+ksEzUUZQIY+2uVQRojKtZKo0RxLEzo d2QAGC9c9dvdLpQqs+SaOXh+K8QcUMgsDxq6yB5NS/JhQ5xbJNzEZtFoJDfH6IvveTO7 EAfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bh4kVh5V; 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 k9si15049870jap.120.2021.09.20.18.50.36; Mon, 20 Sep 2021 18:50:47 -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=bh4kVh5V; 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 S1344557AbhITSIf (ORCPT + 99 others); Mon, 20 Sep 2021 14:08:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357157AbhITSDH (ORCPT ); Mon, 20 Sep 2021 14:03:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2AD2B63235; Mon, 20 Sep 2021 17:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158206; bh=9ys4q/Cq6uxiYo0LVkXwRkBOrR9jLBigOEKO29P6kHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bh4kVh5VfJnQqugWw2Lnh9N0WpnwPB6WwzkpWJrGec2Mp52TxGc5XUa0UXGq+9OGl d4+VFlZw+SrOfOKcG7BFV1/+yfG43lwkbFI9ZqjR6jFRCcUPWTHua7f0BdDq9muvzh YojHqIsf442JzZ6tKl1nIp6iKWPk03TIw2RyH1jc= 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.4 016/260] soc: aspeed: p2a-ctrl: Fix boundary check for mmap Date: Mon, 20 Sep 2021 18:40:34 +0200 Message-Id: <20210920163931.672711112@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 */