Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4481556ybx; Mon, 4 Nov 2019 14:09:13 -0800 (PST) X-Google-Smtp-Source: APXvYqxPUCKtROTDSVFBbKPax/oKeTB4Zsbpf54dREJSvmCiR4bzmSKsvmoKPgeNr8KNbE4IN0t8 X-Received: by 2002:a17:907:1114:: with SMTP id qu20mr6180268ejb.42.1572905353308; Mon, 04 Nov 2019 14:09:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905353; cv=none; d=google.com; s=arc-20160816; b=PlORq8OWjCoHEgNsxW9s9X8e1YB0AJWTaomXGyTMh4pkzbhR8DwKXLm/TpQmaYlZfr RCXtizhscAZeJ49AIw3zx608opICU9ngQs9ig1sWz7IMArabFxrK+9yTXnq+2v6rfvSY Z11ygxhBnrhTejnAYSddVv3loC3fN03+leMZZHBblMGDBYWFUJTuBcbjz8BIDqKcVTSJ dTwSBGC/fhJfQgad5h1px9qEqw2nLTWmzQRmSP2ITDDD6QiUWgcptmAjZV76HCBVnk6+ Pqc4YIrL9nKj7eJuZ0NAT158N06d5Z3Gu/i49v48LKTsLVZlOJ0TglvfjYwlnEHnw7O+ uIdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=85UdwrhrZe+R3MDP5YN4r3tom6lvQgVa+r+gewkpuIc=; b=05FNC7IroB/IlF33BGIT1XuTeEY0/e21eTOCs/RPO3LhysZjTrZ3ah8GcdqnRSNY83 gmlroOI50mrsK68dBXDHwEKSWCuaglHuB+u00MauMskcgT6TAPki0RjGBXDXpz/joPLw +0kwlFmW5AEOnS7Dih5wg+a4Fzi/lG/US9+DOuN4wLFFgqFVve42QuRI0+GtH0GqyNuO 3v/dnKZ3Z/zkGlm53ZnflaN+K1gojYq0jRwU4BwmiknQWQHrlrD+c+BuaElmkGPHyH7A mp1TKrETvIvyH4HpHqOpwPgPGeqOblL9kFSQGEQptY8pACDEZI7v03jmB0kg03a9tZDM hvvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YZB2DSzw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x50si8464909eda.155.2019.11.04.14.08.49; Mon, 04 Nov 2019 14:09:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YZB2DSzw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390045AbfKDWH6 (ORCPT + 99 others); Mon, 4 Nov 2019 17:07:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:40620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390032AbfKDWHw (ORCPT ); Mon, 4 Nov 2019 17:07:52 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3F86A217F5; Mon, 4 Nov 2019 22:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905271; bh=esvI05WfeJ8xMcPciXvLfqVogIyhb3CzOSX/UlFwCyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YZB2DSzwAp8U/W4m71atfR1YOfHhlwXQxQk7UEgPGu7+A333N7Rey96fV1E/obn7A Ax6ahl/ORsspTfUc0YM3/scgzil1Cq8nTdcT7UJwTNXnN66vIT29FsOX10jtF2BE4C O605HtR34YmSoF4vrAlfFmUsrbRFUJuQGkl+sblU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+24c12fa8d218ed26011a@syzkaller.appspotmail.com, "Richard W.M. Jones" , Mike Christie , Jens Axboe , Sasha Levin Subject: [PATCH 5.3 086/163] nbd: verify socket is supported during setup Date: Mon, 4 Nov 2019 22:44:36 +0100 Message-Id: <20191104212146.474325178@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Christie [ Upstream commit cf1b2326b734896734c6e167e41766f9cee7686a ] nbd requires socket families to support the shutdown method so the nbd recv workqueue can be woken up from its sock_recvmsg call. If the socket does not support the callout we will leave recv works running or get hangs later when the device or module is removed. This adds a check during socket connection/reconnection to make sure the socket being passed in supports the needed callout. Reported-by: syzbot+24c12fa8d218ed26011a@syzkaller.appspotmail.com Fixes: e9e006f5fcf2 ("nbd: fix max number of supported devs") Tested-by: Richard W.M. Jones Signed-off-by: Mike Christie Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index bd164192045b0..9650777d0aaf1 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -935,6 +935,25 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx, return ret; } +static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd, + int *err) +{ + struct socket *sock; + + *err = 0; + sock = sockfd_lookup(fd, err); + if (!sock) + return NULL; + + if (sock->ops->shutdown == sock_no_shutdown) { + dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n"); + *err = -EINVAL; + return NULL; + } + + return sock; +} + static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, bool netlink) { @@ -944,7 +963,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, struct nbd_sock *nsock; int err; - sock = sockfd_lookup(arg, &err); + sock = nbd_get_socket(nbd, arg, &err); if (!sock) return err; @@ -996,7 +1015,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg) int i; int err; - sock = sockfd_lookup(arg, &err); + sock = nbd_get_socket(nbd, arg, &err); if (!sock) return err; -- 2.20.1