From patchwork Thu Apr 4 19:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1919926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=biuIz3Lb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V9WXC3cMPz1yYf for ; Fri, 5 Apr 2024 06:14:51 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsSXJ-000660-Vw; Thu, 04 Apr 2024 15:14:10 -0400 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 1rsSXJ-00065q-FN for qemu-devel@nongnu.org; Thu, 04 Apr 2024 15:14:09 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rsSXH-0005bK-VU for qemu-devel@nongnu.org; Thu, 04 Apr 2024 15:14:09 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-56829f41f81so1939197a12.2 for ; Thu, 04 Apr 2024 12:14:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712258046; x=1712862846; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Akez/1J4Qb6iNF6NCgcGNV+l9m0ULLqhTgwyXKIYR5w=; b=biuIz3Lb7k3OiGzK1KJnKEVvgp+6unv2z7LZBcXfRlR9x+vzOju/3IAtritJhOANW/ sMTxr9CYV2tTYf/ndxx/+FfOXxWyN0OPdXi/n7XjtV+EF2KcZ2gf4XF5dV1UKgFGOVxq JWtLIFgFhHAzTddAvDYXmreSD5q4R8A8QzPcUJLe0JwEqvePypnzoHx4ht8RE6MGcjuq kjy25UM8nEmuFyft0zHNku1X0rcv5A+QO+9a/KtNTC5Rq1bABwC6/3Bx3IKyEnz6JmZ8 x+Rg4PuHap5WcN78KUDmGJWP1i7eEN2e+lKLJgqI7DIuQE3HyQVKGmVRKolLkI6I7g7r W4pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712258046; x=1712862846; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Akez/1J4Qb6iNF6NCgcGNV+l9m0ULLqhTgwyXKIYR5w=; b=EY0GoxafG6E+tn+ivC/4F3gnpFLoMIOr2vtj6VkufET2SkYZrLHmRUxEDxKxnsDKRX lMDqHduZyiJU1hiruKe1j1hL/YOSJfgHoM9NtFrdEy16upkwdIjo0KwqhFV8ie9jeOz3 BfJli2tdoayo3pFp4NXZ4sF2Omi1OA91ixP6ysAXgH1wXQwm39D1OgpUTrXsY8XK5cFH k5G9XymdQqzprCtSNxAK4/cTS2Rh3V3DgcIa3IZM+gMDWY4ZHyYqigLipv9+3Ih/+BwH Gp8tlBPRKKK/tdCaZ8oiqT/O9Kza/4RC/IlH6dbu5ppZp/N3M6b75LV7RDkNZ++UvPr9 n2rw== X-Gm-Message-State: AOJu0Yzr8qYQ5cd1bSZ99wpP38ZAWK3Hm6WT8v+ddr5++dSfE+s32HkQ gdeAbKhDsavdcgDe1LDuBIUUXY2F15NQy2Ba2ttFrrvHznQCHqAhuBcH+s4y34QXsIa6xq0HmGd 3 X-Google-Smtp-Source: AGHT+IGLoMb8t7r7GYKSxyW4HkphOCxA+5iDuPIbupfj+qcbb7fGAayvTK+8ByhvNfY46zdM8c7Ojw== X-Received: by 2002:a17:906:ca04:b0:a4e:8508:d807 with SMTP id jt4-20020a170906ca0400b00a4e8508d807mr2252811ejb.0.1712258046324; Thu, 04 Apr 2024 12:14:06 -0700 (PDT) Received: from m1x-phil.lan ([176.187.216.111]) by smtp.gmail.com with ESMTPSA id l3-20020a1709067d4300b00a466af74ef2sm9352805ejp.2.2024.04.04.12.14.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 04 Apr 2024 12:14:05 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Amit Shah , "Michael S. Tsirkin" , Alexander Bulekov , "Gonglei (Arei)" , =?utf-8?q?Marc-Andr=C3=A9_Lurea?= =?utf-8?q?u?= , Laurent Vivier , Mauro Matteo Cascella , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH-for-9.0 4/4] hw/virtio/virtio-crypto: Protect from DMA re-entrancy bugs Date: Thu, 4 Apr 2024 21:13:39 +0200 Message-ID: <20240404191339.5688-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240404191339.5688-1-philmd@linaro.org> References: <20240404191339.5688-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=philmd@linaro.org; helo=mail-ed1-x52b.google.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Replace qemu_bh_new_guarded() by virtio_bh_new_guarded() so the bus and device use the same guard. Otherwise the DMA-reentrancy protection can be bypassed. Cc: qemu-stable@nongnu.org Suggested-by: Alexander Bulekov Signed-off-by: Philippe Mathieu-Daudé --- hw/virtio/virtio-crypto.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index fe1313f2ad..ac1b67d1fb 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -1080,8 +1080,8 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp) vcrypto->vqs[i].dataq = virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_bh); vcrypto->vqs[i].dataq_bh = - qemu_bh_new_guarded(virtio_crypto_dataq_bh, &vcrypto->vqs[i], - &dev->mem_reentrancy_guard); + virtio_bh_new_guarded(vdev, virtio_crypto_dataq_bh, + &vcrypto->vqs[i]); vcrypto->vqs[i].vcrypto = vcrypto; }