Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4886540imm; Tue, 7 Aug 2018 08:58:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcZ+O2E1STD0xwYKyP4VC6k9qXZBFy8B/3l/8BDwo4mK45sHyLGXTif5BWc3fgp1pnP6jyM X-Received: by 2002:a63:5922:: with SMTP id n34-v6mr19407351pgb.113.1533657494082; Tue, 07 Aug 2018 08:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533657494; cv=none; d=google.com; s=arc-20160816; b=uN0iEmTLzW2SXEc+GCnjVrVOm60Uwczut45Zus2UwSKb20t4FE8F2t7qZChxw5ijYS hv0/+qz24Fiab4OuEl0jBVFT1TowZNg+3nbk1kBUpSgn/FIasRKnxhBFRwTFcqdR1DeI 8r7D52TYNWNjHVYys80JWVV3pg4IrTMWpZ8vZU2Enfjloe3OhoPNTIY4UzVX8N+WvfLX 4Cm62tkbpfN69e0HLWz7v6ZyFVCF3FYFqnop2qBg4q73ZGlzXheD0CL/kidiTECUJI5H EfcwF6ZfX7qQ0O9soPiah0W8iWtsgc5Od0qEe4DW9mSqhInxS5DItwYIU3aXBxvMdWTi mO/Q== 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=733K17huAoIxn2n2AhVUqN5PTTz8MC64wplXWBoTp5Y=; b=gfpNLiYXt8FLVLTRQNxH2Q1ofwUNEMxUEEqzeV43mPXC40qUQ8L1snghzpygJtzRkL U/ejUuVqT6S7133Pi4XfbKR1JXJN1Lw4zGhX+Ix2FKr5zbEwpgn8oB2EHWLWbgJ9dOWq YblGytQQRrAZ9M9uwLKXPc4i1Emil+vYOyJmWurpM7qp1IftT+5fYYCyjLYmy31Jh05S 99+hNte18WCxKGDnGqpACCY4qHwYchHi7fbvhkBfkLaD8MRZIK5N8u3UdOAQHqWce0NP oEPbmj7ZJOJDcJYWNy6wHWvwshcffCj7R/Ifuwh0jbGdU0yV3Y4Mi/E+/mpJTW10jJvX vm+g== 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 77-v6si1718933pfh.332.2018.08.07.08.57.59; Tue, 07 Aug 2018 08:58:14 -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 S2389351AbeHGQJW (ORCPT + 99 others); Tue, 7 Aug 2018 12:09:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:46950 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389241AbeHGQJW (ORCPT ); Tue, 7 Aug 2018 12:09:22 -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 BA06FAE2C; Tue, 7 Aug 2018 13:54:54 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id B2C771E3C4F; Tue, 7 Aug 2018 15:54:53 +0200 (CEST) Date: Tue, 7 Aug 2018 15:54:53 +0200 From: Jan Kara To: Andrew Morton Cc: Jan Kara , Chengguang Xu , 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: <20180807135453.nhatdtw25wa6dtzm@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180806155927.4740babd057df9d5078281b1@linux-foundation.org> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Honza -- Jan Kara SUSE Labs, CR