Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3527881pxf; Mon, 15 Mar 2021 11:33:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6oZlsVz03E/pCss/Fin8khvf48mB4OHl++/wjJ6EqBk51kG/nWy1lb5oACoQBfof8E3TY X-Received: by 2002:a17:906:b286:: with SMTP id q6mr25443705ejz.422.1615833194783; Mon, 15 Mar 2021 11:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833194; cv=none; d=google.com; s=arc-20160816; b=KeZCMf08R4qjtiTaTyJuaCkqVKI01wv+dy9HKPnzSX1RudJGvxtyDKs4YKGhmF8Q0K WNGW2n0pq5+5r6792hYYKUGqHvTnjqxYG1BeUfNB7ugssH64hGs2FzkPSy8+ZhZcI9rl FJmAXaDEnk/BaCKC4m4rTA1PC+muLrv3pJ3hIZBcOQ+o59NTismk+5cgHpOGVp0ggprx QeGqd/VvF4b5hVCfmQ5/Q55fsVfVUTkLNJXIlCwaRsomIpAlvpRExd4fALy2r4d5B9Cj DZPdGvhw7wbHTl7YsyiRoo4cYp4Q7DN1IgV07L3GOqDvd7zdYKZrjiXWIrklvKf31wnI lJ2w== 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=piQuZntpL+TmBbkstR7otzclPFi37zwJBq5uNLwUbwa1KT7m6c7w7i/TC+1hkTluzu rsP0YdG65ysXJ8zHgT9cqfqCPR9x05Hecq1H2DpAzOcG8Q1EIfyuIB55j+VGlFQBd7yc G/IzR0v9gsvZozYAbGG+CrfGLPrL97mx1t3y7uqRh2UhlnvtIN9J0REqWJh07Nv2T3x/ wmlksRFZct7ugPzyoKL3kyHg4qw1e7cR4w8lod/YJ751FOUCrRauqXrXjRbYDeEQCNh6 wpz7VRKSaIR0w28szKK61mq5yaC2JF+l+4udM88uXeJYZftUVxAmN1kGFPZViEybN5Cd gpfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=en9ddTJI; 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 b9si11293272ejg.509.2021.03.15.11.32.52; Mon, 15 Mar 2021 11:33:14 -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=en9ddTJI; 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 S236176AbhCOOjS (ORCPT + 99 others); Mon, 15 Mar 2021 10:39:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbhCOOCS (ORCPT ); Mon, 15 Mar 2021 10:02:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB91F64F2C; Mon, 15 Mar 2021 14:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816934; bh=7FnpRKc4Wvba20HFD+Q6GPJu64JtwqjEycgRBK0bmhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=en9ddTJId0l8SEvzlZr/Nm7ODgP3P4BVsm2yTIB0twc27r+buhRDA9+KXv3nOKDXW ZgjbOlRU/kKH/1Rbp7idTwDUzTfcKVuU3Z6BaIY3wDXZNBtMN6H2SHLI3cptOirYYR fhsMZgfyIBxRaoaC7U92bHkr/+5EfDuHj0InKghY= 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.11 212/306] usbip: fix stub_dev to check for stream socket Date: Mon, 15 Mar 2021 14:54:35 +0100 Message-Id: <20210315135514.795120969@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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;