From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 EFADB41B8DC for ; Mon, 10 Aug 2026 19:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390406; cv=none; b=mVymJMwzQnGvZR90bomPSybay0AaXrH17MrkLulo1LNU4jvs3mZL4MaJivcZTpRwQwvJSgdPh7LSHCOxIcHUNt6+d6cBU8mRWt/Mfel8km7surAz4UoHJXQXa0bugBmTLc2ffLWBSczY2ojUpeWWKFUYKU2wBNSzF/Oed6kE9s4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390406; c=relaxed/simple; bh=SW5/seaUl+tZNUVKwpdaQB5vHV2SqlBFmBBbRGHqLu0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=P+QE/Uxqffl8twKOLoYzFX4Gbbba3WhojeZgMp/8xgK1ed+hbCnpKAijaJK1CcVh4xp7LjQF6KGa1EQhBPhqzrDb7Wqj7UWpKOb1y/C5RsTZTTWVLS2gJgEbWXxf3mtVpa86lDNtxxNnFngKaXwxTN7Eo72h6mNJ58FXgzv4Ysg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PVwzylR9; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PVwzylR9" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7ee4f241f42so154849a34.1 for ; Mon, 10 Aug 2026 12:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1786390402; x=1786995202; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QrRlsgcOgMJKftL8Bqe2As9MXqW/RKYfWKo2wJ61FY8=; b=PVwzylR95W8sUinMFu/x2GTRQ+B9p0fqZiaAlzC33nBoOBRlExlOziF6rdlppeFJWK RO5KAtyIfh0jPkwf0krJOXrI/Zor7X4kogJCK6xtLgVSAxhOh0TUh+HpNAhAaEpgLZiy Mbyo6Ua3SG1KMbh2MY+ATAGe3rXZv+Cy4UMwk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786390402; x=1786995202; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QrRlsgcOgMJKftL8Bqe2As9MXqW/RKYfWKo2wJ61FY8=; b=Gbdt63THze9JPiJOqQv0x1edku0bgOa/YCH8+92cmG09kB3XQsc83XLXHWIjvEJlR9 wYaLcRQdyyGM32exHuN/2JrwJjFQqIWM6nmx5z9/cLwSr7xCkEpWPuscF+a27socMeGF U7bEnVU4udMHDF4e92iOZXL3/LjFTp0DlS5vyWqrgiYs8kCTDAg/c4UT9NQgm6Y9FQKu /MR5OXqVlS4mtSPGZYwMqXTwfjj90GuiVUjcFw0Yr3l7AS9uyqnQr9IeZNcRgmefbw9G 1iRwIfCLwes+ma3EsVkMkZJrFbjJTNKxS6sO1IE4y0zcMxtkdzYTYpa2sW0i8GRD3IyR MG7w== X-Forwarded-Encrypted: i=1; AHgh+Rpw1Y2gVhieL41f80aue2moPnj2zAwtQP0aLbkKHRgr4DLa4fI5bHmwVFCNlU6NmWZGeokAWgJO1pzTeiw=@vger.kernel.org X-Gm-Message-State: AOJu0YwnF5u+tcmps5Rn4vga99xqHkDihdbYsV2+ZH5eHuzk8S7qXJLH BCKDaPwhba1cBx1NmksbIrDeUhwuRkbha2vmWvW+0XUo0KRO5gycR0rl/Qb9t6ZlBEQ= X-Gm-Gg: AR+sD113Huq5jJWFTs1cEa9qBty9pp113BjRDLEN3fG3X1r+1Mu8vm4gODLBSOOUrg4 FOJqkiIG1Fa9KzBNFqdiRcXMEeZUKGYsV8vq/KFHdG3AWUi/fentLkpZhXtLXnAC8dqFeSU0pDE ryMhjK3hIqucyb4BZhuLVq5M3forxBi1rC0zMKoOVhCK45na1VBMfWmg8261O9kv8QmxRWO9fbD 1camy2U+1yfaJjVFtm1hD4In1dv80BVUKX0btxdkiM/jIdFfGTatvBb4BdD011+/R/slK+uW4jw NdoUZ6LUuR4AvJZWOiyn8pAtWNNr2oUcorT3kI437t/8uB+QSqx3UhPO3UMU71N/35pgqLTxNTB 8BNLCxsr4KL8jC8uexDSPXAbc86SaiN0KyypBDQyFVe6cq33EIhHRpU5DgOGxjqe15Uhm/2WK5u nFWcNnStsHuRtvgPGlIhiexFVbg68GKF1iwdZQaGNVbgRGKOz27WzkB9lxvMEm/GgoQzqaIw== X-Received: by 2002:a05:6820:178a:b0:6b0:40d9:8691 with SMTP id 006d021491bc7-6b099ae1beemr490758eaf.8.1786390402359; Mon, 10 Aug 2026 12:33:22 -0700 (PDT) Received: from [192.168.1.128] ([38.15.57.99]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-459f1a9e431sm8909201fac.6.2026.08.10.12.33.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Aug 2026 12:33:21 -0700 (PDT) Message-ID: <34d4ca1b-ce89-444f-bb02-245287edfad0@linuxfoundation.org> Date: Mon, 10 Aug 2026 13:33:18 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] usbip: fix use-after-free in event_handler() To: Aleksandr Nogikh Cc: syzbot , syzkaller-bugs@googlegroups.com, Greg Kroah-Hartman , linux-usb@vger.kernel.org, Shuah Khan , Valentina Manea , Nobuo Iwata , i@zenithal.me, linux-kernel@vger.kernel.org, syzbot@lists.linux.dev, Shuah Khan References: Content-Language: en-US From: Shuah Khan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/7/26 08:18, Aleksandr Nogikh wrote: > Hi Shuah, > > Thanks for reviewing the patch! > > On Tue, Aug 4, 2026 at 7:31 PM Shuah Khan wrote: >> >> On 8/3/26 09:05, syzbot wrote: >>> From: Aleksandr Nogikh >>> >>> The event_handler function in drivers/usb/usbip/usbip_event.c is a >>> workqueue item responsible for processing events for a struct usbip_device. >>> During device teardown, usbip_stop_eh() is called to wait for the event >>> handler to finish processing. However, usbip_stop_eh() uses >>> wait_event_interruptible() and ignores its return value. If the process >>> unbinding the driver receives a signal, wait_event_interruptible() returns >>> immediately, causing the teardown process to falsely assume the event >>> handler has finished. >> >> Does this mean unbinding didn't happen? > > The unbinding did happen (and finished freeing the memory), but > without actually waiting for event_handler() in > drivers/usb/usbip/usbip_event.c to finish processing the removal > event. As the device memory was prematurely freed, we got the > use-after-free crash in event_handler(). > > For reference, here's a C reproducer for the original bug: > https://syzkaller.appspot.com/text?tag=ReproC&x=16ffb7b9580000 > It sets up a timer to deliver a signal and wakes up the > wait_event_interruptible() call. Thanks. > >> >> The teardown process then proceeds to free the >>> usbip_device memory. Meanwhile, the event_handler workqueue is still >>> running and attempts to access the freed usbip_device, resulting in a KASAN >>> slab-use-after-free crash. >>> >>> BUG: KASAN: slab-use-after-free in __mutex_lock_common >>> kernel/locking/rtmutex_api.c:559 [inline] >>> BUG: KASAN: slab-use-after-free in mutex_lock_nested+0x5a/0x1d0 >>> kernel/locking/rtmutex_api.c:578 >>> Read of size 1 at addr ffff8881145245b0 by task kworker/u8:5/6177 >>> >>> Call Trace: >>> >>> lock_acquire+0x84/0x350 kernel/locking/lockdep.c:5842 >>> __mutex_lock_common kernel/locking/rtmutex_api.c:559 [inline] >>> mutex_lock_nested+0x5a/0x1d0 kernel/locking/rtmutex_api.c:578 >>> event_handler+0x1e3/0x4a0 drivers/usb/usbip/usbip_event.c:73 >>> process_one_work kernel/workqueue.c:3322 [inline] >>> process_scheduled_works+0xa8e/0x14e0 kernel/workqueue.c:3405 >>> worker_thread+0xa47/0xfb0 kernel/workqueue.c:3486 >>> kthread+0x388/0x470 kernel/kthread.c:436 >>> ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158 >>> ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 >>> >>> >>> To fix this, change wait_event_interruptible() to wait_event() in >>> usbip_stop_eh(). This ensures that the teardown process strictly waits for >>> the event handler to finish its execution and drop all references to the >>> usbip_device before the memory is freed, preventing the use-after-free. >>> This change is safe from deadlocks because usbip_stop_eh() is never called >>> with locks held that the event_handler would need to acquire. >> >> Correct - usbip_stop_eh() is called without lock hold after updating >> the shutdown_busid status to true. However I am curious what happens >> to the unbinding? Should usbip_stop_eh() check the return value of >> wait_event_interruptible() and handle the error instead? > > During unbinding, we must wait for the scheduled removal event to > finish before we can safely free the device structures. From what I > see in the code, once we have reached wait_event_interruptible(), > there's no way to abort the process or somehow gracefully handle the > error. > Yes I agree with you on rewinding being hard. Care to explain the scope of this assist? Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot thanks, -- Shuah