From patchwork Mon Jan 2 16:08:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13086803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 584C0C54E76 for ; Mon, 2 Jan 2023 16:09:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2F918E0006; Mon, 2 Jan 2023 11:09:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE1878E0001; Mon, 2 Jan 2023 11:09:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7F4D8E0006; Mon, 2 Jan 2023 11:09:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AD7A58E0001 for ; Mon, 2 Jan 2023 11:09:17 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8B0321A0995 for ; Mon, 2 Jan 2023 16:09:17 +0000 (UTC) X-FDA: 80310343554.27.5050686 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id F2F57A000E for ; Mon, 2 Jan 2023 16:09:15 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Lxe/2IR6"; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672675756; a=rsa-sha256; cv=none; b=BV8xX/JaoG+imqTlP3udJwXcCI0FsHgHY+6AT1NU4sSavSx/XgbBjV5dPynyByyMQzTmPy XzBm2ku/CH3wWDLJ03Qx+829KsRTA4vniaGtoch8WXO+iUC8dqywCcfyzg+pEgqhOG8goK lvE5Pg2ngQryVhq2f2OEAjUCrtoxNJ4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Lxe/2IR6"; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672675756; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Sh73hBCrQns8aoevVV+OOnfi6R1HtUp1NLv5DeAjtKc=; b=Di4JCKLOW6LrS4QYwJwxn+fh3fr5LRDscSZL523NsOuTjPC9yelFSGziP6YntxCgrD75e+ KJKAdUiLdTNrPAl05bsBpW3JEJR7jQFKys4mkP0qX+X65VJPap+4C4JaW+2CgSSPU1QxhJ 55bIAgNXChg8CxKyFi2BEeKGnTmhwYs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672675755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sh73hBCrQns8aoevVV+OOnfi6R1HtUp1NLv5DeAjtKc=; b=Lxe/2IR66UfxphV5VUq8KdTb6pAnT8h4ANievpAIeuIuy41/HsFwOaFVxX+EvYncxbjkcx f4OF6zdFKEnJje/FPV9W65JY2IpJ+9Y6ByeVU2BlDWFdqffT/P6eN7BWeTh+Do9aI7OaWI n3tRyoACbCG0GSKxhfZjbXSXar85O54= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-h6RgIbbbPnKtMqdUN9kSDg-1; Mon, 02 Jan 2023 11:09:09 -0500 X-MC-Unique: h6RgIbbbPnKtMqdUN9kSDg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48408811E6E; Mon, 2 Jan 2023 16:09:08 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D18D35455; Mon, 2 Jan 2023 16:09:06 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, David Hildenbrand , Andrew Morton , Arnd Bergmann , Greg Kroah-Hartman , Nicolas Pitre , Jens Axboe , Pavel Begunkov Subject: [PATCH mm-unstable v1 3/3] drivers/misc/open-dice: don't touch VM_MAYSHARE Date: Mon, 2 Jan 2023 17:08:56 +0100 Message-Id: <20230102160856.500584-4-david@redhat.com> In-Reply-To: <20230102160856.500584-1-david@redhat.com> References: <20230102160856.500584-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Queue-Id: F2F57A000E X-Rspamd-Server: rspam01 X-Stat-Signature: ryb9hqzfweots9dmkjmj8158sj91ep7s X-HE-Tag: 1672675755-377829 X-HE-Meta: U2FsdGVkX18FLY8Ys20bvbk9SHBglHk9AfPpNjIzulqNJ5y+xfySbbYI73na+crb4h9dI+qCu0PLEV8CuUof0j7jv+ntT5BnRN88lQF7H0VojB2IrAhAIoExjM3P4Ugd7LjEyOKDaGL9j8gXtxsNKZFiD0ULexIJXB+tpspPlVe/AhRlzJRzRlyLNGTHfouX8VJmEDDuq20DkaR5YiXAVQ7MT4EBed4ebrInQtHPJsU/HJ7ZTuNvGl7yWOD2dUH7ndSUy6W7x4ZxPs7O2nuj9dq0K63kNRRA3UalzEhqV0uXJ5JEweYM+D/PzyLUMMO2WF7gYMoJQvyXjGqzeMw97+1I3hrW0vwVGAQxAUzWX9so3+GZLIabLtZFrmvZ8QjsNLr3iNpupi0WPjeXFH11I4tG4Bc1fpEHtzNAHjNBHjUPPBPZYY2D0d1N1oLirpHxrtq/8D+PISkFeZa8bvm+EQWU+fpN6czWkBtn7i0Ptl0oEwIG1QC5ND9OLYrbXj4Y3x5IFlBlDqiMEP9aSdQKnKXXptaEAmiuHSuD0epQHrkxdPb7MR0koEL9AFsF9MZlBEPDaC4GH3qhIyfXl7NHMIK/qDXdfc6OmbEsWETOIbvccQZyphiZRatsHMQ4fayS4mv0gOFb8gzfzHFGtpLZH7WqoJFVzSiZofztEW31uOW0MNSv8ehi4KzJNF2HT3PwnXJrnYuer8SCV34BL8p7izQxS+5NjDR99Bw6SwwoSPrMmhkpvqvyOgo/dLFnkfBIn5QBGDgEPopULbIxq0QSuNJNONzMshHutORM3K7bV/68ic+D0/nvu39d8lDEgVQ+s4R/jlbgRDZ803WxWdFa1MQ+3Vkhbl8Q/dBQxIOwbJ/aTODQCmHSxBUNAZag5l8t2bUKqNOTWYNWPuodVae/MhRcrvnaqEyZyW0QdETClWV81Mq9dt+YMbFbbb53/0S0GZTVHDUty8kaq7iEhMh AvT14mHG ky+HlY8BR+fa/xScCBllrvpjTLj3YdMytfVkosTDsPGn30KQLyaJk+2NRVe8rK5KCqYt/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A MAP_SHARED mapping always has VM_MAYSHARE set, and writable (VM_MAYWRITE) MAP_SHARED mappings have VM_SHARED set as well. To identify a MAP_SHARED mapping, it's sufficient to look at VM_MAYSHARE. We cannot have VM_MAYSHARE|VM_WRITE mappings without having VM_SHARED set. Consequently, current code will never actually end up clearing VM_MAYSHARE and that code is confusing, because nobody is supposed to mess with VM_MAYWRITE. Let's clean it up and restructure the code. No functional change intended. Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Signed-off-by: David Hildenbrand --- drivers/misc/open-dice.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/misc/open-dice.c b/drivers/misc/open-dice.c index c61be3404c6f..9dda47b3fd70 100644 --- a/drivers/misc/open-dice.c +++ b/drivers/misc/open-dice.c @@ -90,15 +90,13 @@ static int open_dice_mmap(struct file *filp, struct vm_area_struct *vma) { struct open_dice_drvdata *drvdata = to_open_dice_drvdata(filp); - /* Do not allow userspace to modify the underlying data. */ - if ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED)) - return -EPERM; - - /* Ensure userspace cannot acquire VM_WRITE + VM_SHARED later. */ - if (vma->vm_flags & VM_WRITE) - vma->vm_flags &= ~VM_MAYSHARE; - else if (vma->vm_flags & VM_SHARED) + if (vma->vm_flags & VM_MAYSHARE) { + /* Do not allow userspace to modify the underlying data. */ + if (vma->vm_flags & VM_WRITE) + return -EPERM; + /* Ensure userspace cannot acquire VM_WRITE later. */ vma->vm_flags &= ~VM_MAYWRITE; + } /* Create write-combine mapping so all clients observe a wipe. */ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);