Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3133544pxj; Mon, 10 May 2021 19:59:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjru7SAaO06CwXt93SrOq3+aSK9PQ9JJghgfHkR+OeLi7RqlQKeXTsWjbQAuzeRYq799gy X-Received: by 2002:aa7:c691:: with SMTP id n17mr16425168edq.243.1620701984763; Mon, 10 May 2021 19:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620701984; cv=none; d=google.com; s=arc-20160816; b=bJdtMzy0jwX3yRXcRdh57GBDSoRj0Igm97kU3CmKQsxL2SIQ7KXZNn2kYcND1bUd2X 40Z9Qe3b1mlRxkoKGcwAS5I3qg2M/lvZ8Uh6/awWw0x0nomCbg4MDShu0Mep5xsC7dZE SK/crjIOY4kmdtmEwcvV6TUugEwo52z8xwPZdV8I+s2f5ffUN+tKcZYGCXOwrCbISXVo RXsfsmRJUwmpXHJSnsDrOWMFcBndZTHvyqavlCbfa6qld7nPPEU43wqZFidLNU3LsERD dkYpJ4o/zC2xW8ZE9mlWeFgY10YfsKcx8P7gnixE1/LZd0t1JgH2+G9uLe39hoZGCM1x 7vyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JxJR04Xv/YnMAFrcHyESkEXBblvroZPD5TgFitfVkoo=; b=0v5GoAUArmel7tZeuH1Eq+iWgQAI2Y4FhUS6sjMqhFx77FiLdtEJJXfowBc8jEMoan qKWX3szAk5vtrVImOv2/kVTVw7WFQ8WeadS+ubmmTkj2ziOVKqUlOzkYB5F37gi0jRkg 3+WzyH4vNVKDb676IdGPFYCPlZwvLAL7fvIavNHPV+GT3u5CRWh9zogkd3l7WAU/Yw77 qz1XxF4QBYGBziHQ0N3mVOo+k21eO94n5iDbblfPqz3FK0EDZYz69Pip1fgZ3vWWU9mH DgVhYgipJGe7fOfXJ4xclsDc/nF1Enf2v39Xu5RSBbESq61kuMGUMuQqpmS24ypuz4kZ 56aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RbexxldZ; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si14738792ejh.586.2021.05.10.19.59.20; Mon, 10 May 2021 19:59:44 -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=@chromium.org header.s=google header.b=RbexxldZ; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhEKC7d (ORCPT + 99 others); Mon, 10 May 2021 22:59:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhEKC7c (ORCPT ); Mon, 10 May 2021 22:59:32 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6840BC06175F for ; Mon, 10 May 2021 19:58:27 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id l10-20020a17090a850ab0290155b06f6267so456381pjn.5 for ; Mon, 10 May 2021 19:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JxJR04Xv/YnMAFrcHyESkEXBblvroZPD5TgFitfVkoo=; b=RbexxldZUVymd2P/sIJDv9SMCoq8cD1CsFLOcLwfXYxm4mtn7+1MJlPRjvy9LM1mBe ZqxuadNDV8Tg01bppw8VAYW8pmg4peKpLWe727NAwtxDpN7+5gfUp7wIHmlhe3wJ0py9 FL0kQOiaKnzDcmer8y7tk4eExkKRwXIvKZhh8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JxJR04Xv/YnMAFrcHyESkEXBblvroZPD5TgFitfVkoo=; b=bgg49H87S2ZEx93eYYrGvJpkhH7W6cyzn6eccj7SrvIRQDwYp6nzjCct5EfGyaj7Uv kouzuaUVrvDp8H63h7SQ1MIigYXh3aINjeQ2zuP6QKc5Z+twbcdfKKd0j9mhm482RgjM n5YFqEWrkXUFhZjB/93horbPpZ3sRF0HnjSoM+7Zvl4p0qxXxyIk2EhFgpldgaa1HbGx VZ/kjhPGxDZ0k5/Pyo27CdhDtn9Tkkp3Bhlnlf5gB0JPHHlgZ9o8BpcXfCW+0ykY83gz ub8jXUZ3X0SQe10VI6V0vb98pRycNScATBj9h2DykGmQeVLFp++z3K9ft6Y9ytxlfHOR ze+A== X-Gm-Message-State: AOAM530Dr8hFTyJdiiYK5qfBQ0Hf87mOP9Bbd6G2HLK+6YOZUgMnC+eG jOzhsXmPuRTJ2FuFhXjZz5njmw== X-Received: by 2002:a17:90a:df0b:: with SMTP id gp11mr13701357pjb.4.1620701906855; Mon, 10 May 2021 19:58:26 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e6sm12099160pfd.219.2021.05.10.19.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 19:58:26 -0700 (PDT) Date: Mon, 10 May 2021 19:58:25 -0700 From: Kees Cook To: Maxime Coquelin Cc: alex.williamson@redhat.com, jmorris@namei.org, dhowells@redhat.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, kvm@vger.kernel.org, mjg59@srcf.ucam.org, cohuck@redhat.com Subject: Re: [PATCH] vfio: Lock down no-IOMMU mode when kernel is locked down Message-ID: <202105101955.933F66A@keescook> References: <20210506091859.6961-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210506091859.6961-1-maxime.coquelin@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 06, 2021 at 11:18:59AM +0200, Maxime Coquelin wrote: > When no-IOMMU mode is enabled, VFIO is as unsafe as accessing > the PCI BARs via the device's sysfs, which is locked down when > the kernel is locked down. > > Indeed, it is possible for an attacker to craft DMA requests > to modify kernel's code or leak secrets stored in the kernel, > since the device is not isolated by an IOMMU. > > This patch introduces a new integrity lockdown reason for the > unsafe VFIO no-iommu mode. > > Signed-off-by: Maxime Coquelin > --- > drivers/vfio/vfio.c | 13 +++++++++---- > include/linux/security.h | 1 + > security/security.c | 1 + > 3 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > index 5e631c359ef2..fe466d6ea5d8 100644 > --- a/drivers/vfio/vfio.c > +++ b/drivers/vfio/vfio.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -165,7 +166,8 @@ static void *vfio_noiommu_open(unsigned long arg) > { > if (arg != VFIO_NOIOMMU_IOMMU) > return ERR_PTR(-EINVAL); > - if (!capable(CAP_SYS_RAWIO)) > + if (!capable(CAP_SYS_RAWIO) || > + security_locked_down(LOCKDOWN_VFIO_NOIOMMU)) The LSM hook check should come before the capable() check to avoid setting PF_SUPERPRIV if capable() passes and the LSM doesn't. > diff --git a/include/linux/security.h b/include/linux/security.h > index 06f7c50ce77f..f29388180fab 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -120,6 +120,7 @@ enum lockdown_reason { > LOCKDOWN_MMIOTRACE, > LOCKDOWN_DEBUGFS, > LOCKDOWN_XMON_WR, > + LOCKDOWN_VFIO_NOIOMMU, > LOCKDOWN_INTEGRITY_MAX, > LOCKDOWN_KCORE, > LOCKDOWN_KPROBES, Is the security threat specific to VFIO? (i.e. could other interfaces want a similar thing, such that naming this VFIO doesn't make sense? -- Kees Cook