Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2127093pxb; Mon, 12 Apr 2021 15:21:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGCOc8DRB68CyBhuGE46UA/fncCJTjNZxnVXHVJb979dZsx28yNXy8gc2MbgJP1Ny417Zt X-Received: by 2002:a17:902:b091:b029:e6:f010:a2b6 with SMTP id p17-20020a170902b091b02900e6f010a2b6mr28340193plr.39.1618266097946; Mon, 12 Apr 2021 15:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618266097; cv=none; d=google.com; s=arc-20160816; b=MZSBvs/aMDRkmOhLPo3SBxVG3GZStq3l2YwsjyujaGWCh31CqI0ne7NhYApo42WaVL AnWzK/taPzhHB3+SNb7m6HFo0p6J5uZyqAhcJQCHAZAdTjuTtHM4UHBK/+snwRWuVwyn AuZlWS+4AkxOoOII+dV2ke/A0jcmKZ75CcW7ICWQ88i6YChmuxdzk0G0Tv4La7TpQ52i 5fuzYtbmxbZ+B7Nxz91eIPzPt9aliClPdgiLZ3WDhvTeRm8+33FXlhNVnSn3+oKPrWgR t18Jg7gFSWj0wglbvpVkprqnhT1W0R8+Q+F1VRi8HVQO8gnFvtF7zCj7SW7fMLB7xc/d aPVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JuT1RteP3UHlueMIOXhU4wN0MXKwCWGAcoFPgHdnkvk=; b=qgI2MumOjChQvjWAwQR5BoRYtY70JPcwPqzvHlRy1i4JEXAgek7cAAbRaXdssTz9JS 0AzMmVoY1Ar392QmsC3WALil0zVdITnxI6akQzQ6c6xPXX5tdFp9NTa0F2C4x1L+YiXJ bEB15HiromAf6n6fAfIxibFG8JaRVrpFIU8UDX2Bwtl3oYRABHJcfYG+EPV/ibyPuRP8 8VlkdaKbzSNvj3DkIyxGeLh3UHOZRMu0TB1lbIHnnnMofsQLIE53sNCIoQvXPLNy9vIi pUwhUheztd4Bc591ytw5LzRXmyYXbpRct8GSCeVOqdOVTZ53vq0ch9wdyscZ6NDP4NCg ygOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G1gKahnK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si15447551plo.138.2021.04.12.15.21.26; Mon, 12 Apr 2021 15:21:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G1gKahnK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242551AbhDLJ24 (ORCPT + 99 others); Mon, 12 Apr 2021 05:28:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:54840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240223AbhDLJFN (ORCPT ); Mon, 12 Apr 2021 05:05:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26ACF60241; Mon, 12 Apr 2021 09:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618218135; bh=p2OwqxFHSKfHPF7Uh5dxXGlLivSDO5iVmkwk2ean3h4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G1gKahnK2F6hgQQ1tXLXgwq4XmMMn4hGAztJuHT8PzsIt6J8ruToNfzD4P42FQfYS z518wnQLRDyjVHypdPXALbPH+LGMpfvrP14QauBQqcAlJ6EohVTWwzLhf8kQ0inxb5 QA4mL/VlTqn5t8VW8g5G0Q3/Q2saYGmPEFeBR3F8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com Subject: [PATCH 5.11 083/210] usbip: synchronize event handler with sysfs code paths Date: Mon, 12 Apr 2021 10:39:48 +0200 Message-Id: <20210412084018.781817604@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084016.009884719@linuxfoundation.org> References: <20210412084016.009884719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shuah Khan commit 363eaa3a450abb4e63bd6e3ad79d1f7a0f717814 upstream. Fuzzing uncovered race condition between sysfs code paths in usbip drivers. Device connect/disconnect code paths initiated through sysfs interface are prone to races if disconnect happens during connect and vice versa. Use sysfs_lock to synchronize event handler with sysfs paths in usbip drivers. Cc: stable@vger.kernel.org Reported-and-tested-by: syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com Signed-off-by: Shuah Khan Link: https://lore.kernel.org/r/c5c8723d3f29dfe3d759cfaafa7dd16b0dfe2918.1616807117.git.skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/usbip_event.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/usb/usbip/usbip_event.c +++ b/drivers/usb/usbip/usbip_event.c @@ -70,6 +70,7 @@ static void event_handler(struct work_st while ((ud = get_event()) != NULL) { usbip_dbg_eh("pending event %lx\n", ud->event); + mutex_lock(&ud->sysfs_lock); /* * NOTE: shutdown must come first. * Shutdown the device. @@ -90,6 +91,7 @@ static void event_handler(struct work_st ud->eh_ops.unusable(ud); unset_event(ud, USBIP_EH_UNUSABLE); } + mutex_unlock(&ud->sysfs_lock); wake_up(&ud->eh_waitq); }