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 X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88302C433E0 for ; Fri, 29 May 2020 01:47:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6562020723 for ; Fri, 29 May 2020 01:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390906AbgE2Br5 (ORCPT ); Thu, 28 May 2020 21:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390018AbgE2Brz (ORCPT ); Thu, 28 May 2020 21:47:55 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75466C08C5C6; Thu, 28 May 2020 18:47:55 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jeU7l-00HHZ1-Ef; Fri, 29 May 2020 01:47:53 +0000 Date: Fri, 29 May 2020 02:47:53 +0100 From: Al Viro To: Linus Torvalds Cc: Linux Kernel Mailing List , linux-fsdevel Subject: Re: [PATCH 2/2] dlmfs: convert dlmfs_file_read() to copy_to_user() Message-ID: <20200529014753.GZ23230@ZenIV.linux.org.uk> References: <20200529000345.GV23230@ZenIV.linux.org.uk> <20200529000419.4106697-1-viro@ZenIV.linux.org.uk> <20200529000419.4106697-2-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 28, 2020 at 06:27:36PM -0700, Linus Torvalds wrote: > On Thu, May 28, 2020 at 5:04 PM Al Viro wrote: > > > > if (*ppos >= i_size_read(inode)) > > return 0; > > > > + /* don't read past the lvb */ > > + if (count > i_size_read(inode) - *ppos) > > + count = i_size_read(inode) - *ppos; > > This isn't a new problem, since you effectively just moved this code, > but it's perhaps more obvious now.. > > "i_size_read()" is not necessarily stable - we do special things on > 32-bit to make sure that we get _a_ stable value for it, but it's not > necessarily guaranteed to be the same value when called twice. Think > concurrent pread() with a write.. > > So the inode size could change in between those two accesses, and the > subtraction might end up underflowing despite the check just above. > > This might not be an issue with ocfs2 (I didn't check locking), but .. case S_IFREG: inode->i_op = &dlmfs_file_inode_operations; inode->i_fop = &dlmfs_file_operations; i_size_write(inode, DLM_LVB_LEN); is the only thing that does anything to size of that sucker. IOW, that i_size_read() might as well had been an explicit 64. Actually, looking at that thing I would suggest simply static ssize_t dlmfs_file_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) { struct inode *inode = file_inode(filp); char lvb_buf[DLM_LVB_LEN]; if (!user_dlm_read_lvb(inode, lvb_buf, DLM_LVB_LEN)) return 0; return simple_read_from_buffer(buf, count, ppos, lvb_buf, DLM_LVB_LEN); } But that's belongs in a followup, IMO.