From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 D4D493F787F for ; Fri, 7 Aug 2026 10:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786096841; cv=none; b=q/PQlLNLdbDAZVz4WpcBddBsYARVA5+xEEXg5fYQsWh6x3sgOwgp3Ztg1J0ZpyIo3VZnhfr/vF+QjF0hTFq+e8iMX79LzMEj8NijSNz1lEhTx65wFuwFVE+eUICgmwieE2tkFw1zv1EWV/PhXU3LMOhjwgitU7qv29X/XeUIe3U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786096841; c=relaxed/simple; bh=WE8i65b9LC7lL9iQ5/lEghqFQeb0neL/8MWHHX2SAPE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cm7LG1jKJg2n6gKSxwoZ3Q6ICq+jVhjtn1xCkhstDbkbJbHdB7aacCTUCJp/sLGIZbkFnPhIp7h+Iwzv/WE6U4aYldlmcw25+xhOycebQgWOF9xfcyGcPJlXFnYmbuZlQhbupRlNaGTdEoeGPFPGSaelsIjaxgT0WYKXNtxKEpM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Pm1SLs9V; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pm1SLs9V" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2cca0c5799eso30956305ad.0 for ; Fri, 07 Aug 2026 03:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786096839; x=1786701639; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=QQZgcdlI2EieaifCVQjJlrIUWRZzFN6DkbdW2khQ3hg=; b=Pm1SLs9Vov4ax6nEhgu4CzxOZs+MSR7P3WXTpdz1PFwe917a57sFkh67hXtDvoqJj7 UiKLoOulcmT1bPsSkAhNOiNxPId7cRsPSg45sov5/hdJRxKZjLyClutI738g4XSwHSRM 5Soudi7LnRXtX8zNHhcvU1On4RKmSFFiB9Oc1jLgpCGx6D4D4JxJ7cN8NGnW6w6GJ4cY mYpOpIYaAd7Nk1v0eHriKCW5pyfjewYHYunp96L5s8khxO3XCbtaG16xrxlDaSJzu+7q DGGNKtuDY2jbPKeSvgK1Po67J3CQmkF2WxirP7NhVC+9KGapmkpb4NUjvg4nLNGpJrgT oN+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786096839; x=1786701639; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QQZgcdlI2EieaifCVQjJlrIUWRZzFN6DkbdW2khQ3hg=; b=rzzpu2IR9+qcZ4zBmP/RqAB+unbJQpfuBnKGkUCFxvHTUZjuWsI3bg+3eHvfMLU77p pWdqbnNY8nWFIn8zrOuPZM0jg4TXHpZGrp2bGKbq4PyPBE9P6XmLFQvhyF/s+QHys4aW zcrNDer1Fu04J3refWXQfZzObLnW4zhJlrZA8NkYlQj+sqwAH6lMrl2WID3ALWZHgkrT dbc/HTPKsOsnLVSFOl7YSn5ZtSUOEg4KhkVpUu1jIlXBInaELK0Kg4rJUqpdN1nA911u 3h6hPo6m96EnYO7JjGG1WrJ0bQ2w7WyIYeDgNzmGZiUBAM3reggd3FjnGsnDxiaI1EgK sstw== X-Forwarded-Encrypted: i=1; AHgh+RpNwS+ry/BkYEDM3OvsERIfkUnDUBfk86hcsuOf/JrgrBdlREhjOVlOpH9fZW8BMKcsOLQXoDNlTLd33VY=@vger.kernel.org X-Gm-Message-State: AOJu0YyK5JeHcldyoD/FW5+rkhJ3fPHl+4NvZGIfqzq8BEFpq+1LAlk0 cJAxVo6hmZhwGdX/jhfFP3Vjl3piIYNB9M5w9n/jo3pMMjHyzzB39qYC X-Gm-Gg: AR+sD10t9Fb/3wq6GYTNN8n60wjcjh6Ik28H3ZojsXUbqJtGv8ubkm37RoURn+snaoh 6R/m8ktXsEznSBlX41zmkkHdWizJhxQ81RK3OuyjaqY1C+nA2c9jnUk4zpxrP5gRX0ZTDtO6c6t qvJ1bDxsTzDrLmm+npQfpbJ+1YV5+lhJph48avNo/dAGc1OYylcQ0AOZCFfgIGncSpPcpBOEc6K NxQNnSTTZTeIKVEeni3GbilwcgQr9TH8JJEo0rCdWs2ldK0fDPAB2B1TnntZUCJglvGZrVL1YMJ dPTwTOCyQINedu1pMWmzbgvuWqqqBgbgUH7eP+o87FkwPb+TyEG6Z+HxdgpDPKmWOT4E3kOXfAX zSQIfyOAkmAMrYIiBLkSQWdxEjx5QKWulk8nmG0BfySFigj24aI9mqiD7QCPwmy34qypWZjkBhf eNfw3wEjsyAXCDldPd0Ke58SpS5r4+mKH5kVlCBPrVqk+7vhit8CvTd16uZTOZ8GSZ9VIaSkEYf woAPuInkVZzPhjA/VjzFwV00yhC26fD1nx9sSVMI1PTj/00WM93A4DzqHiVfV/7mXY= X-Received: by 2002:a17:902:f60c:b0:2cc:aa36:c04c with SMTP id d9443c01a7336-2d0ca7afcabmr254341645ad.1.1786096838646; Fri, 07 Aug 2026 03:00:38 -0700 (PDT) Received: from EAIT-H54D9Q2FJQ.eait.uq.edu.au ([130.102.10.60]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d16c4a9f0fsm6500035ad.68.2026.08.07.03.00.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Aug 2026 03:00:37 -0700 (PDT) From: Yu Zhang To: mst@redhat.com, jasowangio@gmail.com Cc: eperezma@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yu Zhang Subject: [PATCH 0/2] vhost-vdpa: fix a use-after-free on the config eventfd Date: Fri, 7 Aug 2026 20:00:23 +1000 Message-ID: <20260807100025.19750-1-yuz08559@gmail.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vhost_vdpa_config_cb() reads v->config_ctx with no reference and no lock while VHOST_VDPA_SET_CONFIG_CALL frees the old context, so a config interrupt delivered at the wrong moment signals freed memory. Patch 1 stops the fdget error value from ever being installed in config_ctx. It is a fix in its own right -- the callback tests only for NULL and would signal the ERR_PTR -- and it is also what lets patch 2's lock establish "non-NULL implies valid". Patch 2 adds the lock that closes the use-after-free. This is not the reopen refcount underflow fixed by f6bbf0010ba0 ("vhost-vdpa: fix use-after-free of v->config_ctx"), and it is a different bug from the vq call fd one I sent on Aug 6 (https://lore.kernel.org/all/20260806150323.2154-1-yuz08559@gmail.com/), which is about the parent caching an eventfd_ctx it does not own. The three touch different functions. Tested on v7.2-rc6 with KASAN under qemu, VDUSE as the parent: one thread swaps the config call fd on the vhost-vdpa fd while another injects VDUSE_DEV_INJECT_CONFIG_IRQ on the VDUSE fd. 9 of 10 30-second runs hit the UAF; 0 of 5 with the series applied, with the workload counters unchanged either way (~30k swaps and ~2.6M injects per run), so the race is still being exercised rather than merely not reached. Also clean over 5 runs with PROVE_LOCKING, and vdpa_sim shows no change on the shared VHOST_VDPA_SET_CONFIG_CALL path (20000 install/unbind cycles plus the bad-fd path, identical before and after). For patch 1 specifically: with a working config fd installed, 250 injects deliver 250 signals; after a VHOST_VDPA_SET_CONFIG_CALL with a bad fd, delivery stops on an unpatched kernel and continues with the patch. Yu Zhang (2): vhost-vdpa: don't install the eventfd_ctx_fdget() error in config_ctx vhost-vdpa: protect config_ctx from being freed under the config callback drivers/vhost/vdpa.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) -- 2.43.0