Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2361263ybi; Sun, 9 Jun 2019 09:51:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYCcuTfsf+tY79i6YtLaRbAjhWXWIyLFvfB2flq7OSql8nAzPmBhAxjMQFZZ9UmJP0GL8Y X-Received: by 2002:a17:902:2847:: with SMTP id e65mr62301830plb.319.1560099114374; Sun, 09 Jun 2019 09:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560099114; cv=none; d=google.com; s=arc-20160816; b=n4OXmOYvTi7rTJcfNm6qxro76l8SJAbUBr5gpfmoWMh+UdXbenu5hvfi8CFusg0KHG yTytXeBnwJoA4bi9BCDV/iNgVfpTC0bkULPifiDjue7kwFoiZq+Q5KYLQQNl2xBNtDIr +MlC0B7/VBkLYB7CryxG1Or+ROqcCBcn3joCaEY99k2hpNZBsObFXo4tMYKR99Ntwb3b 03ooXrDBdkZ12AiZOgn0eO0/vfRHuYB6pCbStCiezpv8VZsko9eD0DyB/HPCj7ENsf9u Fc+0USrmujqwoq8Fi5PQs095x6wFHFPV5pU13K04zwx/xuIThuAXhNaM2+8yYWpgwFfW sLQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VHwi/zjMYtL9UA+51wL7n6txoPs5KZNyfw6hmRwqNpY=; b=e7f5XfxRmU7ZEF00sSrdh/x5xiTbfKOrYWxtGKm+xM7UZ0d/8WqCNQfMcpdZQ9qJwG HSA1/Aiz5Jt3HFLtm0eWu7giaqJDND+9c6YBaJs79P2qN2p/A20fUksXszCZ63h8kh9k sIqS9DKyWeUDC1EPxTACCW+17PTpWbVDwqgiOk5MR4ZyTG80EpFCTx0SPiJEk7D++7AS DjgUl9Bheo1r90I9dlgnXGzrMkWAkdEDgemULRTCF7dCaniRMFkUYZBzBpN+5dWNmBw/ mukWSnl1rZthzRABAKcOVi1jIPYeupWDb5wlW3p8bKzLIR08rKj66ibRDA00tKc02mZF KI+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="qC1j/oDV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si7263900pll.145.2019.06.09.09.51.38; Sun, 09 Jun 2019 09:51:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="qC1j/oDV"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731233AbfFIQsf (ORCPT + 99 others); Sun, 9 Jun 2019 12:48:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:47636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731216AbfFIQsc (ORCPT ); Sun, 9 Jun 2019 12:48:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BD88205ED; Sun, 9 Jun 2019 16:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560098911; bh=TJCm5AsGVKgzsrO8Flov/50oIA64VW2TAdaGPxGaYm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qC1j/oDVF/GMDJDp31oXBmbDvrxB2eoJlwFK99j5NHekhJCih1Hrh/xT1aDzsnp/S 5i35xgx8mT4BxpRKa6ipSCI6l9f4xOKsf8rm/rM6mV6DGn3IKp6p/KghFYi0YazI1L NWMRTsMxDcc36R5YOBj+uryVLbW/jHAoPCi9iJ7o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Burton , Julien Cristau , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , YunQiang Su , linux-mips@vger.kernel.org Subject: [PATCH 4.19 32/51] MIPS: Bounds check virt_addr_valid Date: Sun, 9 Jun 2019 18:42:13 +0200 Message-Id: <20190609164129.141484622@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.123076536@linuxfoundation.org> References: <20190609164127.123076536@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Burton commit 074a1e1167afd82c26f6d03a9a8b997d564bb241 upstream. The virt_addr_valid() function is meant to return true iff virt_to_page() will return a valid struct page reference. This is true iff the address provided is found within the unmapped address range between PAGE_OFFSET & MAP_BASE, but we don't currently check for that condition. Instead we simply mask the address to obtain what will be a physical address if the virtual address is indeed in the desired range, shift it to form a PFN & then call pfn_valid(). This can incorrectly return true if called with a virtual address which, after masking, happens to form a physical address corresponding to a valid PFN. For example we may vmalloc an address in the kernel mapped region starting a MAP_BASE & obtain the virtual address: addr = 0xc000000000002000 When masked by virt_to_phys(), which uses __pa() & in turn CPHYSADDR(), we obtain the following (bogus) physical address: addr = 0x2000 In a common system with PHYS_OFFSET=0 this will correspond to a valid struct page which should really be accessed by virtual address PAGE_OFFSET+0x2000, causing virt_addr_valid() to incorrectly return 1 indicating that the original address corresponds to a struct page. This is equivalent to the ARM64 change made in commit ca219452c6b8 ("arm64: Correctly bounds check virt_addr_valid"). This fixes fallout when hardened usercopy is enabled caused by the related commit 517e1fbeb65f ("mm/usercopy: Drop extra is_vmalloc_or_module() check") which removed a check for the vmalloc range that was present from the introduction of the hardened usercopy feature. Signed-off-by: Paul Burton Reported-by: Julien Cristau Reviewed-by: Philippe Mathieu-Daudé Tested-by: YunQiang Su URL: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929366 Cc: stable@vger.kernel.org # v4.12+ Cc: linux-mips@vger.kernel.org Cc: Yunqiang Su Signed-off-by: Greg Kroah-Hartman --- arch/mips/mm/mmap.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -203,6 +203,11 @@ unsigned long arch_randomize_brk(struct int __virt_addr_valid(const volatile void *kaddr) { + unsigned long vaddr = (unsigned long)vaddr; + + if ((vaddr < PAGE_OFFSET) || (vaddr >= MAP_BASE)) + return 0; + return pfn_valid(PFN_DOWN(virt_to_phys(kaddr))); } EXPORT_SYMBOL_GPL(__virt_addr_valid);