From nobody Sun Feb 8 04:11:40 2026 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9C023054EF for ; Fri, 5 Dec 2025 11:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764934761; cv=none; b=jVFlbgMieeZ3qHnGqeEVWRUHffdu+J2vXHhneUJqpjxsrcyXjrA9xccnCo6jkE+Ch5yq/NeM8WChnnQKXqhrEmMqtOMNRqimKdcrWgbqvEchshrUQNx6eOhIfFT4ZxDbyOEXykId+sgwB6ecRK2UiyIGSs9XT4LXP5PxiLwxxqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764934761; c=relaxed/simple; bh=QqH8/pjRCcGh0Jyr6tcZ3HotdYoJ1HgZDkQeP8IceDk=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=hfLO8fqu+UBtkUCKblyY/vjIWs8MTWgckr2p9kHqv6/ZvAkwl9tee+8HOftZ6/VNR3jVjXqCnm/3i4DhdUWfC1S4+Rh2moCEUY1+5CreSRFosxDVs/UKhkmFlx6IfG0ZAwHI45XY4D3SDd3gUIWqlAR2+g6xhKLylNPKkIhVWg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ICG9sMR8; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ICG9sMR8" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-477632d9326so14162295e9.1 for ; Fri, 05 Dec 2025 03:39:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764934756; x=1765539556; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ydvHPuR/TEWjlqHSyc+IuhV3845FKKl2OTvoX5xFzHs=; b=ICG9sMR8JnkA+elVgSM2l6ApOru1cWYXHe00gVb3FdUMkDOiC0ZikjRSWfQForHPDv boYF7OzPI6ZJS8uIPDGDfN2h/ZyawiuL3v5QRtbxvS02PGWnLMkwT+C/52tRIwZjqJCD ip5cm3tYVvWVRlG/tEvBsMi6+MUKcpjMHxIegnwtPsTGHjxAlE2TIqB6GuXk9d1gFCZV RBlox2NPs8X5bMrt/17ELOdeo62PLNul8bfoO33+rn1BPe+IyBdKz0LGxtZQe9u/W6q0 XqUjDCn0df5TvsnRq2RBGN5UR2/Ou8l7z3R39irV/tyvmhLnExjWhoyNnubBSxjxZvFr PhQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764934756; x=1765539556; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ydvHPuR/TEWjlqHSyc+IuhV3845FKKl2OTvoX5xFzHs=; b=GceAMd4BgJa2+937N2Foxu55X3Dx9Edbd5n+2932JCa8BZ3yIJ2B0EENi5vgnIKtlD rNti4nekXG3mdtm+YfQRRNgVQm/C0C2JbzmTOKwh0g5jl+fTfPekmS7xyEaoJfVbYW00 uymeKR0ccHOBswjsdo0oV+5JWYgwJgvJkIRocHM7xylcUWaWkrFv9sV3wzpZ6NPvjdoD iWVOvrJyT22JFs9PtVPwM6JYwBkaWV2xl/tR6Mlydo0ds6ojYw40UnGdNKZLgdhvM5oM yPUfwrwsVza5B24uSCpTbyunDL7m6KsxTDF3ppLXh1ixjMeaRSNu+KOm3ejb0pv/kjwN NUXA== X-Forwarded-Encrypted: i=1; AJvYcCU2azchdY8P8i13YtsoNJzU1P9+0OEXfxDh+YxaqIvQ+/+fx9pOJCitBm/KyBKSIrdPstWoY21jpqHTz80=@vger.kernel.org X-Gm-Message-State: AOJu0YyBkzUE9gtdm97TIV8b3an4HtmTcejRtzqCbIxCNZFa041Fd7s2 PX6NdXf/Zn0xUbpSj+iT9vfZp9VXuiYZ2nBQR3zlZ8rEl/b0xfZ3C4+Zkuaw8GpQOGw= X-Gm-Gg: ASbGnctL2soHJChgvXvsZvHeAzLdz8aHX+Ws+LybcJVcGfuwO3GZyNPn9i9bS76iBA7 EmRqohajPa7132wv9ntxBX5nuuuXAt5/+cdRMOalTx1LzonKooAxpd1GeUUiYxM6GppozVL9Vd5 z74CwvYGQFx4ZTxWm5TzG6U8wh6mWvbPlRcajLnSfYc7UHIkbwSIIoO+5HZ4iq8Jmfs66Aets+K ugmeaRa+YElx/lyp+UuxUiPEJ7vKF22ogFTysMq17zldFr2RylZjFMK5oblJAZAniZyTGRB7CzB sBeTUrt0PwCSsypAjdT4mym8Uttb3vWMLkfbrNxwM2SaQVxtVdEQB0jiVMPOSuxvKSDVvdbny9v XKno/EAaqAipZmNht/C1S/xCk7zDPiH49SgcqL1lUSoCpt96jbC3qzuw6gHQ7MyRmmy9RZuLbfi q3PQrvTvXfwTRJXfI5c4bq9JuYFWs= X-Google-Smtp-Source: AGHT+IF/vwM9KOmX570wAov4Xy6x0tD+87+iHCXLimHTetQ/1oLM41jUaLHyTjztyr8/nNeI54dvbg== X-Received: by 2002:a05:600c:c8c:b0:477:7bca:8b2b with SMTP id 5b1f17b1804b1-4792aef7050mr121690165e9.15.1764934755224; Fri, 05 Dec 2025 03:39:15 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-42f7d353f8bsm8501158f8f.43.2025.12.05.03.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Dec 2025 03:39:14 -0800 (PST) Date: Fri, 5 Dec 2025 14:39:10 +0300 From: Dan Carpenter To: =?utf-8?Q?Micha=C5=82?= Winiarski Cc: Jason Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , Rodrigo Vivi , kvm@vger.kernel.org, intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH next] vfio/xe: Fix use after free in xe_vfio_pci_alloc_file() Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This code frees "migf" and then dereferences it on the next line to get the error code. Preserve the error code before freeing the pointer. Fixes: 2e38c50ae492 ("vfio/xe: Add device specific vfio_pci driver variant = for Intel graphics") Signed-off-by: Dan Carpenter Reviewed-by: Kevin Tian Reviewed-by: Michal Wajdeczko --- drivers/vfio/pci/xe/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/xe/main.c b/drivers/vfio/pci/xe/main.c index 0156b53c678b..8e1595e00e18 100644 --- a/drivers/vfio/pci/xe/main.c +++ b/drivers/vfio/pci/xe/main.c @@ -250,6 +250,7 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *= xe_vdev, struct xe_vfio_pci_migration_file *migf; const struct file_operations *fops; int flags; + int ret; =20 migf =3D kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); if (!migf) @@ -259,8 +260,9 @@ xe_vfio_pci_alloc_file(struct xe_vfio_pci_core_device *= xe_vdev, flags =3D type =3D=3D XE_VFIO_FILE_SAVE ? O_RDONLY : O_WRONLY; migf->filp =3D anon_inode_getfile("xe_vfio_mig", fops, migf, flags); if (IS_ERR(migf->filp)) { + ret =3D PTR_ERR(migf->filp); kfree(migf); - return ERR_CAST(migf->filp); + return ERR_PTR(ret); } =20 mutex_init(&migf->lock); --=20 2.51.0