From nobody Mon Dec 15 22:04:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; t=1765724391; cv=none; d=zohomail.com; s=zohoarc; b=HHYiy3BG38UF6nQnHLNS1f9kIT3TwH0FfQXLMydHCHkfzKsfeG/ko2//HKCG5L8+3RywDwiDD63OSgtHSTQFODFpB1GMLNXOaB7KqrwgJ/f0WGsOJcPAJvxTl22SbmdhkbTda9Dt7DlbSYM7ZQX6cdkrCUrRCUBQOIHyvZKXfiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765724391; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iggrNO2Dxvo63J6+OiyErUibEGZbf8duM3p5uId6vEI=; b=TBpUT+yAJUZPomXprYnF0NLkXEstcFcUSZG2AZBFU2DoTr4oZehG7uscvjkNZ1Z6wTz070aYM1pB7gjYkcVBfrRk2CBAEqY01oxocABYxhb9i4GQXkCq4qS6klADAs2+bgqJ0qHwJDPMRcr+AkQoeQGXOn06HojyHOapaGhY+VU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765724390852473.961431345071; Sun, 14 Dec 2025 06:59:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vUnZE-0003Au-09; Sun, 14 Dec 2025 09:59:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vUi7m-0001zj-BB for qemu-devel@nongnu.org; Sun, 14 Dec 2025 04:10:43 -0500 Received: from out-174.mta0.migadu.com ([2001:41d0:1004:224b::ae]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vUi7j-00038u-Kf for qemu-devel@nongnu.org; Sun, 14 Dec 2025 04:10:42 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765703430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iggrNO2Dxvo63J6+OiyErUibEGZbf8duM3p5uId6vEI=; b=s618xGAmYnw0cT9pZlPoJHMMHAYVuh24aeCQdmwkbNRiZAqw8RAG9+PWI/AWLqnt69eLl4 JpNPddKfVOWusUzavyIpNp4JyN9B1JpqTJXaffSShjPs7WqZKWrybi7XTTrVfqiaglQaU0 z9uR1irP/4+y9JC4OU3B+uSnaGeDO8Y= From: zhenwei pi To: qemu-devel@nongnu.org Cc: mst@redhat.com, arei.gonglei@huawei.com, nakamurajames123@gmail.com, qemu-security@nongnu.org, mcascell@redhat.com, zhenwei pi Subject: [PATCH 1/2] hw/virtio/virtio-crypto: verify asym request size Date: Sun, 14 Dec 2025 17:09:38 +0800 Message-ID: <20251214090939.408436-2-zhenwei.pi@linux.dev> In-Reply-To: <20251214090939.408436-1-zhenwei.pi@linux.dev> References: <20251214090939.408436-1-zhenwei.pi@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:41d0:1004:224b::ae; envelope-from=zhenwei.pi@linux.dev; helo=out-174.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 14 Dec 2025 09:59:22 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.dev) X-ZM-MESSAGEID: 1765724393330158500 The total lenght of request is limited by cryptodev config, verify it to avoid unexpected request from guest. Fixes: 0e660a6f90a ("crypto: Introduce RSA algorithm") Reported-by: AM =EC=9D=B4=EC=9E=AC=EC=98=81 Signed-off-by: zhenwei pi --- hw/virtio/virtio-crypto.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 517f2089c5..94dbf9d92d 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -767,11 +767,18 @@ virtio_crypto_handle_asym_req(VirtIOCrypto *vcrypto, uint32_t len; uint8_t *src =3D NULL; uint8_t *dst =3D NULL; + uint64_t max_len; =20 asym_op_info =3D g_new0(CryptoDevBackendAsymOpInfo, 1); src_len =3D ldl_le_p(&req->para.src_data_len); dst_len =3D ldl_le_p(&req->para.dst_data_len); =20 + max_len =3D src_len + dst_len; + if (unlikely(max_len > vcrypto->conf.max_size)) { + virtio_error(vdev, "virtio-crypto asym too big length"); + goto err; + } + if (src_len > 0) { src =3D g_malloc0(src_len); len =3D iov_to_buf(iov, out_num, 0, src, src_len); --=20 2.43.0 From nobody Mon Dec 15 22:04:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.dev ARC-Seal: i=1; a=rsa-sha256; t=1765724405; cv=none; d=zohomail.com; s=zohoarc; b=DXbRrgJaIfugeISgS95ylwFQ8Awzoycu07wkV6kbpi+cWCXT0ezkAfrluSja6bGODrEtvMlvQdjow6aywYjPca2Z7Q5mSiBOAcVCuSrqgksGOsGbFA5mgbUSqHV/QMSjHhQnG++n1x7Cq80AbhsVKs1yBYxGk9rG4PwHNX7Ql8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765724405; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YjccH9cASOhv8Xqy6ggla8HIcFFiQvPnmz2kFeaGjjw=; b=Us7EhWT3e0RGHKQvQ0tvytIFGLy3M2NKJEU8i3VgKMXm1DnrV3a6tXJ+IH2aVR8OtV6ZSrYXhWOrrtnuPAbwW42JH19kfymnLcQb/aDkOBkuAuFI/j6fRpkRq/wvjjfS8AJDbgAZDR0/HNzbgKN+deGhRA+PRvIlp3JQb4Cl0ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1765724404951603.8567278497954; Sun, 14 Dec 2025 07:00:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vUnZE-0003BP-Q3; Sun, 14 Dec 2025 09:59:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vUi7n-000201-Nd for qemu-devel@nongnu.org; Sun, 14 Dec 2025 04:10:43 -0500 Received: from out-170.mta0.migadu.com ([91.218.175.170]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vUi7k-00039E-NQ for qemu-devel@nongnu.org; Sun, 14 Dec 2025 04:10:43 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765703438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YjccH9cASOhv8Xqy6ggla8HIcFFiQvPnmz2kFeaGjjw=; b=GE/rM1eyP6iMkeIurBP06z4wXr4YKlSPOEicEC6ZRHNO5eEFG6K+R8+cgYlNEcJdyh9Z4m xru7Jt2798iZsef0DV5sVSmW7eCuM0UZQ3Gk9TJD9VmDka8l2JiMTiRgN1JHD7Xz3LwkXp UD/rczU4Z8XaZIpWs/rzCILIMYM++NE= From: zhenwei pi To: qemu-devel@nongnu.org Cc: mst@redhat.com, arei.gonglei@huawei.com, nakamurajames123@gmail.com, qemu-security@nongnu.org, mcascell@redhat.com, zhenwei pi Subject: [PATCH 2/2] cryptodev-builtin: Limit the maximum size Date: Sun, 14 Dec 2025 17:09:39 +0800 Message-ID: <20251214090939.408436-3-zhenwei.pi@linux.dev> In-Reply-To: <20251214090939.408436-1-zhenwei.pi@linux.dev> References: <20251214090939.408436-1-zhenwei.pi@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=91.218.175.170; envelope-from=zhenwei.pi@linux.dev; helo=out-170.mta0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 14 Dec 2025 09:59:22 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.dev) X-ZM-MESSAGEID: 1765724406325158500 This backend driver is used for demonstration purposes only, unlimited size leads QEMU OOM. Fixes: 1653a5f3fc7 ("cryptodev: introduce a new cryptodev backend") Reported-by: AM =EC=9D=B4=EC=9E=AC=EC=98=81 Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 0414c01e06..55a3fbd27b 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -53,6 +53,8 @@ typedef struct CryptoDevBackendBuiltinSession { =20 #define CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN 512 #define CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN 64 +/* demonstration purposes only, use a limited size to avoid QEMU OOM */ +#define CRYPTODEV_BUITLIN_MAX_REQUEST_SIZE (1024 * 1024) =20 struct CryptoDevBackendBuiltin { CryptoDevBackend parent_obj; @@ -98,12 +100,7 @@ static void cryptodev_builtin_init( 1u << QCRYPTODEV_BACKEND_SERVICE_TYPE_MAC; backend->conf.cipher_algo_l =3D 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo =3D 1u << VIRTIO_CRYPTO_HASH_SHA1; - /* - * Set the Maximum length of crypto request. - * Why this value? Just avoid to overflow when - * memory allocation for each crypto request. - */ - backend->conf.max_size =3D LONG_MAX - sizeof(CryptoDevBackendOpInfo); + backend->conf.max_size =3D CRYPTODEV_BUITLIN_MAX_REQUEST_SIZE; backend->conf.max_cipher_key_len =3D CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_= LEN; backend->conf.max_auth_key_len =3D CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; cryptodev_builtin_init_akcipher(backend); --=20 2.43.0