From patchwork Thu Feb 28 11:50:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Smelkov X-Patchwork-Id: 10832861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E03A1399 for ; Thu, 28 Feb 2019 12:18:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AEC62DDA5 for ; Thu, 28 Feb 2019 12:18:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 792F72EC34; Thu, 28 Feb 2019 12:18:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,URIBL_GREY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 008712DDA5 for ; Thu, 28 Feb 2019 12:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727781AbfB1MSJ (ORCPT ); Thu, 28 Feb 2019 07:18:09 -0500 Received: from mail179-15.suw41.mandrillapp.com ([198.2.179.15]:19727 "EHLO mail179-15.suw41.mandrillapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726087AbfB1MSI (ORCPT ); Thu, 28 Feb 2019 07:18:08 -0500 X-Greylist: delayed 902 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Feb 2019 07:18:07 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=mandrill; d=nexedi.com; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Date:MIME-Version:Content-Type:Content-Transfer-Encoding; i=kirr@nexedi.com; bh=iLIE2+s+Lsrvvn8hHyzhkql06UI//eKBfPTmhxo3VLs=; b=BnSCADFSIWrSFDw0KLmYMvr3U6rMokdOOLa8pObiMUAe11l/xjNmxjXE1pvDsN++NYDjisfNjaIh 2OWaw+n5idnbSOl1jK/PoQARFybFI1ibHPXwT8cPR+E9+dHlfIL2Pv+9DBJVqZ+UqFdzg7TZ8s4s BY1oNR8ZhRjKmJKSsBg= Received: from pmta04.mandrill.prod.suw01.rsglab.com (127.0.0.1) by mail179-15.suw41.mandrillapp.com id hev8nu22s28n for ; Thu, 28 Feb 2019 11:50:55 +0000 (envelope-from ) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; i=@mandrillapp.com; q=dns/txt; s=mandrill; t=1551354655; h=From : Subject : To : Cc : Message-Id : In-Reply-To : References : Date : MIME-Version : Content-Type : Content-Transfer-Encoding : From : Subject : Date : X-Mandrill-User : List-Unsubscribe; bh=iLIE2+s+Lsrvvn8hHyzhkql06UI//eKBfPTmhxo3VLs=; b=Zaw8yiIiVA1ywcJahjLDIXfREsYIXeqIWiudnMQ7437qssD/M/XkDJle8EmeOhdhGlchw+ g1onP9FHlt/w1KXsKXcXmn7dwkrxIZGhVIN2JBw549Lg+QrFKmpNSIX4pCfJO/2OEqUXK34o 2/QkpQLvled7A5k7k7FEL0/I7PBpA= From: Kirill Smelkov Subject: [PATCH 2/2] fuse: require /dev/fuse reads to have enough buffer capacity as negotiated Received: from [87.98.221.171] by mandrillapp.com id 1773fad30f5642bbb9cb2e8ebefee01c; Thu, 28 Feb 2019 11:50:55 +0000 X-Mailer: git-send-email 2.21.0.352.gf09ad66450 To: Miklos Szeredi , Miklos Szeredi Cc: , , Kirill Smelkov , Han-Wen Nienhuys , Jakob Unterwurzacher Message-Id: <20190228115024.12419-1-kirr@nexedi.com> In-Reply-To: <20190228114757.GA2796@deco.navytux.spb.ru> References: X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=31050260.1773fad30f5642bbb9cb2e8ebefee01c X-Mandrill-User: md_31050260 Date: Thu, 28 Feb 2019 11:50:55 +0000 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A FUSE filesystem server queues /dev/fuse sys_read calls to get filesystem requests to handle. It does not know in advance what would be that request as it can be anything that client issues - LOOKUP, READ, WRITE, ... Many requests are short and retrieve data from the filesystem. However WRITE and NOTIFY_REPLY write data into filesystem. Before getting into operation phase, FUSE filesystem server and kernel client negotiate what should be the maximum write size the client will ever issue. After negotiation the contract in between server/client is that the filesystem server then should queue /dev/fuse sys_read calls with enough buffer capacity to receive any client request - WRITE in particular, while FUSE client should not, in particular, send WRITE requests with > negotiated max_write payload. FUSE client in kernel and libfuse historically reserve 4K for request header. This way the contract is that filesystem server should queue sys_reads with 4K+max_write buffer. If the filesystem server does not follow this contract, what can happen is that fuse_dev_do_read will see that request size is > buffer size, and then it will return EIO to client who issued the request but won't indicate in any way that there is a problem to filesystem server. This can be hard to diagnose because for some requests, e.g. for NOTIFY_REPLY which mimics WRITE, there is no client thread that is waiting for request completion and that EIO goes nowhere, while on filesystem server side things look like the kernel is not replying back after successful NOTIFY_RETRIEVE request made by the server. -> We can make the problem easy to diagnose if we indicate via error return to filesystem server when it is violating the contract. This should not practically cause problems because if a filesystem server is using shorter buffer, writes to it were already very likely to cause EIO, and if the filesystem is read-only it should be too following 8K minimum buffer size (= either FUSE_MIN_READ_BUFFER, see 1d3d752b47, or = 4K + min(max_write)=4k cared to be so by process_init_reply). Please see [1] for context where the problem of stuck filesystem was hit for real (because kernel client was incorrectly sending more than max_write data with NOTIFY_REPLY; see also previous patch), how the situation was traced and for more involving patch that did not make it into the tree. [1] https://marc.info/?l=linux-fsdevel&m=155057023600853&w=2 Signed-off-by: Kirill Smelkov Cc: Han-Wen Nienhuys Cc: Jakob Unterwurzacher --- fs/fuse/dev.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 38e94bc43053..8fdfbafed037 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1317,6 +1317,16 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, unsigned reqsize; unsigned int hash; + /* + * Require sane minimum read buffer - that has capacity for fixed part + * of any request header + negotated max_write room for data. If the + * requirement is not satisfied return EINVAL to the filesystem server + * to indicate that it is not following FUSE server/client contract. + * Don't dequeue / abort any request. + */ + if (nbytes < (fc->conn_init ? 4096 + fc->max_write : FUSE_MIN_READ_BUFFER)) + return -EINVAL; + restart: spin_lock(&fiq->waitq.lock); err = -EAGAIN;