Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp403457pxj; Thu, 20 May 2021 12:01:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYaoPtI97zCGegSBZRGapljIwitUOSqfOAskvEEAwiKCQyHUW8IkKQqz+LvVAmqwOjGKT2 X-Received: by 2002:a05:6e02:1bc7:: with SMTP id x7mr6778286ilv.206.1621537292798; Thu, 20 May 2021 12:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537292; cv=none; d=google.com; s=arc-20160816; b=kYQT1nr+PagNGg7QlO9f05xmnlXV8051XqCzVkX0PbriRruDNA5RrG0dYpYpdj9t9p iPwitTjaqSa8Z6xXij3rhw6YOmtL136zdJzKvbHXsp9n43YVTWt4GOOKjIz7+fSibJBt XWqWEZXrFCsKWyKtLYUW3hz79LbEAjqISIOEf5/dWMWn+NodfXSmK0hQRwiT6KTTnm9f eX/y4Ne/+96qZ5RjzwzY/39cuKOHPPQMSM9wpYjwl4Gy4ELpcnJEdJkXgc1WHNq3z7DI Z+yzzad80PS7e6CsuOCkn2VFMOSitKub/PgQwwvdRQgKT3Zv0/3Z1TS7LqIDkHMribDS CSjw== 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=N/jx8+pjTI87b+BHoPxGhEXi+hPpRof+j70Vvt9grY8=; b=OCTPWeEnM/FgDNZWI8Tv3kcgkMPYmf95WpFaX2PWALczPceSU1j02VWtDsFB4Hax5X bvDRJHf+wMMWiVXxAI5QbjGZf45t4NBmnAk6Js4mK6dCU/WTjKC1hlImOCOrzCxkP5Wk 44FoXeDX2Qy2wjzQdAGzPIPtfz2uxFFSQQe5IIQpNAupRWQ1daXr7l6Ov+wsGfcKTm3x cqDing6dcxjjmAWHEmnzZ3EH8RUcBI17H7rFUMvnH3RQLxnSlITI+dTDO7T/Egnh5rX+ WnPVh9rwvXmAok1+2U9iofKNSYbET9NAM0PWh1U/qHiZq4SaYy2p2U37mnr/oBv6ms2L 4oiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dMIKCLDQ; 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 z8si3528698ilq.2.2021.05.20.12.01.14; Thu, 20 May 2021 12:01:32 -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=dMIKCLDQ; 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 S236696AbhETK1E (ORCPT + 99 others); Thu, 20 May 2021 06:27:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:46918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236377AbhETKPF (ORCPT ); Thu, 20 May 2021 06:15:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A88B06198B; Thu, 20 May 2021 09:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503910; bh=MAo5Hd9YMhuXlUshsU3RIg6tbf+LaT7zrF9v8C4m2Dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dMIKCLDQAuzzhYZUORf5GIFLNbXVguKQ5J4LLfLyElQVLdB2gQgbuoCpai+zGwtla 5KjXcWPvK6iC4+2DjeKs38O1pJrZgRtaflzrn/4yugocwYylf8btmyDwfMcOYW7GWM L1hroo5+n+SgUBALtXCkObyeK94THcse7jdKd2h8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shuah Khan , Tom Seewald , syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com Subject: [PATCH 4.14 001/323] usbip: vudc synchronize sysfs code paths Date: Thu, 20 May 2021 11:18:13 +0200 Message-Id: <20210520092120.166419561@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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 bd8b82042269a95db48074b8bb400678dbac1815 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 protect sysfs paths in vudc. 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/caabcf3fc87bdae970509b5ff32d05bb7ce2fb15.1616807117.git.skhan@linuxfoundation.org Signed-off-by: Tom Seewald Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/vudc_dev.c | 1 + drivers/usb/usbip/vudc_sysfs.c | 5 +++++ 2 files changed, 6 insertions(+) --- a/drivers/usb/usbip/vudc_dev.c +++ b/drivers/usb/usbip/vudc_dev.c @@ -586,6 +586,7 @@ static int init_vudc_hw(struct vudc *udc init_waitqueue_head(&udc->tx_waitq); spin_lock_init(&ud->lock); + mutex_init(&ud->sysfs_lock); ud->status = SDEV_ST_AVAILABLE; ud->side = USBIP_VUDC; --- a/drivers/usb/usbip/vudc_sysfs.c +++ b/drivers/usb/usbip/vudc_sysfs.c @@ -125,6 +125,7 @@ static ssize_t store_sockfd(struct devic dev_err(dev, "no device"); return -ENODEV; } + mutex_lock(&udc->ud.sysfs_lock); spin_lock_irqsave(&udc->lock, flags); /* Don't export what we don't have */ if (!udc->driver || !udc->pullup) { @@ -200,6 +201,8 @@ static ssize_t store_sockfd(struct devic wake_up_process(udc->ud.tcp_rx); wake_up_process(udc->ud.tcp_tx); + + mutex_unlock(&udc->ud.sysfs_lock); return count; } else { @@ -220,6 +223,7 @@ static ssize_t store_sockfd(struct devic } spin_unlock_irqrestore(&udc->lock, flags); + mutex_unlock(&udc->ud.sysfs_lock); return count; @@ -229,6 +233,7 @@ unlock_ud: spin_unlock_irq(&udc->ud.lock); unlock: spin_unlock_irqrestore(&udc->lock, flags); + mutex_unlock(&udc->ud.sysfs_lock); return ret; }