Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3524498pxf; Mon, 15 Mar 2021 11:28:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIUyV7bD4jfTRXS4MXgr7R8sodVFVjIWCt58cqFOFgZzBhWIpu1oi7lDpuC0CEUEhCMawF X-Received: by 2002:aa7:d5c9:: with SMTP id d9mr32588042eds.102.1615832925758; Mon, 15 Mar 2021 11:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832925; cv=none; d=google.com; s=arc-20160816; b=t5gTSra9WEb9Iu8GHhEcIseBq7zBB/Mq7vtCvsjPhjTCTJl13O+TM6ePy+FUfk7rbp PfHz77o7d3kYO5eZzUq+V4STsIq+11UNbDfpssFkXvuZfV4JTvV4lFkMu6xFMWOMdG+Q wExCA4S5VgHC6mQFxEBIcEvGBucbtOSIAzb7NFgwgjxq+ADN2yely0+mF6uRvZ6NuS7/ vXiyUnpJWhl/tTtggr3P/+Xr9VleCP3QCVthDqE3qA4V7q2NSvqtncswJ7APwonAbsow HlBgGtiKf+1vkmRjifoRdCIWBB+ES0rngXhT0xIQa+td1sCAF99joQlgnJZCfbE1T7SL 3RfQ== 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=DvKBeAczhgfg0D5f/xGCDptPMIRMTCxNwzadjhwcEHuO1xr1EPgvIDMlzK5VSPZusZ ze/XyGePKiP2zltwsgmMzdK7OIm8t8PxvONmoq66DgeFuFpHfZR5jV6OkV+TMPtUaY7j Nk0rnntc6jijGHgI8mj79kz5xgzRd++VdJBGwux9NnOO6503XXhRS4Ol5AQ25P/huime KK5VfwFu/T+BhozYFQuvkJ139OjosQSXJqVIRx41cG/Xl/TUy3IG7JR1p4N/LKVJwsFm BUFGjqD1nY+b6yWh5ZtrBNZ2I9eEpEmCuLZitICWHyBWDdTe9fNeIkpNNo53pRc77cdb BqNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="YTaylO/I"; 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 k19si11829393eja.265.2021.03.15.11.28.16; Mon, 15 Mar 2021 11:28:45 -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="YTaylO/I"; 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 S234670AbhCOO3P (ORCPT + 99 others); Mon, 15 Mar 2021 10:29:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233008AbhCOOAd (ORCPT ); Mon, 15 Mar 2021 10:00:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E2AAA64F39; Mon, 15 Mar 2021 14:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816810; bh=7FnpRKc4Wvba20HFD+Q6GPJu64JtwqjEycgRBK0bmhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YTaylO/I52wF0c1TkTmyQKaWH+m3M6tuQ2WvVY6bHNh4OxQ1trE7FBKLrPqMyBIlX A9FzdptJVjJgEbAtMnYC7VMnouF4Gt/YXE6I7qYVtcJWp0KIcLRFM6JGy2z7sFvho0 c3XX823I2jcmOISa+0y4RpVsUHqdfv2m5pYaGTz0= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tetsuo Handa , Shuah Khan Subject: [PATCH 4.19 083/120] usbip: fix stub_dev to check for stream socket Date: Mon, 15 Mar 2021 14:57:14 +0100 Message-Id: <20210315135722.680996357@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135720.002213995@linuxfoundation.org> References: <20210315135720.002213995@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;