Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2051363pxb; Mon, 12 Apr 2021 13:02:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGtgtPUAIoQguUBGd1iibn6gR6w5PsDXq7CeV/U2cHEsLKdCY2+0uhna/c7RjhZKs4z3E4 X-Received: by 2002:a17:90a:6b06:: with SMTP id v6mr849493pjj.167.1618257763228; Mon, 12 Apr 2021 13:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618257763; cv=none; d=google.com; s=arc-20160816; b=IJoa641k4HlDV2XqJSRFLfw07BhsnENqRghTgzd7PUmNYgUYKMEzX2g0B/AJpVggPG 2/bI1MdLKaa5HsgsHFHJNrHr4lLekYnhzM7BDEkFlPRtWJ/UR49vKG8IdrFM7WhqF6If lX+ylg9Rr7TYoChN2Hxyuh4ak+pXoJrElv3xfkxI+X8hOpsutceMQoojucWP3IuI8JDI FH9BpIIthv/K9H8ysgJhdbt8OyZ4c/bsxlx3oxmE8evrr2QrTAHKMn+QqGWx5xT/zfdq OYldeQZ+G7gK46t+iFwG3TGsHRSv0QG6yqAn6rGwjmP2tsbSJl0IKv+w0xbNanHeEkI6 kHQA== 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=+WpabP/sztEnDuhmrFMdoSFGAqUMfobxKpHbf84pRIo=; b=dYKwBXymlhdjQ745cKBA27/yaJ5okY9yQwUprVnjnIJLKUdcJrq2YTrwmMnEsaC+fP ombZdtyraJKyoef7wav6gXa5XTdScv6R1Cx6H/2hj8CJpcI8LUQ2kIj4TDe8MB0wvHTm 1H4Z/Vcy1u6cM2m+AA0wqH323Tjp4Tp4E39apZnhiht2BvTtj8drWwqce4AEOxOoE/0b f43Ybe5kiAFf4hKC5VGxRlFSkD4hRNjjkM7uqYVaF14BWhBuGYs51/FwS4CGhgkLv6vV WUK236nigTb8kOOlpzgqxQLbl8SO4axLLyA/FCWKbPmjg6Dl2oqGi9/vGDaftYIU9bvg 1itQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OE6dRtmo; 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 nl9si461879pjb.47.2021.04.12.13.02.24; Mon, 12 Apr 2021 13:02:43 -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=OE6dRtmo; 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 S237498AbhDLInW (ORCPT + 99 others); Mon, 12 Apr 2021 04:43:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:34804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237469AbhDLInQ (ORCPT ); Mon, 12 Apr 2021 04:43:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C55FD60241; Mon, 12 Apr 2021 08:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618216977; bh=PFW91EuFBXrqOQKneQUMS7TP1qinbNVO15aALWS0ssE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OE6dRtmoWhVWztBi+6e62w16H6E6xDE4hKti7ZHaC3YNcBAu96ARHGFx3Fs3jF/Zz fDTQGx7QixrNVrU6GCCxeX0aYYPcVBMJJ3bYIZYLPwOZMSQt7lCPk0AOa+SR3h20UX 6oh0fL9/yDXuFWFI4wfeCsLdB2x1uQeXo7vvL9sQ= 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 4.19 24/66] usbip: vudc synchronize sysfs code paths Date: Mon, 12 Apr 2021 10:40:30 +0200 Message-Id: <20210412083958.910341200@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412083958.129944265@linuxfoundation.org> References: <20210412083958.129944265@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 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: 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 @@ -571,6 +571,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 @@ -113,6 +113,7 @@ static ssize_t usbip_sockfd_store(struct 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) { @@ -188,6 +189,8 @@ static ssize_t usbip_sockfd_store(struct wake_up_process(udc->ud.tcp_rx); wake_up_process(udc->ud.tcp_tx); + + mutex_unlock(&udc->ud.sysfs_lock); return count; } else { @@ -208,6 +211,7 @@ static ssize_t usbip_sockfd_store(struct } spin_unlock_irqrestore(&udc->lock, flags); + mutex_unlock(&udc->ud.sysfs_lock); return count; @@ -217,6 +221,7 @@ unlock_ud: spin_unlock_irq(&udc->ud.lock); unlock: spin_unlock_irqrestore(&udc->lock, flags); + mutex_unlock(&udc->ud.sysfs_lock); return ret; }