Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp167078ybt; Tue, 7 Jul 2020 19:20:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt+srF7rEIW1+AmNG7JkOB+hKzufpmM+DBQHfoUTNKUQpO5KkSYF3RrP2JfP+0iaNX63ks X-Received: by 2002:a17:906:c201:: with SMTP id d1mr43097257ejz.40.1594174854892; Tue, 07 Jul 2020 19:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594174854; cv=none; d=google.com; s=arc-20160816; b=UoYi43LsxA5M+HdOF5xv8M6v9wDWG6MifKQZcvi658tR+6Y6wX62DjPvTpYKZflDpN 5/dcXxBOXFvDUJ9eAzVfGHQBvu/nnyAKXPqpl62KHeYHgjeJ84pmkrxbXHHPfexobqby uBuGeFH29j6zHeIM2X9suSPesRSampBjsQ3L9x6vAiyRlwSyxsRPEq0FBH2QR7PeWoHp L9Os78cu8wXoDK7ObwZ/G0HsdSakj6TQuwq2jJOlQZgwwq9BrR0e43+br29iYG/LSnQK DREXS0QdSVLfA73IAgp+mVvrR/uGCPoHjhY7d3VMVNrS8z8p/dyDZr4kggA2IinTO0Mj q/vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Ji/pvoJnruxZ5NTjsh4X71yxAbd7TNOpl18z5+X561M=; b=YEDJjgiI+pLIienKZBw9Q/lYal8+LGEekHYRfBoo4x2+52g4SSKKXTt8oMnEsM68Q6 EvUPCQBS8Xxek7V8AZLTXA/lSGXalxV1+2EqsaXuonpR+sItqNBNa8wq1JpPFNAQwnUB 78Wt2jCTAJMwSin8rkhj8pJ01ASgP2ceCoHdImMYTjzoUNurYZ81hZ2/y5Ru7U+wGBhf 3j01lZASCKi3Pt6vxBOWl5RGDsmVo3rFmpT4FubmVFeTwSvpLv3nP1n0BC6vKmsl+KrZ WCbmg0+2Ueh2ONvWubUibueVQLFxMvVdfY4EsyzcqTfcvAgYoBl5ZHOw6HT7xt8EmZqe 3HZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qm0NEvdH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si15997021edr.215.2020.07.07.19.20.32; Tue, 07 Jul 2020 19:20:54 -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=Qm0NEvdH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729303AbgGHCSZ (ORCPT + 99 others); Tue, 7 Jul 2020 22:18:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:38986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728479AbgGHCSZ (ORCPT ); Tue, 7 Jul 2020 22:18:25 -0400 Received: from sol.localdomain (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 2F15720708; Wed, 8 Jul 2020 02:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594174705; bh=tmDaVR1PNrJoafm9vwgEyEGPyx5FVMi3bRneTLieczc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qm0NEvdHgBIvBYQ0kZRa9x8UC5hkczTLyfUPIZtS4ULBj+sQfa9A5Z27URXj1jJvf RUslpdDbm8ypKaJ8FhMNxWW2eq09Q3TCg7uN7eJ6r2DwgffiICQRSzPCAA9mG5rEFg QMMPAobt7Sa+Opu8cuWkX8xa0c1cacPM6oF/YtV8= Date: Tue, 7 Jul 2020 19:18:23 -0700 From: Eric Biggers To: Daeho Jeong Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH v4] f2fs: add F2FS_IOC_SEC_TRIM_FILE ioctl Message-ID: <20200708021823.GJ839@sol.localdomain> References: <20200618125152.84099-1-daeho43@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200618125152.84099-1-daeho43@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daeho, On Thu, Jun 18, 2020 at 09:51:52PM +0900, Daeho Jeong wrote: > +static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) > +{ > + struct inode *inode = file_inode(filp); > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > + struct address_space *mapping = inode->i_mapping; > + struct block_device *prev_bdev = NULL; > + struct f2fs_sectrim_range range; > + pgoff_t index, pg_end; > + block_t prev_block = 0, len = 0; > + u64 end_addr; > + bool to_end; > + int ret = 0; > + > + if (!(filp->f_mode & FMODE_WRITE)) > + return -EBADF; > + > + if (copy_from_user(&range, (struct f2fs_sectrim_range __user *)arg, > + sizeof(range))) > + return -EFAULT; > + > + if (range.flags == 0 || (range.flags & ~F2FS_TRIM_FILE_MASK) || > + !S_ISREG(inode->i_mode)) > + return -EINVAL; > + > + if ((range.flags & F2FS_TRIM_FILE_DISCARD) && > + !f2fs_hw_support_discard(sbi)) > + return -EOPNOTSUPP; > + > + file_start_write(filp); > + inode_lock(inode); > + > + if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) { > + ret = -EINVAL; > + goto err; > + } > + > + if (inode->i_size == 0) > + goto err; > + > + end_addr = range.start + range.len; > + if (end_addr > inode->i_size) { > + ret = -EINVAL; > + goto err; > + } This is missing a check that range.start + range.len doesn't overflow. - Eric