From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793612854; b=hVd/RjMXMbrU4/sahbQJLV0CREOh/2K+nweiwKmT+bsdIErexNoSsrfZTOsyiwBgkxzV U3UghJN6lZ03+5FRpLYJeAB7reLf6V9ruec2hsosNLqoVaUVhxHXo0rWD1uoghWCBxWef UTww87L/M3UCUMzzo+AA95V+oj7eE9+6DurU1QGFmJnGNu/fZ8MBb9j9AzKa0HIN50hSd wPJWDpVGgHGWwwKWAO1bB5Ah6BJZlrC2MWYTEWu4xzccR0w//+FZRuuEjKWI+QEadkj3s E5zV/0UpAQwQEpgUmS2qBuhen8U/yR4ElL/ynxJjKsifF5MNoYKwKM6scxeVJlTKbzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793612854; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=it6Vu4qt3zaK7MGxxtPRg8P0zTaXMG2Fc9lz6FZfK90=; b=qWjBcJ97WdZ6cCBiYPLSaVNZSoTwaxpa31TrdRqttGYy8+IIqI2Bcpv5WAvy5f+MvPq4 3PFV+7lQpp3RT6lB3tDDGuKkYxUyarO6tnEWr35rSFCiZvpOIcVQ+HYbBHta6iHR9/sU4 6pMmKI54rCrzZDJR9DARVIPfkpwq5V8wQvkMKwNccO+iqbb90/ZeE6G8uQ3Cln+iPSc+t CKyHGkbMtpDMHsSmtk8CrFxE1tbB0bDn7nxNBqv/S6GFSRUsv6uAuDDnO7gVuSrrf+WFA qA5iisv9HzQjm8wH1BEC0cVd7Cu+9FZYVC2tz6xDmzRzf1nqtWzYDbBWjXZps0GUtsQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K0NFfgmA; arc=none smtp.remote-ip=209.85.210.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFD5E606A32D for ; Mon, 2 Nov 2026 09:47:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EFD5E606A32D 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K0NFfgmA Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8a05da1cc1fso1049092b3a.2 for ; Mon, 02 Nov 2026 01:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793612853; x=1794217653; darn=vger.kernel.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:content-type; bh=it6Vu4qt3zaK7MGxxtPRg8P0zTaXMG2Fc9lz6FZfK90=; b=K0NFfgmAD1BkLg8Vt/1M9Vxej+O0L822wWuMB4YB4Y1hQQRNjtgQcrsP58wumtCELx SpieaXvvYyuxNDJEGYbpN7EyvRifFgu0dKpJ0pjVLHLFDBy9RfAhvTtnTAlvhXgkFNCF M+rCjjH572pyOW7iatpV+x5NgSO3sWLEqBthReSwYWQMH2k9NV0hV6SopvX2MVlfCqPm 5sUEd87mQHEV0JN+mNP8yspBh1t1yg4TA4JxyGhqTK3tt7up252c3aRkxPAwh5VEdJN3 m82Rw+PVNSFxv3kCIk0oFLkiBdwvSjx1Av2b5OVnPhD+uvZ3Z+pxFDaUTZm7Cg/CM2EH 0Aag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793612853; x=1794217653; h=content-transfer-encoding:mime-version:references:in-reply-to :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=it6Vu4qt3zaK7MGxxtPRg8P0zTaXMG2Fc9lz6FZfK90=; b=nJXHQ8Yy/uyDwVwt+JEi84KB+aZNRxEc34yWlT8G9dQTK6+ic4IxUQa8kGnC7QnVUJ 6N1u3xLmy/m/E3sL990B/k33FKHwkJtEdnE0aO5WOLdiCwu2tpJLLR+QMP+PuT5q3p1I 5wTDHiRM4gSUMr4yO66RpxRtlp357fbmVq7TduWSY2PclTO9CVwYuMrMOu2NXOEluI7v BodMGXCF3L6pCA3+cTjL/qXjzyiTlSyx0OtluYUYtp/l6EvnfI49JWeu9q1Jdg2bT7pg OnGKBBZlSrLNr8MGEfAB9F8iWRVytmJZuue9Evz6ry+cx9u/w4WFvHXWNQWeMZ//NPwK LeQA== X-Forwarded-Encrypted: i=1; AKwUvBwc/Kx2exYPxlW19oRq5i2TzbNg0o+zYQazoYehR9zcJ3IlRlsDIJUIApHur4VEmxiEUpujy4pH4xVgKcw=@vger.kernel.org X-Gm-Message-State: APuU4Z8lqRL+ZrXSZIf4y8/5T4rzolJfdtz1Sr+ZZAM9faoQq0MF3zbb WjZZnp7YoCjwMtQLZ833QFmwCwVYiMoTZ2dBTM7KNGGInydUmGljabJU X-Gm-Gg: AYBFou2As8FG6us7DK0OgWvCGUC6B/cyoltlq2neFFtlfnFZmbCHuTCEqqU6ZKjF1an UUEArF+11mtepmMGHDCblEqOi9uyI4pnQuT5RyBwRPq5r/gRIIyWGqn7G0vy5e7We2oda5xriwd PD7vrLRxIYLB6cQcNeYkQaC/kMxpdbQ/n8rkXes3CgGxGTDkKwm3rDWDKJphVRXxxiSd5jvPWPA LoXNuAGe2mGT/8btJWp05Y32Aa1H7+qpY1rtoV7YEk3LR9vKNmKxrcfs2skmkHTRmxw+rtLLDxt obivAZoViS+CXx21ZA7bxfOj/gM5VkMPzsFRaP5jowJqmKi+KrffjlAcXBTQCs/+nF05Y4h5hBi RtcS4ehDnsWAuW8QkxE/N6kQ1Sq1hTp0KPzCUB52jTHYKHPwD/A5cJNZKkcgIuBhlEryaGBb/7F bP0PNhhyB7t/MyggDqLM5XDK6Z/8x+LE7Qxm093Zr6sjxqN8/6VcIQeFBkhPxD5LXEwluOSp27U 6fFlDIVc+ox321oC+uIz/xtZQD6ADAuqCYPtyud6LDC3WR+/fqUicQs13miFvV1sO/fym9ppxY0 VdJ27Nu10QlHEscyULBG4I18cDOfIzWzN74LjYmq1T2Vi37DqaMGEH0= X-Received: by 2002:a05:6a00:3a21:b0:8a0:7677:c8c9 with SMTP id d2e1a72fcca58-8a9bfde052fmr8075185b3a.51.1793612853308; Mon, 02 Nov 2026 01:47:33 -0800 (PST) Received: from localhost.localdomain ([155.69.168.11]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8aada3d479dsm1802116b3a.39.2026.11.02.01.47.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 02 Nov 2026 01:47:32 -0800 (PST) From: Yuqiang Sun To: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com Cc: mhklinux@outlook.com, stephen@networkplumber.org, linmq006@gmail.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/2] Drivers: hv: vmbus: Do not remove the channel when device registration fails Date: Mon, 2 Nov 2026 17:47:19 +0800 Message-ID: <20261102094719.35760-3-izaiahsun@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261102094719.35760-1-izaiahsun@gmail.com> References: <20261102094719.35760-1-izaiahsun@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When vmbus_device_register() fails, it drops the device it was setting up, and the device's release, vmbus_device_release(), calls hv_process_channel_removal() on the channel. That function is for channels the host has rescinded and starts with BUG_ON(!channel->rescind), so the kernel stops there. Without the BUG_ON, it would unmap and release the relid, unlink the channel and free it, and then the error path of vmbus_add_channel_work() would do all of that again. Leave the channel to vmbus_add_channel_work(): clear the device's channel pointer before dropping the device on the error paths of vmbus_device_register(), and only remove the channel in vmbus_device_release() if there is one. If a driver was bound, its remove callback runs in device_del() and still sees the channel. Fixes: c2e5df616e1a ("vmbus: add per-channel sysfs info") Cc: stable@vger.kernel.org Signed-off-by: Yuqiang Sun --- Notes: The bug was found with kbound, a research static analysis prototype. The patch, the changelog and the test setup were written with the help of an AI coding assistant (Claude); I have reviewed them and tested them as described in the cover letter. drivers/hv/vmbus_drv.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index fc0f16f51266..e8fb0c4c4f5e 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -979,9 +979,15 @@ static void vmbus_device_release(struct device *device) hv_debug_rm_dev_dir(hv_dev); - mutex_lock(&vmbus_connection.channel_mutex); - hv_process_channel_removal(channel); - mutex_unlock(&vmbus_connection.channel_mutex); + /* + * No channel if vmbus_device_register() failed: the channel was not + * rescinded, and vmbus_add_channel_work() cleans it up. + */ + if (channel) { + mutex_lock(&vmbus_connection.channel_mutex); + hv_process_channel_removal(channel); + mutex_unlock(&vmbus_connection.channel_mutex); + } kfree(hv_dev); } @@ -2189,6 +2195,7 @@ int vmbus_device_register(struct hv_device *child_device_obj) ret = device_register(&child_device_obj->device); if (ret) { pr_err("Unable to register child device\n"); + child_device_obj->channel = NULL; put_device(&child_device_obj->device); return ret; } @@ -2228,7 +2235,10 @@ int vmbus_device_register(struct hv_device *child_device_obj) kset_unregister(child_device_obj->channels_kset); err_dev_unregister: - device_unregister(&child_device_obj->device); + /* The driver's remove, if one was bound, still needs the channel */ + device_del(&child_device_obj->device); + child_device_obj->channel = NULL; + put_device(&child_device_obj->device); return ret; } -- 2.53.0