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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 F3960C55196 for ; Fri, 24 Apr 2020 19:17:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C986C21655 for ; Fri, 24 Apr 2020 19:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587755862; bh=VlyxgCrOLgi7dFsPEF6HpMuYuVTTibVbUYAsTqnMBZQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=Xxi8n6wzzyo5iZPhLAm4ZJ350xfUug3HbyGEjd5I8a1eX2tzW6q4iZ4qNez+FCa0y oNfWTX1pM/GD7AvvexqDHHJAeFglK0RCwxY3UPm4oxQitbw2ne1IYNpLW2cPw9gHCq raUCd1DfsnLpbrl3d2NMawIqsgvLGd6pfN44QRfY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727031AbgDXTRl (ORCPT ); Fri, 24 Apr 2020 15:17:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:59544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727022AbgDXTRl (ORCPT ); Fri, 24 Apr 2020 15:17:41 -0400 Received: from gmail.com (unknown [104.132.1.76]) (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 CBA7A20857; Fri, 24 Apr 2020 19:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587755861; bh=VlyxgCrOLgi7dFsPEF6HpMuYuVTTibVbUYAsTqnMBZQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q16C0/hczHcQoc0YoGcJ6bs6EebZRpbQ8HK4F7h4D4AZNQLn/OWJyPdhQJs6i2/fc Eb06SirpvCybURyZWFZ79HsVhUmBdECxZZ6xr2A/tB500s2LPx2Vswg0mzfDN1CNe3 Mhb8LVTWkPmhkEN+hWJVEnqWB5leCOJ4jGD0S9Ls= Date: Fri, 24 Apr 2020 12:17:39 -0700 From: Eric Biggers To: Ritesh Harjani Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, Alexander Viro , "Darrick J . Wong" , Christoph Hellwig , Jan Kara , tytso@mit.edu, "Aneesh Kumar K . V" , linux-ext4@vger.kernel.org Subject: Re: [PATCH 1/2] fibmap: Warn and return an error in case of block > INT_MAX Message-ID: <20200424191739.GA217280@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org On Fri, Apr 24, 2020 at 12:52:17PM +0530, Ritesh Harjani wrote: > 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 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. > > Signed-off-by: Ritesh Harjani > --- > fs/ioctl.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/fs/ioctl.c b/fs/ioctl.c > index f1d93263186c..3489f3a12c1d 100644 > --- a/fs/ioctl.c > +++ b/fs/ioctl.c > @@ -71,6 +71,11 @@ static int ioctl_fibmap(struct file *filp, int __user *p) > block = ur_block; > error = bmap(inode, &block); > > + if (block > INT_MAX) { > + error = -ERANGE; > + WARN(1, "would truncate fibmap result\n"); > + } > + WARN() is only for kernel bugs. This case would be a userspace bug, not a kernel bug, right? If so, it should use pr_warn(), not WARN(). - Eric