From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.198.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796135958; b=dXd8isfEyHIGUhtDY2h5XV/N270s90F8tBKDTNj8XAKGGlh9Kc0fIYXeb1za3SxHSuao RA/a58MCoAvucYg317CNTJsgKAKnleeeX6Y1q6VH0xqZIGz/du5JxqoUxZ2GFxK0UCqYb DjF181UYOo7VvjDw3Qc4kUy2qY0AEKemqw++kU+SvhTy9rNtacUOmnU/OyclfBTOM8bUE gZO+yd8kCyqMgtECFcSmdgDdcJ3USKGjmkihCnIT+77YLkPl5NvkIL3L6HJSdJVVj9inv XY/bwWEJ0UlrGrOInsdC+3D2/J3t/6LRH0bnBQm7hQd0E+RHOvNq/bXhvA2IwF0b8Lw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135958; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=ExMsS5htYpCBrirn22X7JJAf5AdwAzOBOdwQF6+4pOg=; b=boHnd5BITNr2d3AYD/OzHNHGWl2BxOPD2WH+WRT324p3VsP6zHYOjaI/042Fb4ZwU4Ap 2pjszvlnyzcsfScJrXP/M+PN7FPm1Mf380ZrA8nGOqYOsUzg/20TaQJSd7rucQUSVl5kU FvPqNKTUmMNDOHUAznopDjF0D4qm62kKv28FhPUAF0+n7gXNSl3v/BDggT7Y+e+qSlzFf +xPZqcVO9XGK9tf7nNFtGEEoCjr3D4ZG+DwFPhO/a2XjB8DVnfYAmmqHXvgj/q0qik8vb 7j+foMRrbsYSATL4xzpZD1b9Ky13VuEgs99+WsZO1IBCbZKCcABHlIGecQmtCxGzZPw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ip2WKY1S; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.198.18 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010018.outbound.protection.outlook.com [40.93.198.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69D31606A320 for ; Tue, 1 Dec 2026 14:39:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 69D31606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ip2WKY1S ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xJtd2pq5HfaftmTMw+PwllEkEut4nyYSsf20fRZC4EqF8DBR4zXaLFYUJi49X35evaBGmG3k7ErH8s9giiVXbgZjrThiWTypCgWTkzgre1LpgU9NpGvFr3apVvQu5Bgv+sFnJeSl077f+f+xWVHEmORn//7Uz8exlyMPQTOecQFYrVbak8rbsHxJX2rBTObyohCGI/K62RRHUvcafBe+xTGHHGYo8G4upacVu8eAjrLDi56HB8I0Loy/WT5wjTSuiaAQhz42u5NBMfn1rKkpuHMTqCyXQrJ+1eCu6UU5qwnS/cgY0eo+MNQd9hBMOas8ZET/HCMiUCNbQsw7DjhGNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ExMsS5htYpCBrirn22X7JJAf5AdwAzOBOdwQF6+4pOg=; b=tRCFqMrRO//EIX/9TKLsUMOyq9C/7UMNu11g/gXlSHI8vyW70u3AN4Rq7QysbHKcGQkLybs2durMkjVqEX2G+yeFvF1ckXOEKGie7mUCJsPk+J2y8x6DKOn9uny/8bJ1oGtjGrFhc5c5PIUFwn4x7Q6rBo38N4Bv4mjIRWTobIedlJD/YyChqI4v3H/OmR/eS43B8rnwsGRVjuUltO84bRXpxbi4xCbkq3eufJvsydsDnG6oHLfbT6KVRvm3z+B9gk8eMOcgbOydT4p+7SNGjoYXF2/2M+kmiATZyDTt2ikXkFE0FJ2CcRZdpiKhk5Ncnnv6Bhv3W0KnMj88UmUrcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ExMsS5htYpCBrirn22X7JJAf5AdwAzOBOdwQF6+4pOg=; b=ip2WKY1StbCtIfe+4qCAbMhb8fd9BSKtPUlH0Jstq18UyEgidkrUppC11Jjfz8aLfz53jWnRxY/V2Bc/7E5pQJpw4SY048ax/OM0hb+Ttbq/t0WoLGhQSx9y9MWpfL0kb9fBmJWqMg+bckSowfnk3mlZ/o8reF7y/w+pesioX4//aFHdyIuFnBvWvS7U+PsZyzdhHDuKZowH0XNK/Rcu/AXAN5jjOrHJdf+IjtFDY52iBVOS52LPFEtntJLDNXy5I+e+04YRgdWzOYurKl3U53Wv/uXvM73r8XxefUR8m5ETTuq5XXYDBfmcOEW/H8uB1ryprCtU/3RuHOh745ZfBg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5505.namprd12.prod.outlook.com (2603:10b6:208:1ce::7) by PH7PR12MB6540.namprd12.prod.outlook.com (2603:10b6:510:213::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Tue, 1 Dec 2026 14:35:27 +0000 Received: from BL0PR12MB5505.namprd12.prod.outlook.com ([fe80::9329:96cf:507a:eb21]) by BL0PR12MB5505.namprd12.prod.outlook.com ([fe80::9329:96cf:507a:eb21%5]) with mapi id 15.21.0688.009; Tue, 1 Dec 2026 14:35:27 +0000 Message-ID: <0ce163bd-aca1-4ec6-8f72-8311d911ad9c@nvidia.com> Date: Tue, 1 Dec 2026 16:35:22 +0200 User-Agent: Mozilla Thunderbird Subject: Re: [net-next,v23,03/14] virtio: Add config_op for admin commands To: netdev-bot+sashiko@kernel.org Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, virtualization@lists.linux.dev, parav@nvidia.com, yohadt@nvidia.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, kuba@kernel.org, andrew+netdev@lunn.ch, edumazet@google.com, danielj@nvidia.com References: <20260831161109.2999926-4-shshitrit@nvidia.com> <178835473869.3394541.13020013369139989380@kernel.org> Content-Language: en-US From: Shahar Shitrit In-Reply-To: <178835473869.3394541.13020013369139989380@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: TL2P290CA0024.ISRP290.PROD.OUTLOOK.COM (2603:1096:950:3::8) To BL0PR12MB5505.namprd12.prod.outlook.com (2603:10b6:208:1ce::7) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR12MB5505:EE_|PH7PR12MB6540:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f0676aa-57fb-40c4-a3e7-08df4fb85748 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|23010399003|4143699003|11063799006|6133799003|261009223027099003|18002099003|22082099003|3023799007|261028144727099003|56012099006|261021123027099003|261026121527099003|261102123227099003|10067099003|261026140227099003|261021121427099003|261022075727099003|261022113327099003|261022105027099003; X-Microsoft-Antispam-Message-Info: kCaBHCEoycAhuFYY01LiH0MBXszaZ9Pe7rN0/+DYMwmHhyZGGPbtuX90My2SA6Slpd50k5s11GozeIdnMePAMKhV9iQmLCPJFTj3fiWdX05GDhjLOttjr2pkvbOkPN7YhQZdN0T28eZlFx+dIiPXnVjhlnNzT+rMm6o4oDTLmrstkEAmxeMO3v24dxTNWqrHrHLmbHCMvT0B1L7wdyMgO5pNGWfAhwubPC1vx/TKkC5AL+DUAPVmZWj2oHTwwmHxOoFPtP0z3eXwSOC5U8O5uv64AXoEMiYKl/SqcosUM4GTv4eumHTU1mhfH9FDylhD8xBG7G/yIm4UGRy1hhaEX4198CJEZQg/opiypZuutdHirDOwEmfqY2PYQh4rNbI4GrLbf/pWm+plcqdbo9b7aparu3coLegelSkF2U6+FAZCeMY1OZffjPDtUFsm0PWhGBp2UyA+m5Fl9YXGI4SF04gS87pcr9BDCuBhXcNfrT4WGEfDI9gtmzGdoHLWGvyYbOElYB72kk3hyzDCpRQ54WO1QdbKjZzI0z92DVcNn5xz6WCui82t705crBCMFnrT2rSZjo8X2fxnpgwGkVG3IEABm8CNIak7ZK+gTjUj5Uw8Fsjev4B/X5wBjVVfSL8JARvb9WfzmzarA1fdLhUKgs1NbS9I8HS5uGF178FAHiQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5505.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(23010399003)(4143699003)(11063799006)(6133799003)(261009223027099003)(18002099003)(22082099003)(3023799007)(261028144727099003)(56012099006)(261021123027099003)(261026121527099003)(261102123227099003)(10067099003)(261026140227099003)(261021121427099003)(261022075727099003)(261022113327099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aElrQmdReEhKdTArR25MUlZmY2F6L2grNjZyQTJqTmplRWpLcWsvSStleksz?= =?utf-8?B?K3UrVlpTUWZBNXNveW8velBqS3pvNFY4WWJUbDRFM1ljZDlTOUtkUUFZc2ZK?= =?utf-8?B?YnZJRTRiWm53MHlwdDNpbFBjV3RkZHVZcERkRTBUc2NENGxvekdsdkZ2T3B5?= =?utf-8?B?ZEtubXRTK3NLU2Z4Z1hxMG9HNERpQXNnY25DbGc5Q3JwR1RiK1dnRDNpQ1gz?= =?utf-8?B?VDFoU1FTMUNF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ZOHE2amdzYjhxelVMM0tu?= =?utf-8?B?VXU3RGVPd2JDS2lDcmxpck5vOVM0WnRMdkZGNk00R2dGUFB4Tjd2OVRmZXhY?= =?utf-8?B?YVUwUWNPRUlldzR2OFVlaFVlck1CMStKMVovY3BwZzZCNFh6eG5xVEV0SVlw?= =?utf-8?B?VnpjOTFwNDduNFZDd0tnSjd3OCt4eUxOcmprUFdaL3B2L1Y0Z21LYkNyNW1i?= =?utf-8?B?T2tGUFVXOTJiQlFsNkFDRlBxaklOMkRjQjBTSTVsSGhPZDVKRWNlb1RzajM0?= =?utf-8?B?RjlkS1JIdFllcnFzbzBmdTBIV1VrcUprZk5GMHBhU2tqdUU4NnlmUT09?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f0676aa-57fb-40c4-a3e7-08df4fb85748 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5505.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 14:35:26.9480 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: srPe4aaKyQmFpOlF+H4j6CBwmLAwOqsxk44vcYy6Q3qbYafSZ8k/vV63egIww9K7jYj38MgzuHx5HKjwbzXUog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6540 On 02/09/2026 16:12, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 2 potential > issue(s) to consider: > > Critical: 0 · High: 0 (3) · Medium: 1 · Low: 1 > > - [Medium] The newly published `->admin_cmd_exec` transport op has no > lifecycle precondition check or documentation:… > - [Low] The kernel-doc added for `@admin_cmd_exec` in > include/linux/virtio_config.h states no calling-context constraint,… > > Pre-existing issues: > - [High] Free-while-in-flight / use-after-free on the admin-command kick- > failure path. > - [High] The admin-command path accesses `admin_vq->info` with no > synchronization against admin-queue teardown, and the newly published… > - [High] `struct virtio_admin_cmd::result_sg_size`, now part of the > generic `->admin_cmd_exec` contract, is filled in… > > -- > > virtio: Add config_op for admin commands > > This adds a new optional admin_cmd_exec callback to struct > virtio_config_ops and points it at vp_modern_admin_cmd_exec() in both > modern virtio-pci config op tables, so that virtio device drivers can > issue admin commands through the transport. > > No Link: tags in the commit header. > > A few questions about the newly published op below. > >> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c >> index dab63b044a312..3b2515e29728a 100644 >> --- a/drivers/virtio/virtio_pci_modern.c >> +++ b/drivers/virtio/virtio_pci_modern.c >> @@ -1248,6 +1248,7 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = { >> .get_shm_region = vp_get_shm_region, >> .disable_vq_and_reset = vp_modern_disable_vq_and_reset, >> .enable_vq_after_reset = vp_modern_enable_vq_after_reset, >> + .admin_cmd_exec = vp_modern_admin_cmd_exec, >> }; > > [Severity: Medium] > Now that any bound driver can reach this path, is there anything that keeps > admin_vq.info valid at the entry point? virtqueue_exec_admin_cmd() starts > with: > > vq = admin_vq->info->vq; > if (!vq) > return -EIO; > > The guard tests the inner vq pointer, so it does not catch info == NULL. > The only precondition tested by vp_modern_admin_cmd_exec() is: > > if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ)) > return -EOPNOTSUPP; > > That feature bit is set by vp_finalize_features() before the driver's probe > runs and it stays set across del_vqs(), while vp_del_vq() in > virtio_pci_common.c does: > > if (vp_is_avq(vq->vdev, vq->index)) { > cancel_work_sync(&vp_dev->admin_vq.work); > vp_dev->admin_vq.info = NULL; > } > > vp_dev->del_vq(info); > kfree(info); > > So admin_vq.info is NULL before find_vqs() creates the admin queue, on the > find_vqs() error path, and after del_vqs(). Can a call made outside the > find_vqs()..del_vqs() window dereference NULL here? > > The virtio_net consumers added later in this series do appear to stay inside > that window, so this may not be reachable in-tree today. Would it still be > worth checking admin_vq->info and spelling out the required device/VQ state > in the new kernel-doc? Will document in the admin_cmd_exec kernel-doc: it must only be called after find_vqs() and before del_vqs(). No extra check, callers are expected to stay in that window. > > [Severity: High] > This isn't a bug introduced by this patch, but the kick-failure path in > virtqueue_exec_admin_cmd() looks like it leaves a descriptor in flight: > > mutex_lock(&admin_vq->lock); > ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL); > ... > if (!virtqueue_kick(vq)) > goto unlock_err; > ... > unlock_err: > mutex_unlock(&admin_vq->lock); > return -EIO; > > virtqueue_kick() returns false when the vring is broken, and > virtio_break_device() can be called asynchronously, for example from > virtio_pci_remove(): > > if (!pci_device_is_present(pci_dev)) > virtio_break_device(&vp_dev->vdev); > > so the state can change between the virtqueue_is_broken() pre-check and the > kick. The descriptor added by virtqueue_add_sgs() is not reclaimed on that > path, and vp_modern_admin_cmd_exec() then frees the buffers it published: > > err_cmd_exec: > kfree(va_hdr); > err_alloc: > kfree(va_status); > return ret; > > The token handed to virtqueue_add_sgs() is the caller's struct > virtio_admin_cmd, which goes out of scope when the caller returns. When the > following reset runs vp_modern_avq_cleanup(): > > while ((cmd = virtqueue_detach_unused_buf(vq))) { > cmd->ret = -EIO; > complete(&cmd->completion); > } > > does this write through a stale token belonging to another task's stack > frame, and can the device still DMA into the freed, device-writable > va_status? Should the error path detach the descriptor (or defer the frees) > before this op is exposed to more drivers? > > [Severity: High] > This is a pre-existing issue, but the admin queue accesses do not share a > lock with admin queue teardown, and this patch widens the set of contexts > that can submit commands without adding a serialization rule. > > Reader side, with no lock held: > > virtio_pci_modern.c:virtqueue_exec_admin_cmd() { > vq = admin_vq->info->vq; > if (!vq) > return -EIO; > } > > virtio_pci_modern.c:vp_modern_avq_cleanup() { > vq = vp_dev->admin_vq.info->vq; > if (!vq) > return; > > while ((cmd = virtqueue_detach_unused_buf(vq))) { > } > > vp_modern_avq_work() also reads admin_vq->info->vq before taking the mutex. > > Writer side, holding only vp_dev->lock for the list removal: > > virtio_pci_common.c:vp_del_vq() { > if (vp_is_avq(vq->vdev, vq->index)) { > cancel_work_sync(&vp_dev->admin_vq.work); > vp_dev->admin_vq.info = NULL; > } > > vp_dev->del_vq(info); > kfree(info); > } > > Since admin_vq->lock is not held by the cleanup or the teardown, can a > command submitted from an unrelated driver context concurrently with > del_vqs() or reset dereference NULL or the freed struct > virtio_pci_vq_info, and then operate on a destroyed vring? > > The concrete unsynchronized submitter today is the existing > virtio_pci_admin_* path used by virtio-vfio-pci, which reaches a PF admin > queue while the PF's virtio driver can be unbound independently. Should the > new kernel-doc carry an analogue of the @reset rule about not running in > parallel with virtqueues being added or removed? > Not introduced by this series, and the kick-failure path is unchanged here, so no fix in this series (like all other pre-existed bugs). >> >> static const struct virtio_config_ops virtio_pci_config_ops = { >> @@ -1268,6 +1269,7 @@ static const struct virtio_config_ops virtio_pci_config_ops = { >> .get_shm_region = vp_get_shm_region, >> .disable_vq_and_reset = vp_modern_disable_vq_and_reset, >> .enable_vq_after_reset = vp_modern_enable_vq_after_reset, >> + .admin_cmd_exec = vp_modern_admin_cmd_exec, >> }; >> >> /* the PCI probing function */ >> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h >> index 69f84ea85d71a..e36a32e0a20c8 100644 >> --- a/include/linux/virtio_config.h >> +++ b/include/linux/virtio_config.h >> @@ -108,6 +108,10 @@ struct virtqueue_info { >> * Returns 0 on success or error status >> * If disable_vq_and_reset is set, then enable_vq_after_reset must also be >> * set. >> + * @admin_cmd_exec: Execute an admin VQ command (optional). >> + * vdev: the virtio_device >> + * cmd: the command to execute >> + * Returns 0 on success or error status > > [Severity: Low] > Could this kernel-doc also state the calling context? The implementation > sleeps in several places: two kzalloc_obj() GFP_KERNEL allocations in > vp_modern_admin_cmd_exec(), and in virtqueue_exec_admin_cmd(): > > mutex_lock(&admin_vq->lock); > ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL); > ... > wait_for_completion(&cmd->completion); > > The wait has no timeout and is only woken by vp_modern_avq_work() or by > vp_modern_avq_cleanup() on reset. > > The header of this struct is otherwise explicit about context, for example > that @get/@set, @get_status/@set_status and @get_features/@finalize_features > are not safe from atomic context, and that a device must not be reset from > its vq or config callbacks. > > No in-tree caller violates this today. Would it help to note that > admin_cmd_exec may sleep, must be called from process context, and can block > until the device completes the command or the device is reset? > > [Severity: High] > This is a pre-existing issue, but the cmd->result_sg_size field that this > contract now exposes to arbitrary drivers is filled straight from the > device-written used ring length. In vp_modern_avq_work(): > > while ((cmd = virtqueue_get_buf(vq, &len))) { > if (len < status_size) > cmd->result_sg_size = 0; > else > cmd->result_sg_size = len - status_size; > > virtio_ring does not clamp that length against the posted buffer; in > virtqueue_get_buf_ctx_split() and virtqueue_get_buf_ctx_packed() only the > descriptor id is range-checked while the length is taken verbatim: > > *len = vring_read_split_used_len(vq, last_used); > > Is result_sg_size therefore fully device-controlled and able to exceed the > caller's result scatterlist? The existing consumer already trusts it: > virtio_pci_admin_dev_parts_get() does *res_size = cmd.result_sg_size; and > drivers/vfio/pci/virtio/migrate.c does buf->length = res_size; for a buffer > whose real size is ctx_size, which the migration file then reads from. > > Should the transport clamp result_sg_size to the total length of the > caller's result_sg before completing the command, and should the new > kernel-doc say that this field is untrusted device input? > >> */ >> struct virtio_config_ops { >> void (*get)(struct virtio_device *vdev, unsigned offset, >> @@ -137,6 +141,8 @@ struct virtio_config_ops { >> struct virtio_shm_region *region, u8 id); >> int (*disable_vq_and_reset)(struct virtqueue *vq); >> int (*enable_vq_after_reset)(struct virtqueue *vq); >> + int (*admin_cmd_exec)(struct virtio_device *vdev, >> + struct virtio_admin_cmd *cmd); >> }; >