Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp579101imm; Wed, 8 Aug 2018 01:58:55 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyQIZDeiEI/mr/uISIDlypODYecwU/JlyVyzch/8ZhlhWeZJQR6jIT29NSv8+pO37+3p9Ps X-Received: by 2002:a63:a70f:: with SMTP id d15-v6mr1710571pgf.168.1533718735740; Wed, 08 Aug 2018 01:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533718735; cv=none; d=google.com; s=arc-20160816; b=SnzzI8f8ftZEZ84PM+pJATHRBmUDQNigEnIAME4OUmX7UadGiPuf6Mo3ZcqiKUAEJ4 05EpUJrSOrQmQWCj9Kw8eR7/5jX0Ut46BfBayRcNhovmidJWIrEE3/OW+Z468juo7Nvf hJrHvi2KHxEIfHYbI8mbCoL1CNJhT/6l8wK0iivX6P+sFRg0Bp76to9kgUbDl4Wljd+J qcZA0eBGYLHMvAVSKcLth7BpgkO+/QzWvW41i4FR7jJkut54GUgA9QLnwBS/Kmnc9Yti ON22jHBcaXiUTJ8USwQCWiaYT0se2nSHutqs0b5Loaoq4LJuVnX/7R8reFrA4PBFFGu7 0lpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=7nx+4XJ3PudhYnKMSOemV1US2SOwoMBeI8KOhxuFM0g=; b=IQzv0Tx6dZL5lY08O7VDA4hh5p9gzLyJ14QePkMM0xdWUNa+yEQVSS8HaTILntKpsJ e68ab9sn5SIRRfpydwzAKkD2TOKtln31zrzGbmkgJSnPP8yZRWCPpXoT/FOJFAQ8BXxU eTIYmnL4ofn8lKKL/+kU0yWA2eaJJqeRWe96Q/o2UqAYj9mKNomh0q6TCqzAq79kWpiY NgI5mzYzuFwUJElixIdQvcWfYR77PjtfyazPvT7WDanL3Ko3e/UWHjU+SiLHdKSoKRMO gDenPc2TxFfetPvMq49VUE8VvvgC7RR/Jgcoa9eOPeEJBQD1kxzZRPT32nlDUyHLzlqs mfDw== ARC-Authentication-Results: i=1; mx.google.com; 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 t89-v6si3858232pfe.59.2018.08.08.01.58.40; Wed, 08 Aug 2018 01:58:55 -0700 (PDT) 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; 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 S1727390AbeHHLQe (ORCPT + 99 others); Wed, 8 Aug 2018 07:16:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:39498 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727083AbeHHLQd (ORCPT ); Wed, 8 Aug 2018 07:16:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CB8ABACD0; Wed, 8 Aug 2018 08:57:47 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 383CC1E065A; Wed, 8 Aug 2018 10:57:47 +0200 (CEST) Date: Wed, 8 Aug 2018 10:57:47 +0200 From: Jan Kara To: cgxu519 Cc: Jan Kara , Andrew Morton , mgorman@techsingularity.net, jlayton@redhat.com, ak@linux.intel.com, mawilcox@microsoft.com, tim.c.chen@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Al Viro Subject: Re: [PATCH] mm: adjust max read count in generic_file_buffered_read() Message-ID: <20180808085747.GE15413@quack2.suse.cz> References: <20180719081726.3341-1-cgxu519@gmx.com> <20180719085812.sjup2odrjyuigt3l@quack2.suse.cz> <20180720161429.d63dccb9f66799dc0ff74dba@linux-foundation.org> <20180806102203.hmobd26cujmlfcsw@quack2.suse.cz> <20180806155927.4740babd057df9d5078281b1@linux-foundation.org> <20180807135453.nhatdtw25wa6dtzm@quack2.suse.cz> <7be05929-a5d0-e0b0-9d48-705c3840ee95@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7be05929-a5d0-e0b0-9d48-705c3840ee95@gmx.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 08-08-18 08:57:13, cgxu519 wrote: > On 08/07/2018 09:54 PM, Jan Kara wrote: > > On Mon 06-08-18 15:59:27, Andrew Morton wrote: > > > On Mon, 6 Aug 2018 12:22:03 +0200 Jan Kara wrote: > > > > > > > On Fri 20-07-18 16:14:29, Andrew Morton wrote: > > > > > On Thu, 19 Jul 2018 10:58:12 +0200 Jan Kara wrote: > > > > > > > > > > > On Thu 19-07-18 16:17:26, Chengguang Xu wrote: > > > > > > > When we try to truncate read count in generic_file_buffered_read(), > > > > > > > should deliver (sb->s_maxbytes - offset) as maximum count not > > > > > > > sb->s_maxbytes itself. > > > > > > > > > > > > > > Signed-off-by: Chengguang Xu > > > > > > Looks good to me. You can add: > > > > > > > > > > > > Reviewed-by: Jan Kara > > > > > Yup. > > > > > > > > > > What are the runtime effects of this bug? > > > > Good question. I think ->readpage() could be called for index beyond > > > > maximum file size supported by the filesystem leading to weird filesystem > > > > behavior due to overflows in internal calculations. > > > > > > > Sure. But is it possible for userspace to trigger this behaviour? > > > Possibly all callers have already sanitized the arguments by this stage > > > in which case the statement is arguably redundant. > > So I don't think there's any sanitization going on before > > generic_file_buffered_read(). E.g. I don't see any s_maxbytes check on > > ksys_read() -> vfs_read() -> __vfs_read() -> new_sync_read() -> > > call_read_iter() -> generic_file_read_iter() -> > > generic_file_buffered_read() path... However now thinking about this again: > > We are guaranteed i_size is within s_maxbytes (places modifying i_size > > are checking for this) and generic_file_buffered_read() stops when it > > should read beyond i_size. So in the end I don't think there's any breakage > > possible and the patch is not necessary? > > > I think most of time i_size is within s_maxbytes in local filesystem, > but consider network filesystem, write big file in 64bit client and > read in 32bit client, in this case maybe generic_file_buffered_read() > can read more than s_maxbytes, right? I'd consider this an internal problem in the implementation of the networking filesystem. Not something VFS should care about. It's similar to a normal filesystem loading corrupted file size from disk... Honza -- Jan Kara SUSE Labs, CR