From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD31AC4363C for ; Wed, 7 Oct 2020 20:16:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C781206F7 for ; Wed, 7 Oct 2020 20:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZqTpxtvK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gmE2LdZ8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C781206F7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kxl2JMyRAS6/fDtlGf0Ur1KJO9BY1Od09IOoz8yPjKs=; b=ZqTpxtvKV7e8Tw+RzNLtf5dmC Aom9n6wqzGK5R5YAXW3WxTg16fpiXCR+w6SJa88C+LYRbbdMXo9QckyrAJO/WNs6+1lAZUzejbI0K bbN8P43MPLuHrc/41tTr6SEnz8WD9Is6cik6NV6DBiYyAVMq1XONpelE6pGp682knGqgMBQV30Z8z H4YssOKM8MzNohzSbSP70SnskcGCnDzotACS5YminQrTHb27PjoLIcOlwxYfpf1uaT2qHD1r0B9+5 0dqfUsj52fjtfNPrUVVSViNBx+LZ6gZ4yNDzhwVuhBWF3E0sWhu3oeaiSZ/XJ4O53E9S3CPupo8GE Mc6Gq9mgQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQFqm-0000D0-8S; Wed, 07 Oct 2020 20:15:48 +0000 Received: from userp2120.oracle.com ([156.151.31.85]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQFqj-0000C0-U7 for linux-arm-kernel@lists.infradead.org; Wed, 07 Oct 2020 20:15:46 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 097K9k4Z155286; Wed, 7 Oct 2020 20:15:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=sEc3+JOY4GEUw7wZjFGU94rrw05aoMQl93fhhWlYcUM=; b=gmE2LdZ8E+KF4wjs2C0rOpLG6fnheNQFNiI5jZsAgeMD20tsilNtf+YluYt5qq/uALMI +hk9rjugah/1hM1Hjxlr/7pNRCkpKXS4EcgOw8ZH1ZeNcG3lPp8GXOqnwtGgGttnjdIk 8tkD7VyFl2EqivTy3StxYDikwthvfNjAjGvMbVBEGFxv7E44K0SAiBVmin2r9y4lp+Fm GEW/1V1JdfDAdmGxLr+o5Mb0BkbTbR9Cnaafsuf95itcPPqRm8WHm0Lbv2Y2aRcZwxc5 NQ0HZarITCobHJ6IkCkyVwQeAp5pTucJq9OEM7ujHIHO0D4wls+zDlJCeRif1yEg22L+ LQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 33xhxn41kf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 07 Oct 2020 20:15:31 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 097KBCu4119070; Wed, 7 Oct 2020 20:15:31 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 33yyjhnk1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 07 Oct 2020 20:15:31 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 097KFUlB031996; Wed, 7 Oct 2020 20:15:30 GMT Received: from [10.65.129.34] (/10.65.129.34) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Oct 2020 13:15:29 -0700 Subject: Re: [PATCH 2/2] sparc: Check VMA range in sparc_validate_prot() To: Jann Horn , "David S. Miller" , sparclinux@vger.kernel.org, Andrew Morton , linux-mm@kvack.org References: <20201007073932.865218-1-jannh@google.com> <20201007073932.865218-2-jannh@google.com> From: Khalid Aziz X-Pep-Version: 2.0 Organization: Oracle Corp Message-ID: <230d612d-75e8-34e0-00d6-b0f7274e692c@oracle.com> Date: Wed, 7 Oct 2020 14:15:28 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201007073932.865218-2-jannh@google.com> Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9767 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010070128 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9767 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010070128 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201007_161546_152604_15F8276F X-CRM114-Status: GOOD ( 39.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Herrenschmidt , Catalin Marinas , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Paul Mackerras , Michael Ellerman , Anthony Yznaga , Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/7/20 1:39 AM, Jann Horn wrote: > sparc_validate_prot() is called from do_mprotect_pkey() as > arch_validate_prot(); it tries to ensure that an mprotect() call can't > enable ADI on incompatible VMAs. > The current implementation only checks that the VMA at the start address > matches the rules for ADI mappings; instead, check all VMAs that will be > affected by mprotect(). > > (This hook is called before mprotect() makes sure that the specified range > is actually covered by VMAs, and mprotect() returns specific error codes > when that's not the case. In order for mprotect() to still generate the > same error codes for mprotect(, , ...|PROT_ADI), we need > to *accept* cases where the range is not fully covered by VMAs.) > > Cc: stable@vger.kernel.org > Fixes: 74a04967482f ("sparc64: Add support for ADI (Application Data Integrity)") > Signed-off-by: Jann Horn > --- > compile-tested only, I don't have a Sparc ADI setup - might be nice if some > Sparc person could test this? > > arch/sparc/include/asm/mman.h | 50 +++++++++++++++++++++-------------- > 1 file changed, 30 insertions(+), 20 deletions(-) Looks good to me. Reviewed-by: Khalid Aziz > > diff --git a/arch/sparc/include/asm/mman.h b/arch/sparc/include/asm/mman.h > index e85222c76585..6dced75567c3 100644 > --- a/arch/sparc/include/asm/mman.h > +++ b/arch/sparc/include/asm/mman.h > @@ -60,31 +60,41 @@ static inline int sparc_validate_prot(unsigned long prot, unsigned long addr, > if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_ADI)) > return 0; > if (prot & PROT_ADI) { > + struct vm_area_struct *vma, *next; > + > if (!adi_capable()) > return 0; > > - if (addr) { > - struct vm_area_struct *vma; > + vma = find_vma(current->mm, addr); > + /* if @addr is unmapped, let mprotect() deal with it */ > + if (!vma || vma->vm_start > addr) > + return 1; > + while (1) { > + /* ADI can not be enabled on PFN > + * mapped pages > + */ > + if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) > + return 0; > > - vma = find_vma(current->mm, addr); > - if (vma) { > - /* ADI can not be enabled on PFN > - * mapped pages > - */ > - if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) > - return 0; > + /* Mergeable pages can become unmergeable > + * if ADI is enabled on them even if they > + * have identical data on them. This can be > + * because ADI enabled pages with identical > + * data may still not have identical ADI > + * tags on them. Disallow ADI on mergeable > + * pages. > + */ > + if (vma->vm_flags & VM_MERGEABLE) > + return 0; > > - /* Mergeable pages can become unmergeable > - * if ADI is enabled on them even if they > - * have identical data on them. This can be > - * because ADI enabled pages with identical > - * data may still not have identical ADI > - * tags on them. Disallow ADI on mergeable > - * pages. > - */ > - if (vma->vm_flags & VM_MERGEABLE) > - return 0; > - } > + /* reached the end of the range without errors? */ > + if (addr+len <= vma->vm_end) > + return 1; > + next = vma->vm_next; > + /* if a VMA hole follows, let mprotect() deal with it */ > + if (!next || next->vm_start != vma->vm_end) > + return 1; > + vma = next; > } > } > return 1; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel