From mboxrd@z Thu Jan 1 00:00:00 1970 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 D7279CDE00F for ; Thu, 26 Sep 2024 15:01:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F1386B0093; Thu, 26 Sep 2024 11:01:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47ABE6B0095; Thu, 26 Sep 2024 11:01:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D5B16B0096; Thu, 26 Sep 2024 11:01:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 06B0C6B0093 for ; Thu, 26 Sep 2024 11:01:19 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7D732141670 for ; Thu, 26 Sep 2024 15:01:17 +0000 (UTC) X-FDA: 82607202594.23.670F8B7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 9937C1A0029 for ; Thu, 26 Sep 2024 15:01:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G71ETbkN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of snitzer@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=snitzer@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727362776; a=rsa-sha256; cv=none; b=4e/zDf1cFMP4kXHWmJB/+oJuhxTkVb5gzEvmIlu6S+U2oJEHfj/DCOmKo0jcQXUaIGOH4d uEZYGRiScw1W+v3Fe6HtYwUhp7RPCrfhj72uScvcHjQCH/vHcSrg5EkzufQgwl+GPOZrMl 0693EgyAuN1RxPQ3E6kdrLRqD6Bi9aI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=G71ETbkN; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of snitzer@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=snitzer@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727362776; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2qXYI/UD83vL8TvfYNNulhx3f0n0CxC7GEHfoUbdkT4=; b=SfBIr1mtRFAc1I+82jtNNwNj/5qhqFScdSw0W6bK1tPRxIrVPR2+Ndofb9n0T3xAzAKO9h 56TbbTF2cnsMU/lrjKg/3LN0sjUzf44GZzfRmY4HCyDcA9yiQcZVwgSmbKZykOOpZPVH5e JuT2ep//bOfs875Eqow793JiCbo9DQE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 84C925C5C79; Thu, 26 Sep 2024 15:01:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3744C4CECD; Thu, 26 Sep 2024 15:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727362873; bh=xt+lwaa8Bhd6R3nAk5b0ke55SJtmalMMKqPtuZLAfeQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G71ETbkNuOvxdCDcYwz1RthpPynvTuSaqF+qzvKT1QXOY4quc8y79x/kV+Dsqli4Z AgYyN/ebZfjIa3T2gVhgXID2u1WLYfO4YlhMfVxZE97hrpoClionXb+C7XExXUYtLS 2T5x13+SfXcfVLVpX281Tex4m3BoR+3ZsVL83Nae6oeqVVfVeUpVwYvkaKulbOGjW1 kROSiaq0bu2NzVMuS8V2QlcRHHizeMW53ysAlMkQjaAjoJS9joBiGe8zDXVAdzJwnS 3zkquPaq6YnbM79fDb2Ol6plnjSDWdlFMOkU8uIA4p11k2UH8smlYuI0+PtweVoMmE sn+KNsFVQ4VJA== Date: Thu, 26 Sep 2024 11:01:11 -0400 From: Mike Snitzer To: Matthew Wilcox Cc: Andrew Morton , linux-mm@kvack.org, trondmy@kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, Dave Chinner Subject: Re: filemap: Fix bounds checking in filemap_read() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9937C1A0029 X-Stat-Signature: 6xjtthu51y84qdkniiq55d943mzp53ca X-Rspam-User: X-HE-Tag: 1727362874-499723 X-HE-Meta: U2FsdGVkX19HJMBO02l2ROkRHEUL5AmWQh/Y3zsMNRktyukfQWIAkJMUHpvms+ngefNZo2lp81d0hMIymbBTpUp0JY3UP4FAaluqsPrQ7OMAoXf+alvAEtnO9DeKJfi8pKFy+uTtltlQrza+BbIFcRVzRGK7E9sk/bsimV1/+lcax26PxV6acN9VR2bPfkVtjBW0DGbf2NaCBfazsJVfYKOdCIGu7BoIRNL1Ke+coNMhKZB6ZFHcgI7Q0981g7rGFJ+gzzNoKDzjemgiOVl56WxmgUk5JS3fXn0/jSbigj64evxUa04Hf/Q4w/1n0w9hKSHwOyHaprE9dytBwRGEXwrer6RVHDp5xTw502PBgOWN21zAG08rBlaqipf8okelTAXAWPlYXypIWYBHNrcrAShmOFv33NHm0wkLeI00ZYbKRLyRLal82O7h1bGH8AFBstKIGSsX5tvGqDcjNcupbvVfxNzhdCHisAb1eSuhAz3kg00Ep+U6+yzOVZBsBrkVRTb2Fg2J6ybbkEtRZ8wBQsb6QdagnqDHbOW0msUThe+sR1oGkP89hI14W/a6Sd/L9HdHj/hCjqLnThzswA4GlqK5sXYqzGVddc+aYj8e0YsR8K+u3MPjcYMqUdkI/+wBpaX0UL2PkZdLWKdLGAldqm0ZnH96MApr6jzbUoNTMczeDpMymyfy4xmTOHs0Vpt2lOcTh9KsDDfWGzJRjgLimlETYwrtWz6PThtIOGuyxkMU662A8Ax2K15hfHvcoxDH2HyJJpHxzunA6B3fJ7XMY7PUOWusVU90hi6DAP83FnOUZJp/wKeyMks8KkeYDuRK8aLjKVNDLuSaK3jiU13yZSfNaZQU6oo981D29CEV82UKje7UCVuYHDiPXdsbbdiUicUEULFurJF+519jTst0IH6opsqnV8nsq2Z4EFjK+x7No5rMhm56wA9o7wnhHezYW5tOyiAO2M/fIVQ0Uu6 hO8I83zn /1TQ7gE67mZQLXOUyRJv+vSJ1WPy/8oDSSeYnP9Ru9+i5y5222tXqKiQzk+4S+UXdFSD2JvnA7WuEorhUuvTLx0oNkLrsJflWJRtbZcVkxCTQQEbud6FW95nMaHA88jMcd8kSUYFfVDUBEkZbgDJ/c6EpIXSZyGkJun7Yr4EjHpi0NPnlYh6bTXi+wId6GC13s5qrMaHkm7+DfKVxkWP3rg/RObrgVtgyyThb8aiFBl0EdCikqTDkHuegkjeiH8gdvGAv9vM6fdassnlL3TsPRvDFCkzO38izZdaW6jWwO6KBsjxScGG52RRs6e7GgphZTkGbSQ1XkGIMgB+viiQnYIBxJF6gYSp8eehq8U4G5ul+/lAQArrj+OPPFejxUYFUF2MBv1msSAPmBaxuR1sqUpGE+KSMw0FdvDU1CBVYIRMVJhnhHSMXUIfZ2CXuxzFp3XwH 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: Hi Willy, On Tue, Sep 17, 2024 at 07:55:29AM +1000, Dave Chinner wrote: > On Fri, Sep 13, 2024 at 07:21:54PM +0100, Matthew Wilcox wrote: > > On Fri, Sep 13, 2024 at 01:57:04PM -0400, trondmy@kernel.org wrote: > > > If the caller supplies an iocb->ki_pos value that is close to the > > > filesystem upper limit, and an iterator with a count that causes us to > > > overflow that limit, then filemap_read() enters an infinite loop. > > > > Are we guaranteed that ki_pos lies in the range [0..s_maxbytes)? > > I'm not too familiar with the upper paths of the VFS and what guarantees > > we can depend on. If we are guaranteed that, could somebody document > > it (and indeed create kernel-doc for struct kiocb)? > > filemap_read() checks this itself before doing anything else: > > if (unlikely(iocb->ki_pos >= inode->i_sb->s_maxbytes)) > return 0; > > i.e. there is no guarantee provided by the upper layers, it's first > checked right here in any buffered read path... > > -Dave. > > -- > Dave Chinner > david@fromorbit.com Linus merged the NFS LOCALIO changes via the NFS client tree a couple days ago. LOCALIO teased out this filemap_read infinite loop bug, so it is important to fix this for 6.12 (probably should get marked for stable@ too): https://lore.kernel.org/all/c6f35a86fe9ae6aa33b2fd3983b4023c2f4f9c13.1726250071.git.trond.myklebust@hammerspace.com/ (weirdly, Trond's reply to you didn't make it to the linux-nfs or linux-fsdevel list archives, but Dave's above reply covers the same) Trond also offered this additional filemap_read negative check: https://lore.kernel.org/all/482ee0b8a30b62324adb9f7c551a99926f037393.1726257832.git.trond.myklebust@hammerspace.com/ Could be you've been busy with travel or whatever, but for future reference, should linux-mm and/or Andrew always be cc'd on filemap fixes? Thanks, Mike