From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752068AbcGSUOm (ORCPT ); Tue, 19 Jul 2016 16:14:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:29497 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751892AbcGSUOi (ORCPT ); Tue, 19 Jul 2016 16:14:38 -0400 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: borntraeger@de.ibm.com X-IBM-RcptTo: linux-arch@vger.kernel.org;linux-ia64@vger.kernel.org;linux-kernel@vger.kernel.org;sparclinux@vger.kernel.org Subject: Re: [PATCH v3 02/11] mm: Hardened usercopy To: Kees Cook References: <1468619065-3222-1-git-send-email-keescook@chromium.org> <1468619065-3222-3-git-send-email-keescook@chromium.org> <578DF109.5030704@de.ibm.com> Cc: LKML , Balbir Singh , Daniel Micay , Josh Poimboeuf , Rik van Riel , Casey Schaufler , PaX Team , Brad Spengler , Russell King , Catalin Marinas , Will Deacon , Ard Biesheuvel , Benjamin Herrenschmidt , Michael Ellerman , Tony Luck , Fenghua Yu , "David S. Miller" , "x86@kernel.org" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Andy Lutomirski , Borislav Petkov , Mathias Krause , Jan Kara , Vitaly Wool , Andrea Arcangeli , Dmitry Vyukov , Laura Abbott , "linux-arm-kernel@lists.infradead.org" , linux-ia64@vger.kernel.org, "linuxppc-dev@lists.ozlabs.org" , sparclinux , linux-arch , Linux-MM , "kernel-hardening@lists.openwall.com" From: Christian Borntraeger Date: Tue, 19 Jul 2016 22:14:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071920-0040-0000-0000-0000020185CB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071920-0041-0000-0000-00002109DF79 Message-Id: <578E8A22.5080807@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-19_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607190215 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/19/2016 09:31 PM, Kees Cook wrote: > On Tue, Jul 19, 2016 at 2:21 AM, Christian Borntraeger > wrote: >> On 07/15/2016 11:44 PM, Kees Cook wrote: >>> +config HAVE_ARCH_LINEAR_KERNEL_MAPPING >>> + bool >>> + help >>> + An architecture should select this if it has a secondary linear >>> + mapping of the kernel text. This is used to verify that kernel >>> + text exposures are not visible under CONFIG_HARDENED_USERCOPY. >> >> I have trouble parsing this. (What does secondary linear mapping mean?) > > I likely need help clarifying this language... > >> So let me give an example below >> >>> + >> [...] >>> +/* Is this address range in the kernel text area? */ >>> +static inline const char *check_kernel_text_object(const void *ptr, >>> + unsigned long n) >>> +{ >>> + unsigned long textlow = (unsigned long)_stext; >>> + unsigned long texthigh = (unsigned long)_etext; >>> + >>> + if (overlaps(ptr, n, textlow, texthigh)) >>> + return ""; >>> + >>> +#ifdef HAVE_ARCH_LINEAR_KERNEL_MAPPING >>> + /* Check against linear mapping as well. */ >>> + if (overlaps(ptr, n, (unsigned long)__va(__pa(textlow)), >>> + (unsigned long)__va(__pa(texthigh)))) >>> + return ""; >>> +#endif >>> + >>> + return NULL; >>> +} >> >> s390 has an address space for user (primary address space from 0..4TB/8PB) and a separate >> address space (home space from 0..4TB/8PB) for the kernel. In this home space the kernel >> mapping is virtual containing the physical memory as well as vmalloc memory (creating aliases >> into the physical one). The kernel text is mapped from _stext to _etext in this mapping. >> So I assume this would qualify for HAVE_ARCH_LINEAR_KERNEL_MAPPING ? > > If I understand your example, yes. In the home space you have two > addresses that reference the kernel image? No, there is only one address that points to the kernel. As we have no kernel ASLR yet, and the kernel mapping is a 1:1 mapping from 0 to memory end and the kernel is only from _stext to _etext. The vmalloc area contains modules and vmalloc but not a 2nd kernel mapping. But thanks for your example, now I understood. If we have only one address >>> + if (overlaps(ptr, n, textlow, texthigh)) >>> + return ""; This is just enough. So what about for the CONFIG text: An architecture should select this if the kernel mapping has a secondary linear mapping of the kernel text - in other words more than one virtual kernel address that points to the kernel image. This is used to verify that kernel text exposures are not visible under CONFIG_HARDENED_USERCOPY. > I wonder if I can avoid the CONFIG entirely if I just did a > __va(__pa(_stext)) != _stext test... would that break anyone? Can this be resolved on all platforms at compile time?