From patchwork Tue Mar 12 22:27:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1911408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fr1aX4Zv; 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 4TvT0W5QSJz1ydl for ; Wed, 13 Mar 2024 09:32:11 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkAb7-0008El-96; Tue, 12 Mar 2024 18:27:49 -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 1rkAav-0007s6-PD for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkAat-0004Qv-Sh for qemu-devel@nongnu.org; Tue, 12 Mar 2024 18:27:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710282455; 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: in-reply-to:in-reply-to:references:references; bh=vE++ACnpq2l4kPgdISccW6Kl+44m7WS4zYEt6708zkc=; b=fr1aX4ZvVmT1vdatnVgL96aJmnzYGr+5omFSsKV6Z56VMAt1PURSJmYYs/BLyNEmYpRrW5 8vA5fooHL2AZmsq/MGR256d5ZNBACTCxWkyErhbrGpg4hgUyF5matE6kBCbCR9lxkdAF2K v/8IzxetDy0a9vzKI9aQ0fiKZ5AXx48= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-AmoocxrMME2I7yw4VuCcYg-1; Tue, 12 Mar 2024 18:27:34 -0400 X-MC-Unique: AmoocxrMME2I7yw4VuCcYg-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a45acc7f07cso26151466b.2 for ; Tue, 12 Mar 2024 15:27:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710282453; x=1710887253; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vE++ACnpq2l4kPgdISccW6Kl+44m7WS4zYEt6708zkc=; b=quCSRddzy+cJ8mu+UMZx3crgZhjQyOqsnkh67sEb3D53/SyznKFWUx9gaV3xikqTvC EoMCzE35bmLsAT/dwmEl1MJfm27aEN4VlA695yxyGcunRozfT4grdltYMLV4P/fI+Xcq QryX6LXacolOT9HPcORT90LT+vNyWjR3+yf7jKmz1xoZ3HIhTiNSJoM9OVPFX4Axqurj Gclx0LW3GnrqoKGXasnuyPYWc1mxKes5oFOHxqjoTCY38PGeS9yewFTT/iiadx25beSK shD1go0vMNjrcjuWUTSMlzlH1WTYNmhcO+5SBjKGkR5YSDBqxJWlBw+EB15n2LmFjEE9 p66Q== X-Gm-Message-State: AOJu0YxMdPv1xVRvMomitwRL5WnRk+DcF52oButbpTFjjVsB+K2cbnF4 tyhfBoMeA5UPZXhU8snJYeaEge49X8GQwcl07IpGxr+AutVQGJrSuSpbaEEgkakrUHZFahP9bVD PJeRd9xkyclEOt32jB95cJMQ9QslA7zM5T78z33Wa5EK3Ly0rf7BGq2eAy2YhcnrFlppS837Zdm 0P8SpR5xce+6c5gVEXer9hgUrDCmz6S5xJ X-Received: by 2002:a17:906:11da:b0:a44:dc35:df19 with SMTP id o26-20020a17090611da00b00a44dc35df19mr3401125eja.67.1710282452826; Tue, 12 Mar 2024 15:27:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFShTwndBcRkeoht7ojHvVlKJpYFRIl0GU53PrRq7iZx6RC6WF5++L2bf/eldEvFoH2w3HqWw== X-Received: by 2002:a17:906:11da:b0:a44:dc35:df19 with SMTP id o26-20020a17090611da00b00a44dc35df19mr3401105eja.67.1710282452350; Tue, 12 Mar 2024 15:27:32 -0700 (PDT) Received: from redhat.com ([2.52.134.16]) by smtp.gmail.com with ESMTPSA id s19-20020a170906501300b00a433f470cf1sm4252067ejj.138.2024.03.12.15.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 15:27:31 -0700 (PDT) Date: Tue, 12 Mar 2024 18:27:29 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Zhao Liu , Markus Armbruster , Alex Williamson , =?utf-8?q?C=C3=A9dric?= Le Goater Subject: [PULL 38/68] hw/vfio/iommufd: Fix missing ERRP_GUARD() in iommufd_cdev_getfd() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 From: Zhao Liu As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD(): * = Why, when and how to use ERRP_GUARD() = * * Without ERRP_GUARD(), use of the @errp parameter is restricted: * - It must not be dereferenced, because it may be null. ... * ERRP_GUARD() lifts these restrictions. * * To use ERRP_GUARD(), add it right at the beginning of the function. * @errp can then be used without worrying about the argument being * NULL or &error_fatal. * * Using it when it's not needed is safe, but please avoid cluttering * the source with useless code. But in iommufd_cdev_getfd(), @errp is dereferenced without ERRP_GUARD(): if (*errp) { error_prepend(errp, VFIO_MSG_PREFIX, path); } Currently, since vfio_attach_device() - the caller of iommufd_cdev_getfd() - is always called in DeviceClass.realize() context and doesn't get the NULL @errp parameter, iommufd_cdev_getfd() hasn't triggered the bug that dereferencing the NULL @errp. To follow the requirement of @errp, add missing ERRP_GUARD() in iommufd_cdev_getfd(). Suggested-by: Markus Armbruster Signed-off-by: Zhao Liu Reviewed-by: Markus Armbruster Message-Id: <20240223085653.1255438-7-zhao1.liu@linux.intel.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/vfio/iommufd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 9bfddc1360..7baf49e6ee 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -116,6 +116,7 @@ static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev) static int iommufd_cdev_getfd(const char *sysfs_path, Error **errp) { + ERRP_GUARD(); long int ret = -ENOTTY; char *path, *vfio_dev_path = NULL, *vfio_path = NULL; DIR *dir = NULL;