From patchwork Fri Oct 20 15:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 156203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1155993vqb; Fri, 20 Oct 2023 09:00:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwekB1Uy9z/TYHKvSTpdZCJjDRX58vGrHhyi21R3b9RpJjtrBv4O8Bin0qk5jaQ+DKbvli X-Received: by 2002:a05:6a20:6a1f:b0:15e:7323:5bf3 with SMTP id p31-20020a056a206a1f00b0015e73235bf3mr7757873pzk.26.1697817638357; Fri, 20 Oct 2023 09:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697817638; cv=none; d=google.com; s=arc-20160816; b=VRizY5XPAtBCCrBCxY6DwXUU8XyYPIgXU0pGR+eTOMchaQQ3KSpQq3Q25/w0JeXjML LY0/HCoeFqh50yGBgDU3ihhTvwwG/cktncExbdCKqY1efYvRhBgqL6sajXpROtDN+bmu poIsdbil/vYXvU1ptBUxguMMAfZl4RB4Dkrf8rmOcdOKwBXB/0r2VEYSImy2DTTOW+wi jTQmTnfdoChFYGBtu54i7Oi1+CBRrDdX15xH1Y3qGLwmnMxkiMY2Wm2vIiPxF5VIVj96 jZ7CDQJp/rfMXKib5LYBIvVQYFT9DUIypN3T+wezso0evOh6HsgzTSrqDlyukVeoRCsl BaYg== 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=PrVd5hNLS1wjnMKJG4uMD0VRG9l+SsuhqjwmjWwDMM4=; fh=DW2mHD/f0kRN+01V+Z9as8p7OnC0swQlfBH91pgf6/A=; b=aDOv2MgbVOH4oZAbZopBmbm4le3gcNtRCh5NhWZdG1jyhlfKg2hzeW0emkjDSJ1B04 bQsg6MUosDSOEfO/L6iTFgrFtKyWwPzcmItnzCkNFlHFsk/aUUH7xAjq5rkHM9JBTKCl oaImCn0uI7BcXJ/DHohMcs8Rrpk6JSuTEapc44vJL1PSg5IWwwBowOhEdYYp7JAC98p9 rxizdrm1IEJzxpQ0Jl208pv310kk/u+iEPOy4k99n85QYQst4iRjfMDZzPJVl1wW0qB9 70Mhl+fQrx4tcWQr/fJB9ajon/JSHPn9mY34xNsMFmtV0IvJdGOSCAqy0XvDzI/DjwAz nFqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gde7rFo1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id c7-20020a633507000000b0057744d09d1bsi2209844pga.251.2023.10.20.09.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:00:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gde7rFo1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 32BB0833F8FE; Fri, 20 Oct 2023 09:00:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377852AbjJTQAM (ORCPT + 26 others); Fri, 20 Oct 2023 12:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377835AbjJTQAK (ORCPT ); Fri, 20 Oct 2023 12:00:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170DED73 for ; Fri, 20 Oct 2023 08:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697817529; 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=PrVd5hNLS1wjnMKJG4uMD0VRG9l+SsuhqjwmjWwDMM4=; b=Gde7rFo1I77vKSXaaT6sCNbmBUeBnF5lf95Jkywj5jC6D1SlATsHPnTjL4lp+0sMSR5Tml qdLn/I8vvxMrnuaVAkDfHSy4Oi/BZIB3m3ffB8iinLglApo/cyylBG5sn1LteW62naksYL H/geAOVcthe7iHqEEZc5InodH8V8V/0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-oJ_RXLPwNCCswWlW3aS1YA-1; Fri, 20 Oct 2023 11:58:33 -0400 X-MC-Unique: oJ_RXLPwNCCswWlW3aS1YA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6CED2857D07; Fri, 20 Oct 2023 15:58:32 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61637503B; Fri, 20 Oct 2023 15:58:29 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, xieyongji@bytedance.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, david.marchand@redhat.com, lulu@redhat.com Cc: Maxime Coquelin Subject: [PATCH v4 1/4] vduse: validate block features only with block devices Date: Fri, 20 Oct 2023 17:58:16 +0200 Message-ID: <20231020155819.24000-2-maxime.coquelin@redhat.com> In-Reply-To: <20231020155819.24000-1-maxime.coquelin@redhat.com> References: <20231020155819.24000-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:00:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780290827742759763 X-GMAIL-MSGID: 1780290827742759763 This patch is preliminary work to enable network device type support to VDUSE. As VIRTIO_BLK_F_CONFIG_WCE shares the same value as VIRTIO_NET_F_HOST_TSO4, we need to restrict its check to Virtio-blk device type. Acked-by: Jason Wang Reviewed-by: Xie Yongji Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index df7869537ef1..5b3879976b3d 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1662,13 +1662,14 @@ static bool device_is_allowed(u32 device_id) return false; } -static bool features_is_valid(u64 features) +static bool features_is_valid(struct vduse_dev_config *config) { - if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) + if (!(config->features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) return false; /* Now we only support read-only configuration space */ - if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)) + if ((config->device_id == VIRTIO_ID_BLOCK) && + (config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))) return false; return true; @@ -1695,7 +1696,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config) if (!device_is_allowed(config->device_id)) return false; - if (!features_is_valid(config->features)) + if (!features_is_valid(config)) return false; return true; From patchwork Fri Oct 20 15:58:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 156201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1155219vqb; Fri, 20 Oct 2023 08:59:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeJ53W8XmArNKiN4pL83oduzfP7ZGHwgOmHOcOkTr5y8ZwOxiZ2XipUnnT3Q9pDKZgzg06 X-Received: by 2002:a05:6358:93a3:b0:13a:4f34:8063 with SMTP id h35-20020a05635893a300b0013a4f348063mr2435342rwb.32.1697817572803; Fri, 20 Oct 2023 08:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697817572; cv=none; d=google.com; s=arc-20160816; b=Mm32i7dj7ViMGY9xK5QQwNx3xW5ol5Cw0v95NJNmg/J+e2jya0CI639houriwyYOe/ O5VHpzHgMlU54LAEtnEoWMIPQwnUZr0obO8LNE37rINcQXtEWID15QYzWR8ndnZjo9lp YTtJfM2xQSKxxe4+mo8YsAVvgrlGMNs5OJb6r8/7r24NYgLOyRFulc6H1crLupSrPeDu azdfoI0S1S1FOUpOeuIH7qtT/7O7EzEziVI7wbuEe2fWYYFhKXmJBJ1gGxbZbB6GGTHN efYwSVk0oQGmHDjRebqp85d6X1QNwohBZtmogwwG9uEbxBNc9tEG6HEnEez2xiZJ12hx eIBg== 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=sJDKpQQy665XvGZPky5UtXAeHywtQ/JigxzuJqzayEo=; fh=DW2mHD/f0kRN+01V+Z9as8p7OnC0swQlfBH91pgf6/A=; b=gGW/pZ7dEc14s8NgT2ay0Dfgt8f3YwhnNlxlwgPjxyKuUa4bulLo9Kj5piDctaJQbc uh91kyF4Sgl+3G48mXldHtCcHpS73PL4oxbPF9GoaCDG/zQee9AofT1IQXY7BhAfMdt/ 09l5a/qNGitfjGC4hpVsrZDGzkCg8J5dOn9sEvDL6thBh8j5JmGkntl099LI0BrRmbU2 ktYbDByPypo2l5Wv0vGs59y7HJW5KP++eRQs6rsec9JACtgG3BbAF4NtEe5xN7tlT+ky JeIxmZKroyvitQYTWlY3sa3F9uVhKlHWCs/npmTjOCNcfC/ayfP+wraoLQw5RxaeaTZw yTbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5ybDBf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d38-20020a631d66000000b00578c64433d5si2053280pgm.877.2023.10.20.08.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5ybDBf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F1ED882F7FBA; Fri, 20 Oct 2023 08:59:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377828AbjJTP72 (ORCPT + 26 others); Fri, 20 Oct 2023 11:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377825AbjJTP7Z (ORCPT ); Fri, 20 Oct 2023 11:59:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B61AB3 for ; Fri, 20 Oct 2023 08:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697817520; 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=sJDKpQQy665XvGZPky5UtXAeHywtQ/JigxzuJqzayEo=; b=h5ybDBf3gXe7Q0eb0xYrkIs5InhwZO5XftGD+RvPnrTJiVJbM7xbD1NMsdGLMDoaTPznQY 2Zqp1Ig0xPMmkvnyDpyh4U2lVF9+UOHIigxw0wov/Ejoud9X2jSrr4aQ2e1oErh58GIEW3 zNhwDrMEee3HD07kVYL0EHrxGm1Km+g= 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-636--OQOfImDP0iRRlu1vp9QdA-1; Fri, 20 Oct 2023 11:58:36 -0400 X-MC-Unique: -OQOfImDP0iRRlu1vp9QdA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C98808C7EC1; Fri, 20 Oct 2023 15:58:35 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAB7D8CF2; Fri, 20 Oct 2023 15:58:32 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, xieyongji@bytedance.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, david.marchand@redhat.com, lulu@redhat.com Cc: Maxime Coquelin Subject: [PATCH v4 2/4] vduse: enable Virtio-net device type Date: Fri, 20 Oct 2023 17:58:17 +0200 Message-ID: <20231020155819.24000-3-maxime.coquelin@redhat.com> In-Reply-To: <20231020155819.24000-1-maxime.coquelin@redhat.com> References: <20231020155819.24000-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 08:59:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780290759271657556 X-GMAIL-MSGID: 1780290759271657556 This patch adds Virtio-net device type to the supported devices types. Initialization fails if the device does not support VIRTIO_F_VERSION_1 feature, in order to guarantee the configuration space is read-only. Acked-by: Jason Wang Reviewed-by: Xie Yongji Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 5b3879976b3d..73ad3b7efd8e 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -142,6 +142,7 @@ static struct workqueue_struct *vduse_irq_bound_wq; static u32 allowed_device_id[] = { VIRTIO_ID_BLOCK, + VIRTIO_ID_NET, }; static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa) @@ -1672,6 +1673,10 @@ static bool features_is_valid(struct vduse_dev_config *config) (config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))) return false; + if ((config->device_id == VIRTIO_ID_NET) && + !(config->features & (1ULL << VIRTIO_F_VERSION_1))) + return false; + return true; } @@ -2027,6 +2032,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = { static struct virtio_device_id id_table[] = { { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID }, + { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, { 0 }, }; From patchwork Fri Oct 20 15:58:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 156205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1157001vqb; Fri, 20 Oct 2023 09:01:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSTAnIyIB0YAUERm9mOJuxLOYMk/mmQp5CsKiVZpU1b/BZqgxYbWdQpmfEeOZwcN9Iw2f4 X-Received: by 2002:a17:90a:2f25:b0:27d:5a25:98aa with SMTP id s34-20020a17090a2f2500b0027d5a2598aamr2416119pjd.0.1697817704445; Fri, 20 Oct 2023 09:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697817704; cv=none; d=google.com; s=arc-20160816; b=jZX8npWKZlUoxKBk/yKjJqQ5xvuENrimeR1mCi6sRL2oiaGcwDG201yQzzGZAsa6W1 3EsLkZw4KVCphu+S6qE/2zMKODv5MiU3+VysXbQGjSMtnMmQMsTA2swwcnJ/Vs8F0hFI 3cSFxwWfa3QSUJkhbp8/UGbq8v9kbHlhTF6PJMynQ1orShZr+XoKi2pfVkheCdFFfD09 UWLfIwK+o90Esj9b8krVQZYIYNh2JjmtWX9Ec9HXyX+j3GYBcvcBm0IN8GNErCgrSa3w s52sn5BeAH6DGqql41NysjlQECO/LBzuzlMLTljeGfFmcZOQdq4EgCQ8e1/i1u2VGFuN SQmQ== 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=/YaH8GqSCmsbSQK65aeluJxBiMUQ9PtkPz8wZaXPjys=; fh=DW2mHD/f0kRN+01V+Z9as8p7OnC0swQlfBH91pgf6/A=; b=n+FPDFlo7QA6Z21YIXsWYm81aeff6XyyWCS7gccT7TIk1PI08OLyoDkGeVastcC2BB Kc8gFIQNm8WcPD2zQ83ZVcmKaPFxX39fp7Q7AYTJT4Jef08+c7qUnBmBAzk5YkcJzWSj pPtBmIL16xDXlaFGWIwT6fzIlWfTyR8Js9oLI5oUWzv9/sNZea1LWOZsbroCXP6JV/8X q5Ve6JGu4N4Za2LrO9L7ZU0o5jLo9atd97y4y7AVWLfmow3kw5fkEJmQHsTqKH5Q6sDH U760C7pmxkIDkV11UWzoVCKrYaDFxLk73zBx/73rzBaopUZcfl/y0GZ2B76XGsAQKfT9 sTyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="c/Gnpb2q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id oj11-20020a17090b4d8b00b00268a8e0cab3si4883237pjb.178.2023.10.20.09.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="c/Gnpb2q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D8004804755C; Fri, 20 Oct 2023 09:00:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377863AbjJTQAP (ORCPT + 26 others); Fri, 20 Oct 2023 12:00:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377839AbjJTQAK (ORCPT ); Fri, 20 Oct 2023 12:00:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 265C0D65 for ; Fri, 20 Oct 2023 08:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697817523; 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=/YaH8GqSCmsbSQK65aeluJxBiMUQ9PtkPz8wZaXPjys=; b=c/Gnpb2qABMhWmGPOGNosn8CVEAMwcDUV5f0c4OPYCuVZBcRWz5Pn4LfcXyngQC/E42twk PtOnKBpKaTTxlVvizWsgOOx0aNM5T6YGKWA68PGaAyFuH8mn+bYkJicKroisXFfg/R3niC zAhHcM9+Dd3+cubLQVIGk2p4b1mgSj0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-GcMYqtHEOs6LTSLRuNoADw-1; Fri, 20 Oct 2023 11:58:39 -0400 X-MC-Unique: GcMYqtHEOs6LTSLRuNoADw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F7E33C28647; Fri, 20 Oct 2023 15:58:39 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 219DB10828; Fri, 20 Oct 2023 15:58:35 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, xieyongji@bytedance.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, david.marchand@redhat.com, lulu@redhat.com Cc: Maxime Coquelin Subject: [PATCH v4 3/4] vduse: Temporarily disable control queue features Date: Fri, 20 Oct 2023 17:58:18 +0200 Message-ID: <20231020155819.24000-4-maxime.coquelin@redhat.com> In-Reply-To: <20231020155819.24000-1-maxime.coquelin@redhat.com> References: <20231020155819.24000-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:00:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780290896955662318 X-GMAIL-MSGID: 1780290896955662318 Virtio-net driver control queue implementation is not safe when used with VDUSE. If the VDUSE application does not reply to control queue messages, it currently ends up hanging the kernel thread sending this command. Some work is on-going to make the control queue implementation robust with VDUSE. Until it is completed, let's disable control virtqueue and features that depend on it. Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 73ad3b7efd8e..0243dee9cf0e 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "iova_domain.h" @@ -46,6 +47,30 @@ #define IRQ_UNBOUND -1 +#define VDUSE_NET_VALID_FEATURES_MASK \ + (BIT_ULL(VIRTIO_NET_F_CSUM) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | \ + BIT_ULL(VIRTIO_NET_F_MTU) | \ + BIT_ULL(VIRTIO_NET_F_MAC) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | \ + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | \ + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | \ + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | \ + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | \ + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | \ + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | \ + BIT_ULL(VIRTIO_NET_F_STATUS) | \ + BIT_ULL(VIRTIO_NET_F_HOST_USO) | \ + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | \ + BIT_ULL(VIRTIO_RING_F_INDIRECT_DESC) | \ + BIT_ULL(VIRTIO_RING_F_EVENT_IDX) | \ + BIT_ULL(VIRTIO_F_VERSION_1) | \ + BIT_ULL(VIRTIO_F_ACCESS_PLATFORM) | \ + BIT_ULL(VIRTIO_F_RING_PACKED) | \ + BIT_ULL(VIRTIO_F_IN_ORDER)) + struct vduse_virtqueue { u16 index; u16 num_max; @@ -1778,6 +1803,16 @@ static struct attribute *vduse_dev_attrs[] = { ATTRIBUTE_GROUPS(vduse_dev); +static void vduse_dev_features_filter(struct vduse_dev_config *config) +{ + /* + * Temporarily filter out virtio-net's control virtqueue and features + * that depend on it while CVQ is being made more robust for VDUSE. + */ + if (config->device_id == VIRTIO_ID_NET) + config->features &= VDUSE_NET_VALID_FEATURES_MASK; +} + static int vduse_create_dev(struct vduse_dev_config *config, void *config_buf, u64 api_version) { @@ -1793,6 +1828,8 @@ static int vduse_create_dev(struct vduse_dev_config *config, if (!dev) goto err; + vduse_dev_features_filter(config); + dev->api_version = api_version; dev->device_features = config->features; dev->device_id = config->device_id; From patchwork Fri Oct 20 15:58:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 156202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1155958vqb; Fri, 20 Oct 2023 09:00:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTG3YBmrJm4rNV/G3pkDX2OM0boIB6LBpOThfdSfkyAAOGkqMYlpqip22gC5Iqt0VwFZKL X-Received: by 2002:a05:6871:418a:b0:1bf:787c:411b with SMTP id lc10-20020a056871418a00b001bf787c411bmr3099004oab.10.1697817636442; Fri, 20 Oct 2023 09:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697817636; cv=none; d=google.com; s=arc-20160816; b=1KeMI53mI9lBzuJTrDRWWuMBSrvTr9LCGi/U5h7YAwGQJpQhANX+CGOvdKdDvkg8yd Df4hQBZWE/VKe6xVaknYC+3B7shC+BWN1ok3uL9bP28+QKusQklr7+5XEgaygj+WJ7ge PXNxz/gelMTWbjrTMxp918OjJ4hpfXvW2HMeHabKNKM1L0UKTgpPCnB+WnziYh0Rf9MD JbL2IPviBpA6wC0/VBiAz32kFLqXomkrPgG5Fci88sfchSTI3usFRVAN00sFOr7TruQH cJs7dTS61qphltCLWd/b61xpCur28WiZUkTvcsFEARCIsjahJvDv72oUgPVoxlYBMvzR pcKQ== 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=JMYHGo5Ykl6Wn0M8yf0bZNH2F3mIqZDULBM08KnlTxM=; fh=DW2mHD/f0kRN+01V+Z9as8p7OnC0swQlfBH91pgf6/A=; b=KrsCDUc0zwB2gmGAu/52wCNqxemU59Ed7jQDMa4jeSp4gmYosqatd4h3Yr80HZ/VSD V8RclB9pLbpOC+CWw/3nOv28PjWmQTUn7vQ82aYd9Ft6H5hoXYZRwJe0UgR8vQLEtg21 o/A8eArIwme1gB2+KpTkQCLxOeCUuOqm7d1QNMsbNnIKGN16GEeAwT5r5N8ik0ySAnui JDUXh6cEkVRKs4Y1FWAJOIlEvTKtaSrpKKi+/G1+3RbdOME1vFmgp/wVseVPi/ksSl8D N39UYLpMZeKn/IyvJcsPAzom8ZOcePMMjb4sDGj1pujxx/jrH/RcenRTKQOCSHMQlPXg 7U1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DEnqxbFL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a9-20020a634d09000000b0056336fb99aasi2146376pgb.850.2023.10.20.09.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 09:00:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DEnqxbFL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 86DB18107F32; Fri, 20 Oct 2023 09:00:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377874AbjJTQAS (ORCPT + 26 others); Fri, 20 Oct 2023 12:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377855AbjJTQAO (ORCPT ); Fri, 20 Oct 2023 12:00:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 013A1D6D for ; Fri, 20 Oct 2023 08:58:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697817527; 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=JMYHGo5Ykl6Wn0M8yf0bZNH2F3mIqZDULBM08KnlTxM=; b=DEnqxbFL3fn47ltofID7PhrZbHBT85peFvHjN/SEZDre4Yzz722WQWYsndVmp1xhrxi+20 Jg6yLptAcmp3ZfXz7t3OZb8sxbXGbFgayJK8Awn6CaLwhlK+2onTPV3FY+cXNgasU9VuyQ L/qJZdsz5LNUjzfLMneHEU+BF3JTQHg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-9ZumjUbuNZaU9A4VhoVF5g-1; Fri, 20 Oct 2023 11:58:43 -0400 X-MC-Unique: 9ZumjUbuNZaU9A4VhoVF5g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89CBB29AA2CE; Fri, 20 Oct 2023 15:58:42 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D33710828; Fri, 20 Oct 2023 15:58:39 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, xieyongji@bytedance.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, david.marchand@redhat.com, lulu@redhat.com Cc: Maxime Coquelin Subject: [PATCH v4 4/4] vduse: Add LSM hooks to check Virtio device type Date: Fri, 20 Oct 2023 17:58:19 +0200 Message-ID: <20231020155819.24000-5-maxime.coquelin@redhat.com> In-Reply-To: <20231020155819.24000-1-maxime.coquelin@redhat.com> References: <20231020155819.24000-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 20 Oct 2023 09:00:33 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780290826169797611 X-GMAIL-MSGID: 1780290826169797611 This patch introduces LSM hooks for devices creation, destruction and opening operations, checking the application is allowed to perform these operations for the Virtio device type. Signed-off-by: Maxime Coquelin --- drivers/vdpa/vdpa_user/vduse_dev.c | 12 +++++++ include/linux/lsm_hook_defs.h | 4 +++ include/linux/security.h | 15 ++++++++ security/security.c | 42 ++++++++++++++++++++++ security/selinux/hooks.c | 55 +++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 2 ++ 6 files changed, 130 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 0243dee9cf0e..ca64eac11ddb 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -8,6 +8,7 @@ * */ +#include "linux/security.h" #include #include #include @@ -1443,6 +1444,10 @@ static int vduse_dev_open(struct inode *inode, struct file *file) if (dev->connected) goto unlock; + ret = -EPERM; + if (security_vduse_dev_open(dev->device_id)) + goto unlock; + ret = 0; dev->connected = true; file->private_data = dev; @@ -1655,6 +1660,9 @@ static int vduse_destroy_dev(char *name) if (!dev) return -EINVAL; + if (security_vduse_dev_destroy(dev->device_id)) + return -EPERM; + mutex_lock(&dev->lock); if (dev->vdev || dev->connected) { mutex_unlock(&dev->lock); @@ -1819,6 +1827,10 @@ static int vduse_create_dev(struct vduse_dev_config *config, int ret; struct vduse_dev *dev; + ret = -EPERM; + if (security_vduse_dev_create(config->device_id)) + goto err; + ret = -EEXIST; if (vduse_find_dev(config->name)) goto err; diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index ac962c4cb44b..0b3999ab3264 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -419,3 +419,7 @@ LSM_HOOK(int, 0, uring_override_creds, const struct cred *new) LSM_HOOK(int, 0, uring_sqpoll, void) LSM_HOOK(int, 0, uring_cmd, struct io_uring_cmd *ioucmd) #endif /* CONFIG_IO_URING */ + +LSM_HOOK(int, 0, vduse_dev_create, u32 device_id) +LSM_HOOK(int, 0, vduse_dev_destroy, u32 device_id) +LSM_HOOK(int, 0, vduse_dev_open, u32 device_id) diff --git a/include/linux/security.h b/include/linux/security.h index 5f16eecde00b..a650c500f841 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -484,6 +484,9 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); int security_locked_down(enum lockdown_reason what); +int security_vduse_dev_create(u32 device_id); +int security_vduse_dev_destroy(u32 device_id); +int security_vduse_dev_open(u32 device_id); #else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data) @@ -1395,6 +1398,18 @@ static inline int security_locked_down(enum lockdown_reason what) { return 0; } +static inline int security_vduse_dev_create(u32 device_id) +{ + return 0; +} +static inline int security_vduse_dev_destroy(u32 device_id) +{ + return 0; +} +static inline int security_vduse_dev_open(u32 device_id) +{ + return 0; +} #endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) diff --git a/security/security.c b/security/security.c index 23b129d482a7..8d7d4d2eca0b 100644 --- a/security/security.c +++ b/security/security.c @@ -5337,3 +5337,45 @@ int security_uring_cmd(struct io_uring_cmd *ioucmd) return call_int_hook(uring_cmd, 0, ioucmd); } #endif /* CONFIG_IO_URING */ + +/** + * security_vduse_dev_create() - Check if a VDUSE device type creation is allowed + * @device_id: the Virtio device ID + * + * Check whether the Virtio device creation is allowed + * + * Return: Returns 0 if permission is granted. + */ +int security_vduse_dev_create(u32 device_id) +{ + return call_int_hook(vduse_dev_create, 0, device_id); +} +EXPORT_SYMBOL(security_vduse_dev_create); + +/** + * security_vduse_dev_destroy() - Check if a VDUSE device type destruction is allowed + * @device_id: the Virtio device ID + * + * Check whether the Virtio device destruction is allowed + * + * Return: Returns 0 if permission is granted. + */ +int security_vduse_dev_destroy(u32 device_id) +{ + return call_int_hook(vduse_dev_destroy, 0, device_id); +} +EXPORT_SYMBOL(security_vduse_dev_destroy); + +/** + * security_vduse_dev_open() - Check if a VDUSE device type opening is allowed + * @device_id: the Virtio device ID + * + * Check whether the Virtio device opening is allowed + * + * Return: Returns 0 if permission is granted. + */ +int security_vduse_dev_open(u32 device_id) +{ + return call_int_hook(vduse_dev_open, 0, device_id); +} +EXPORT_SYMBOL(security_vduse_dev_open); diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 2aa0e219d721..65d9262a37f7 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -21,6 +21,7 @@ * Copyright (C) 2016 Mellanox Technologies */ +#include "av_permissions.h" #include #include #include @@ -92,6 +93,7 @@ #include #include #include +#include #include "avc.h" #include "objsec.h" @@ -6950,6 +6952,56 @@ static int selinux_uring_cmd(struct io_uring_cmd *ioucmd) } #endif /* CONFIG_IO_URING */ +static int vduse_check_device_type(u32 sid, u32 device_id) +{ + u32 requested; + + if (device_id == VIRTIO_ID_NET) + requested = VDUSE__NET; + else if (device_id == VIRTIO_ID_BLOCK) + requested = VDUSE__BLOCK; + else + return -EINVAL; + + return avc_has_perm(sid, sid, SECCLASS_VDUSE, requested, NULL); +} + +static int selinux_vduse_dev_create(u32 device_id) +{ + u32 sid = current_sid(); + int ret; + + ret = avc_has_perm(sid, sid, SECCLASS_VDUSE, VDUSE__DEVCREATE, NULL); + if (ret) + return ret; + + return vduse_check_device_type(sid, device_id); +} + +static int selinux_vduse_dev_destroy(u32 device_id) +{ + u32 sid = current_sid(); + int ret; + + ret = avc_has_perm(sid, sid, SECCLASS_VDUSE, VDUSE__DEVDESTROY, NULL); + if (ret) + return ret; + + return vduse_check_device_type(sid, device_id); +} + +static int selinux_vduse_dev_open(u32 device_id) +{ + u32 sid = current_sid(); + int ret; + + ret = avc_has_perm(sid, sid, SECCLASS_VDUSE, VDUSE__DEVOPEN, NULL); + if (ret) + return ret; + + return vduse_check_device_type(sid, device_id); +} + /* * IMPORTANT NOTE: When adding new hooks, please be careful to keep this order: * 1. any hooks that don't belong to (2.) or (3.) below, @@ -7243,6 +7295,9 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = { #ifdef CONFIG_PERF_EVENTS LSM_HOOK_INIT(perf_event_alloc, selinux_perf_event_alloc), #endif + LSM_HOOK_INIT(vduse_dev_create, selinux_vduse_dev_create), + LSM_HOOK_INIT(vduse_dev_destroy, selinux_vduse_dev_destroy), + LSM_HOOK_INIT(vduse_dev_open, selinux_vduse_dev_open), }; static __init int selinux_init(void) diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index a3c380775d41..d3dc37fb03d4 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -256,6 +256,8 @@ const struct security_class_mapping secclass_map[] = { { "override_creds", "sqpoll", "cmd", NULL } }, { "user_namespace", { "create", NULL } }, + { "vduse", + { "devcreate", "devdestroy", "devopen", "net", "block", NULL} }, { NULL } };