Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3354359pxf; Mon, 15 Mar 2021 07:50:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7NOnSsPeBfGCSnI61yLAkha99rhQa7iidKz7Wo71pxew6fzNRfvre5ogCxRA1dv8oaV13 X-Received: by 2002:a17:906:35cf:: with SMTP id p15mr23892230ejb.379.1615819816620; Mon, 15 Mar 2021 07:50:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615819816; cv=none; d=google.com; s=arc-20160816; b=VTv+ChH3nnq5FXpDB0SQCxNz1D6DczKWs1ibQ8oWrvOC0VmV6Wst6poSHQ3emPwgt+ EpUtZqa1Y61h7Dvrb4S98Dy/6dyl/HbjivC0SbVGvsjnD9jeh6zZOULkwKwSZHK1wK2l 7NVkF6ZpBPuBB6I2gTphWUHMPMvEQSWCLo3xkuPTJetNbv68T3j4TNM7TIMlCizSYCvF gJ0HZIGRjap3UZJvBMHp0NT9LOwPYfbMR93+EJN+wEyz3pMGCufPqhpBVIdDVQHQpto4 pOWfWb6O9xDaPliGPDiLUAx8VZ5OV7viFna911ut+IFu6i9UY8iuGg/4vFVBkSjO5qF1 qYiQ== 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=bnR78frwlstBtg8WBEb6n8CFM2DCRSykC6vmKAJvxvE6TWB5XKnRBz2cVUT6vKKd6d twdeO5rr3fcSLZVW2QqkgYyCYcx4HhHk3HAXMrYmqUD/CTCJe1uxZRzToBvmKe1LRFjb FeaoenYbh22N3LLIWrpdXm228KIx7Zz5YKMSvMrtucXhGlDTfXIwHd4Fl3bucEM7sV7e asxG8tORQgQX7Pp3/swR2DZ1Fp+m7iEd61HOaApLQe26GAvjWicaFlS5Q8mzogqp1V75 SQbJNER2Rj0j6VuvrGaVf+iSqg+Id1ySmEuv1ppQRSXFRtHAe0RUjJxC1tjtjQ8/DKLV rVLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JZvEaIFk; 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 bu13si11166413edb.498.2021.03.15.07.49.53; Mon, 15 Mar 2021 07:50:16 -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=JZvEaIFk; 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 S240817AbhCOOsF (ORCPT + 99 others); Mon, 15 Mar 2021 10:48:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:49268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbhCOOCq (ORCPT ); Mon, 15 Mar 2021 10:02:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86C3164EF1; Mon, 15 Mar 2021 14:02:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816964; bh=7FnpRKc4Wvba20HFD+Q6GPJu64JtwqjEycgRBK0bmhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZvEaIFka9dfJ9M0Qizw+0kWfQzInLS1E4TNNFv3jQ2YGfA0E/G3uZkEioJ4GsC/L I0sQ9Jxsx4mcVslmGciwFCRhqQtC2IVIFlnhZngsx6MKeUAPQU965x2GZAQ64v2A1F X/Ccc0qMl6pVMLv6S/UsTQpi75J36Mrl/nfhxilI= 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.10 216/290] usbip: fix stub_dev to check for stream socket Date: Mon, 15 Mar 2021 14:55:09 +0100 Message-Id: <20210315135549.266480936@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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;