From patchwork Fri Aug 11 15:18:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9896205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4447A602DA for ; Fri, 11 Aug 2017 15:18:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 362C228BE8 for ; Fri, 11 Aug 2017 15:18:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29EB228C56; Fri, 11 Aug 2017 15:18:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21F4628BE8 for ; Fri, 11 Aug 2017 15:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753114AbdHKPSM (ORCPT ); Fri, 11 Aug 2017 11:18:12 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:50034 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752901AbdHKPSL (ORCPT ); Fri, 11 Aug 2017 11:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=e28cYeHLPQZi8tBtjtrvzbk09QoA9aLge4WF1iwBSZs=; b=fE+9Ov+ATIr6P1sXeRxGM/kxp hTxP3EwxTaBpOaDRQ3J8ep8TgLMkwJmRjfAam8X/ZDwVNexpe8QVecIMXE5VyOLyCz+8p4m62nquH R8+rTWI0HjflUG71UzTecUPJF721gLDdaZdWGu7fC/udVazQ9dUmCDYYvd9D/ZqUrXohEg+RDR1f3 CppR0EcFxPA5eTXUM7jYY4e5CT3ew9+eReobWeUJWXG7kskODKCyn7kgUfWB2853QgBIcAUPBwC04 rjyW3gml92h22MBO96bWvS5AJ9hnA8otOwMlpltJNZiOZJwwqc3LI8UDbv8QbClG8RzscIvndPbtG lStZqxb4A==; Received: from clnet-p099-196.ikbnet.co.at ([83.175.99.196] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dgBhQ-0006NJ-PM; Fri, 11 Aug 2017 15:18:09 +0000 From: Christoph Hellwig To: linux-xfs@vger.kernel.org Cc: pmenzel@molgen.mpg.de, stockhausen@collogia.de Subject: [PATCH] iomap: fix integer truncation issues in the zeroing and dirtying helpers Date: Fri, 11 Aug 2017 17:18:05 +0200 Message-Id: <20170811151805.22896-1-hch@lst.de> X-Mailer: git-send-email 2.11.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the min_t calls in the zeroing and dirtying helpers to perform the comparisms on 64-bit types, which prevents them from incorrectly being truncated, and larger zeroing operations being stuck in a never ending loop. Special thanks to Markus Stockhausen for spotting the bug. Reported-by: Paul Menzel Tested-by: Paul Menzel Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/iomap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/iomap.c b/fs/iomap.c index 039266128b7f..59cc98ad7577 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -278,7 +278,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data, unsigned long bytes; /* Bytes to write to page */ offset = (pos & (PAGE_SIZE - 1)); - bytes = min_t(unsigned long, PAGE_SIZE - offset, length); + bytes = min_t(loff_t, PAGE_SIZE - offset, length); rpage = __iomap_read_page(inode, pos); if (IS_ERR(rpage)) @@ -373,7 +373,7 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count, unsigned offset, bytes; offset = pos & (PAGE_SIZE - 1); /* Within page */ - bytes = min_t(unsigned, PAGE_SIZE - offset, count); + bytes = min_t(loff_t, PAGE_SIZE - offset, count); if (IS_DAX(inode)) status = iomap_dax_zero(pos, offset, bytes, iomap);