Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3524548pxf; Mon, 15 Mar 2021 11:28:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1A+W6rIZvU0iPRc8ZB9EJbPOd3I4MavoI0YRLr8F/Js80Egx2jgFFKYSpnPG/6ahBwBC6 X-Received: by 2002:a17:907:971a:: with SMTP id jg26mr25767572ejc.317.1615832931174; Mon, 15 Mar 2021 11:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832931; cv=none; d=google.com; s=arc-20160816; b=dj+LXwhV67a5Z7YaV7eQNBC9GY8lWuZUnhOSXmDYrZ+BMPQ6CI5l2LmzCy6ZS+XEVv WPRr4ccDp4WV9AaA6CZBPIkBIscg54sJcclKe02P3iIx9iwWtsIUIYbBOq7OaMO7In4G 9/Qo62ngTbrpDSXvy/kIl9io2wkKKBaKS4xfOoJlwPXon3EHktjX985BnvOldrRrat4i 4ImZr424W5S+4pMLoDNQK4qUDucfXkPyDSyd8fYcJ5YhZurbmNzBEMeW0gNZxPwgUky3 zdz+BqjzFShoTN3vRnZ8SlhEnIQJZq7li8sbv/btyAqwkSA8KGhs8e4PCP2NB8cWwULM gI2g== 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=641ZQ62QcXCJJGkjUsQ/2YdhJjKQVUZVVotRuU3jGN0=; b=sOZC54sCT0D46PaV2cBUJI4Jj9Ss8Gj/TEDRbNSkX0fStJ9kRByndxhUM3kzqFzu0Z PkaV8pSp66rkLEa7ySNIQU1ez2naxZiHr5MF89LX6fShybuQbi0D1QA/60JQFUwwmuPj +SXpK6P9dpQbvtTYukrszy1RruB6PucpgWIpjUc2GFIj6TUGKCK2Tv3/x190kfzoxiTP n6J37+7LybJ0OaXV0lU3s+6YWn1ofk99IURGCC8dJZwJpfVyLaodWgR/L0/S4hWoCiqK U6fzB++DZRLJtjTmW5u4xdTnmw2pysOGUH8FhntjSd8DM5qUkUz3SoD03RmUSETCZyn7 t80Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lfjbruLd; 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 ss27si11698919ejb.322.2021.03.15.11.28.23; Mon, 15 Mar 2021 11:28:51 -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=lfjbruLd; 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 S235061AbhCOO3Y (ORCPT + 99 others); Mon, 15 Mar 2021 10:29:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232978AbhCOOA1 (ORCPT ); Mon, 15 Mar 2021 10:00:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEF2964F1A; Mon, 15 Mar 2021 13:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816800; bh=7FnpRKc4Wvba20HFD+Q6GPJu64JtwqjEycgRBK0bmhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lfjbruLd4pp73CMJqMSqeRuzfdYh/z2RT7Isafl6N5QaKduS/2OApT7ldTK6ZTQRY nAQr7lXvq1EQL9HhPW39rqHQx4herKCB4ieBvBKcrCODAxt7wys2/szGPu2Mw/FmjG vujGgDZNy+kLWnX9QahzEZ+jGBGPZ0UoQxF3ACLE= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , Shuah Khan Subject: [PATCH 5.4 119/168] usbip: fix stub_dev to check for stream socket Date: Mon, 15 Mar 2021 14:55:51 +0100 Message-Id: <20210315135554.270235407@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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: Greg Kroah-Hartman From: Shuah Khan commit 47ccc8fc2c9c94558b27b6f9e2582df32d29e6e8 upstream. Fix usbip_sockfd_store() to validate the passed in file descriptor is a stream socket. If the file descriptor passed was a SOCK_DGRAM socket, sock_recvmsg() can't detect end of stream. Cc: stable@vger.kernel.org Suggested-by: Tetsuo Handa Signed-off-by: Shuah Khan Link: https://lore.kernel.org/r/e942d2bd03afb8e8552bd2a5d84e18d17670d521.1615171203.git.skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/stub_dev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/drivers/usb/usbip/stub_dev.c +++ b/drivers/usb/usbip/stub_dev.c @@ -69,8 +69,16 @@ static ssize_t usbip_sockfd_store(struct } socket = sockfd_lookup(sockfd, &err); - if (!socket) + if (!socket) { + dev_err(dev, "failed to lookup sock"); goto err; + } + + if (socket->type != SOCK_STREAM) { + dev_err(dev, "Expecting SOCK_STREAM - found %d", + socket->type); + goto sock_err; + } sdev->ud.tcp_socket = socket; sdev->ud.sockfd = sockfd; @@ -100,6 +108,8 @@ static ssize_t usbip_sockfd_store(struct return count; +sock_err: + sockfd_put(socket); err: spin_unlock_irq(&sdev->ud.lock); return -EINVAL;