Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2927423ybk; Mon, 18 May 2020 11:18:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqNciRWM4pEo1TAdmvYEdrRxBUPSIpdH/HGWIFhI86JaU0N1dRIcnnCnj9VrZa1hoe87/4 X-Received: by 2002:a17:906:eda3:: with SMTP id sa3mr15556213ejb.253.1589825891882; Mon, 18 May 2020 11:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589825891; cv=none; d=google.com; s=arc-20160816; b=y8RA67AgAIM7zQvJi5FD1k/wT0xTEqq/RlezDkpb3xcPhOEOdHWga4fcT/x4vWv3tj HHQzUDf4xObWM09kR03imz4C9StSxjXq+XfMiX5EtuPS4KLApy2PCJpF5i14kOxHknta aLcg7ohKvZNxt4d3BYGAVWk7aoc+QByx7UULYzSSBh91yM55K2W/vCA7T4+Vm3x/eAJd cwY/ANdOf6uHPBPHTbMLDnzXiNgdcsxZthKi5c9R+ltIIfIU7wlsMzO0BjCnvAspnHU0 cZec2r75ZmzlVUjHeLWwFC7GLP1bRn1Wg2i6IvTcwdY5/0Ez3oaWW41ptr4H8DAWtB3f fzSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pwiaipXLdqOajYL8h2Qv2sILc20ahV67N2hgg9WQgTk=; b=1LfwIRbm1i1kR7kbBwi/kobJIErp+ztrNcUH9OVxdvckvr7+Mr9u27u6HOaugmQTvU cIE9+7scOd9+exS2LF93jiSWJCiT7CglIRiAz6EqytDZedLK6Tt17/qiJNGHtaSkteuB hZO+8IOFPCRix1qhgfqqsAEiVjNWEAfffTccNSC6VrPW3W7TKRtWSq5eLoAxSZf63L8Y 0ZB6EIIC/jOoF5sPPism+e1O4SF+r/YrlD5ANg/hEdPQHPZlZcNwEaLj7//GKVGz0utt e1bvMPzfpZDNoCnnUsWc+A/s2rx6BwydG9PlRIQ61pjVXAQvrNI4uFtWKtFH06b7Ipq3 /6oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ws8W+siL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i26si6946386ejk.424.2020.05.18.11.17.48; Mon, 18 May 2020 11:18:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ws8W+siL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732524AbgERSC1 (ORCPT + 99 others); Mon, 18 May 2020 14:02:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:46280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732509AbgERSCY (ORCPT ); Mon, 18 May 2020 14:02:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A62D0207F5; Mon, 18 May 2020 18:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589824944; bh=u9GjzKj/aPiAqe3X8tN9HEszZ3EIsc2zXBSCISpLFQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ws8W+siLZ9H52tW4RTsOZhUech6ihnnlNrW4I5nLzpr9Ln5Wuysn6q1B344n61BVS ktadE0KM2vsxNYBSiVi+/L2e36tzAe704jvpOOFrJJ+djrtGG7QUnxRWHk8OP6zfd5 9DC+7W4YvpsSsmqjCb971+wee70BZcmEBCiSS8k0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ritesh Harjani , Christoph Hellwig , Jan Kara , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 5.6 066/194] fibmap: Warn and return an error in case of block > INT_MAX Date: Mon, 18 May 2020 19:35:56 +0200 Message-Id: <20200518173537.221590529@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173531.455604187@linuxfoundation.org> References: <20200518173531.455604187@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ritesh Harjani [ Upstream commit b75dfde1212991b24b220c3995101c60a7b8ae74 ] We better warn the fibmap user and not return a truncated and therefore an incorrect block map address if the bmap() returned block address is greater than INT_MAX (since user supplied integer pointer). It's better to pr_warn() all user of ioctl_fibmap() and return a proper error code rather than silently letting a FS corruption happen if the user tries to fiddle around with the returned block map address. We fix this by returning an error code of -ERANGE and returning 0 as the block mapping address in case if it is > INT_MAX. Now iomap_bmap() could be called from either of these two paths. Either when a user is calling an ioctl_fibmap() interface to get the block mapping address or by some filesystem via use of bmap() internal kernel API. bmap() kernel API is well equipped with handling of u64 addresses. WARN condition in iomap_bmap_actor() was mainly added to warn all the fibmap users. But now that we have directly added this warning for all fibmap users and also made sure to return 0 as block map address in case if addr > INT_MAX. So we can now remove this logic from iomap_bmap_actor(). Signed-off-by: Ritesh Harjani Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/ioctl.c | 8 ++++++++ fs/iomap/fiemap.c | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 282d45be6f453..5e80b40bc1b5c 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -55,6 +55,7 @@ EXPORT_SYMBOL(vfs_ioctl); static int ioctl_fibmap(struct file *filp, int __user *p) { struct inode *inode = file_inode(filp); + struct super_block *sb = inode->i_sb; int error, ur_block; sector_t block; @@ -71,6 +72,13 @@ static int ioctl_fibmap(struct file *filp, int __user *p) block = ur_block; error = bmap(inode, &block); + if (block > INT_MAX) { + error = -ERANGE; + pr_warn_ratelimited("[%s/%d] FS: %s File: %pD4 would truncate fibmap result\n", + current->comm, task_pid_nr(current), + sb->s_id, filp); + } + if (error) ur_block = 0; else diff --git a/fs/iomap/fiemap.c b/fs/iomap/fiemap.c index bccf305ea9ce2..d55e8f491a5e5 100644 --- a/fs/iomap/fiemap.c +++ b/fs/iomap/fiemap.c @@ -117,10 +117,7 @@ iomap_bmap_actor(struct inode *inode, loff_t pos, loff_t length, if (iomap->type == IOMAP_MAPPED) { addr = (pos - iomap->offset + iomap->addr) >> inode->i_blkbits; - if (addr > INT_MAX) - WARN(1, "would truncate bmap result\n"); - else - *bno = addr; + *bno = addr; } return 0; } -- 2.20.1