Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp375104pxb; Mon, 16 Aug 2021 07:26:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyOomvPfeXoDWst95vBxoSKqHsn0Q91XPLLGEB5oTe2ea0zktterAACWMp82uqAG8JHDxz X-Received: by 2002:a02:93c1:: with SMTP id z59mr10159731jah.2.1629124005275; Mon, 16 Aug 2021 07:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629124005; cv=none; d=google.com; s=arc-20160816; b=jY9JAf5T6a4tGb9FumZ9mDSokUM6Hn0tLTuZAAdT9YxtIAZCckA+Le65Ojb66xD0I+ YglrjbelgfabOieTe1fMZx6dTryntQcr91zPOq4rxR47UdCi5jQAN8BnukZYQDTlv1ce XjluVMoGiLWp5H0hndcYY7SnLqczH4lERP8lssW1NBY5GGAvwf0wb6DQJh4Da/jzNGk5 bKIq2krjWElp3nxm7MEjrn1jxpHLJEJUFlVVBBR2/XVspV+1WIF2Dvvg29XvsraI0wlK mZ+i+FxzWYyVGfBzsZ6Rp9qTlIc1/eVtrEBT4nreooHBvvfGDQPoIqldj3i+rdoIhDWE JSxQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3hywntJFvc8rY3h4zVE0FB14e7oRCBStJ9/imcpDrqo=; b=u6aVwuRYc4aYnqs6C/CDeZo+orxxoaFQ76bN400FAdHizP6puQJSYUO0IQVORhIHGt mfas0ZXmDlDxkms41RKFjPEXHe4okXBpiN/sUuNWz1JWidllwbBHVND/cnWbCUvZ/EqF RoFODrSCZBx3/St5XQrtICaAQrqEOS8a1QG9R1+M0wa3ttw5qXcJod+KmHWZKnqFGxCO 9QmbpnUHmyeA5HUqmOdq5YMOcMqgkeGQEpEnc0SdwVuyrGn3hGn0qSjMoizuN2ssJ+N6 Bj47zSqPCNtPrh1fdNTxfQ9IPkeqN4bqBHQJaTskLDpSFboEV8jfpttTTXxfI8V76JUG EDIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UTfwVNrC; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q14si1126436ilv.151.2021.08.16.07.26.34; Mon, 16 Aug 2021 07:26:45 -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=@redhat.com header.s=mimecast20190719 header.b=UTfwVNrC; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbhHPO0I (ORCPT + 99 others); Mon, 16 Aug 2021 10:26:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49348 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbhHPO0H (ORCPT ); Mon, 16 Aug 2021 10:26:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629123935; 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=3hywntJFvc8rY3h4zVE0FB14e7oRCBStJ9/imcpDrqo=; b=UTfwVNrC52ceko9QgtxemiuM+A3XFJ9M2gTWIg1q2Edc0fQQFwagAIiDQCcJ+j+LZ/IskK qly59K9ptXlit9dTGVVIsqaWgZiFxowOhdkorxups7OzVZW+2m2XsDJMK9AlJORGrRXD68 udFI5rGX48IFRzn2l7Sh9gnaHlHOnqU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-_Qc_Bh6wPZS4B14o-y1l_g-1; Mon, 16 Aug 2021 10:25:32 -0400 X-MC-Unique: _Qc_Bh6wPZS4B14o-y1l_g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 61F3469737; Mon, 16 Aug 2021 14:25:30 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.192.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E96FE723; Mon, 16 Aug 2021 14:25:23 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , "Rafael J. Wysocki" , Andrew Morton , Dan Williams , Hanjun Guo , Andy Shevchenko , virtualization@lists.linux-foundation.org, linux-mm@kvack.org Subject: [PATCH v2 2/3] virtio-mem: disallow mapping virtio-mem memory via /dev/mem Date: Mon, 16 Aug 2021 16:25:04 +0200 Message-Id: <20210816142505.28359-3-david@redhat.com> In-Reply-To: <20210816142505.28359-1-david@redhat.com> References: <20210816142505.28359-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By creating our parent IORESOURCE_SYSTEM_RAM resource with IORESOURCE_EXCLUSIVE, we will disallow any /dev/mem access to our device-managed region. Note that access to the region would still be possible if someone simply doesn't load the virtio-mem driver; however, there is no way of protecting against someone that just wants to do nasty things. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 09ed55de07d7..c8f914700a42 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2516,8 +2516,10 @@ static int virtio_mem_create_resource(struct virtio_mem *vm) if (!name) return -ENOMEM; + /* Disallow mapping device memory via /dev/mem completely. */ vm->parent_resource = __request_mem_region(vm->addr, vm->region_size, - name, IORESOURCE_SYSTEM_RAM); + name, IORESOURCE_SYSTEM_RAM | + IORESOURCE_EXCLUSIVE); if (!vm->parent_resource) { kfree(name); dev_warn(&vm->vdev->dev, "could not reserve device region\n"); -- 2.31.1