From patchwork Mon Jan 29 09:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13535331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 355D6C47DA9 for ; Mon, 29 Jan 2024 09:49:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C9926B008C; Mon, 29 Jan 2024 04:49:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A0B76B0092; Mon, 29 Jan 2024 04:49:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41AFE6B0093; Mon, 29 Jan 2024 04:49:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 318996B008C for ; Mon, 29 Jan 2024 04:49:41 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DD533A1E45 for ; Mon, 29 Jan 2024 09:49:40 +0000 (UTC) X-FDA: 81731876520.06.1F700AE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 444C218001D for ; Mon, 29 Jan 2024 09:49:38 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McVfDfDi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706521778; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pRcl53v/D7LNYmHWLVDHFLzWMRLsRvElPDySPluG9Xk=; b=uuVQBlFQwcbWxn75ifdi+rJtdq93J3ulXG3jTbklmqsv6ZnizNxakih81Pby2G5ztJUfEv RXWduN9eNqcOjUs3+JJJFqlHpWg4gACYOaPV52KIScWASoO16Z2DUHnFQTPSiEb5t4S/zO q/bv/UdK2BzrH2dmHTqYjSTUuoUqghs= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McVfDfDi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706521778; a=rsa-sha256; cv=none; b=kjS1JfBvdlrVW9cHvNyqc7GPa3wIDPRfASLZx6hg0EuK9K0tfA56OGG1Jvp+haqfC9HEyT PLmPlqHBIbMXb1FqqOWqLpBGqQpgPp0AoZe09Mfc9d9z8BBeMdD/feUeyOpbUYKWBzkjJa 1uIZMUHIKWm0AWj6YBI5Sf+OxgEAbgw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706521777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pRcl53v/D7LNYmHWLVDHFLzWMRLsRvElPDySPluG9Xk=; b=McVfDfDiMQbu66zFjzgLVVcGmgPtragwa3FzkDmp9JAZKsO8Pyu/fxuggEVE+tzGBh2djQ 0uChcaXWu3UwgMub3FJCg7CIvdqhxBlEdpWbZ4tuLuF+Udk28EMnyiV8nz/V7gwAOYRkux YEkBMd5+XM5mzsDIGMawqQZt/EGFza8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-2MqNdY6VNp-CfaPkR9IzXg-1; Mon, 29 Jan 2024 04:49:32 -0500 X-MC-Unique: 2MqNdY6VNp-CfaPkR9IzXg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C0F563C2B606; Mon, 29 Jan 2024 09:49:31 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EF73492BC7; Mon, 29 Jan 2024 09:49:29 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Eric Van Hensbergen , Dominique Martinet , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Marc Dionne Subject: [PATCH 1/2] netfs: Fix i_dio_count leak on DIO read past i_size Date: Mon, 29 Jan 2024 09:49:18 +0000 Message-ID: <20240129094924.1221977-2-dhowells@redhat.com> In-Reply-To: <20240129094924.1221977-1-dhowells@redhat.com> References: <20240129094924.1221977-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 444C218001D X-Stat-Signature: gk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FZY1vD0fdhM3/NA62WEYfEjEDGoWevY1B+MMKayo/9ka+GlG5BjHSC3+nFxtCVA1XQRRLNCcFzJfMVTwRy9n9rMbHd6Vcw16Wn4nVSGzBtSPYqfnVej6XqKE7dzJWdLnvKnx9dgHUJtWN5zjG433GFw4uM+dRc8NTLxtexv1Wk8FUVNOEF5ioOMJv7IfCi38Jihl9pyHd6+ch+47VkKNdXp1Pm2pV+vzxXXReKE/ch8ZqCkIxsuWwv2VkNXIeyEKTKUlHjSDWE4GYVRqMqiGqA6D8qoyzLKDVmXHAcmiUwLROd8BGX0kl/3LPelVKl16cA3unGIiBRnOeeTTM2SgDvkW43YEvU34rwjGSI14ND9KoN7inkdd3WMifE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Marc Dionne If netfs_begin_read gets a NETFS_DIO_READ request that begins past i_size, it won't perform any i/o and just return 0. This will leak an increment to i_dio_count that is done at the top of the function. This can cause subsequent buffered read requests to block indefinitely, waiting for a non existing dio operation to complete. Add a inode_dio_end() for the NETFS_DIO_READ case, before returning. Signed-off-by: Marc Dionne Signed-off-by: David Howells cc: Jeff Layton cc: linux-afs@lists.infradead.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Reviewed-by: Jeff Layton --- fs/netfs/io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index e8ff1e61ce79..4261ad6c55b6 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -748,6 +748,8 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync) if (!rreq->submitted) { netfs_put_request(rreq, false, netfs_rreq_trace_put_no_submit); + if (rreq->origin == NETFS_DIO_READ) + inode_dio_end(rreq->inode); ret = 0; goto out; } From patchwork Mon Jan 29 09:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13535333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8D91C48286 for ; Mon, 29 Jan 2024 09:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C2A96B0093; Mon, 29 Jan 2024 04:49:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 04ACB6B0095; Mon, 29 Jan 2024 04:49:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E06DC6B0096; Mon, 29 Jan 2024 04:49:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C59B66B0093 for ; Mon, 29 Jan 2024 04:49:43 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C01FC095C for ; Mon, 29 Jan 2024 09:49:43 +0000 (UTC) X-FDA: 81731876646.20.CFE5655 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id E4E5C120033 for ; Mon, 29 Jan 2024 09:49:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=flX44zID; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706521781; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ty0Sx4Ua+2bn5g9HXUfTFpOpeFYCT/PUmNHnpETf4uo=; b=ruOmX3ZQdh96BCohyY0lVOeN/ljKTOwVq9KwjDZ1RNaKi4tdXlnvybur9+9VTSB/HHXS/+ 4DidGRhiE1C2ka2ykQtyo3cBbn/KGw+bnbk6IOcZg4lNZ7D1mcNJ3a+iafJUSN+ydUD3nb 2MURBZ/M2TOOJ1GIMIUK+98YTYRRP8o= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=flX44zID; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706521781; a=rsa-sha256; cv=none; b=wyDr1hpUz8XJcu9oy8rVO0updyHVb/Yk7t3i0G+CQagYOX6n15grzBh9ZvVq1lnNIFs6y6 1o7PA0p6IgL72OcvNBVNFwGaVGHybUo0Yw2zHxXTIsVjGIHerpbjJCUJ8mrFlTHRGBapDU eKhmVvNkcEPsK5GetIgybP4eT0ZXJKU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706521781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ty0Sx4Ua+2bn5g9HXUfTFpOpeFYCT/PUmNHnpETf4uo=; b=flX44zIDpBrMoPMl7p0KhvUqaNo5Ato10UXUJNEWMp0ci3G48vuSXjUCRX1vGy2YehLnUq WnvrAl+1JLj8E/3KPduLZZ6WLT1bOzdclJNBa3ZvPMTDD4eeAP1NiRl+SPnoqHmCs4NWOJ 88zDncTsjJ1XtRmwQg9YO/KLgQNOuYk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-X_1LCiW7OoeQwPj1VhB6fQ-1; Mon, 29 Jan 2024 04:49:35 -0500 X-MC-Unique: X_1LCiW7OoeQwPj1VhB6fQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8808688B7A3; Mon, 29 Jan 2024 09:49:34 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79BAB492BE2; Mon, 29 Jan 2024 09:49:32 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Eric Van Hensbergen , Dominique Martinet , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux_oss@crudebyte.com Subject: [PATCH 2/2] netfs: Fix missing zero-length check in unbuffered write Date: Mon, 29 Jan 2024 09:49:19 +0000 Message-ID: <20240129094924.1221977-3-dhowells@redhat.com> In-Reply-To: <20240129094924.1221977-1-dhowells@redhat.com> References: <20240129094924.1221977-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: E4E5C120033 X-Rspam-User: X-Stat-Signature: j87i8m8r3fwjduxuipt5urjb4f845b5c X-Rspamd-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wW2AYZ/aQvt7fLzH7LHUZVUQBX4A9bTnvHHWIcDc/8zGtPB+YVnnHdcQ3pwWSXjUY7xdkAayvuwvdaD6kkgBKQ5LepEP+syXUzIStS+bLYpKEX5yL150wm23t/6G8TOQ+54XDHSXyqRUxvn+mLZFvGJEE45jAY9She1STqCwlOh9y8Q0vZaQfSD75f5qCPjKFmL3qzAsHlGY0wPgq2JNc0I+2h5fddq+9BnKDgdYSVwmC6H1k4zIfj54OGDHkIBd5OQELxG+CsZki7pS+SvHstkJIlpoBt1GsoiEnPa32JgiydAOJ3jAllUGrKFOF+mY9PT2KwKdZ8yZIqeM4gqfCjE5L40 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix netfs_unbuffered_write_iter() to return immediately if generic_write_checks() returns 0, indicating there's nothing to write. Note that netfs_file_write_iter() already does this. Also, whilst we're at it, put in checks for the size being zero before we even take the locks. Note that generic_write_checks() can still reduce the size to zero, so we still need that check. Without this, a warning similar to the following is logged to dmesg: netfs: Zero-sized write [R=1b6da] and the syscall fails with EIO, e.g.: /sbin/ldconfig.real: Writing of cache extension data failed: Input/output error This can be reproduced on 9p by: xfs_io -f -c 'pwrite 0 0' /xfstest.test/foo Fixes: 153a9961b551 ("netfs: Implement unbuffered/DIO write support") Reported-by: Eric Van Hensbergen Link: https://lore.kernel.org/r/ZbQUU6QKmIftKsmo@FV7GG9FTHL/ Signed-off-by: David Howells cc: Dominique Martinet cc: Jeff Layton cc: v9fs@lists.linux.dev cc: linux_oss@crudebyte.com cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org Reviewed-by: Jeff Layton Tested-by: Dominique Martinet --- fs/netfs/buffered_write.c | 3 +++ fs/netfs/direct_write.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index a3059b3168fd..9a0d32e4b422 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -477,6 +477,9 @@ ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) _enter("%llx,%zx,%llx", iocb->ki_pos, iov_iter_count(from), i_size_read(inode)); + if (!iov_iter_count(from)) + return 0; + if ((iocb->ki_flags & IOCB_DIRECT) || test_bit(NETFS_ICTX_UNBUFFERED, &ictx->flags)) return netfs_unbuffered_write_iter(iocb, from); diff --git a/fs/netfs/direct_write.c b/fs/netfs/direct_write.c index 60a40d293c87..bee047e20f5d 100644 --- a/fs/netfs/direct_write.c +++ b/fs/netfs/direct_write.c @@ -139,6 +139,9 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from) _enter("%llx,%zx,%llx", iocb->ki_pos, iov_iter_count(from), i_size_read(inode)); + if (!iov_iter_count(from)) + return 0; + trace_netfs_write_iter(iocb, from); netfs_stat(&netfs_n_rh_dio_write); @@ -146,7 +149,7 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from) if (ret < 0) return ret; ret = generic_write_checks(iocb, from); - if (ret < 0) + if (ret <= 0) goto out; ret = file_remove_privs(file); if (ret < 0)