Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp178189ybg; Tue, 9 Jun 2020 20:19:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJNprWglDiPFNrH3fJRPr4F+lEKAVi9petGZBZR1G4AkwklcWchoJIHP7iP3yIf4xm754p X-Received: by 2002:a17:906:1c8c:: with SMTP id g12mr1366820ejh.456.1591759149037; Tue, 09 Jun 2020 20:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591759149; cv=none; d=google.com; s=arc-20160816; b=JTCTmXSJMsbDCiHGyair09tQYa/knDGpiLAC0jTQopyymRMu+xr+ZtyNAkTReqiDFH R9MtmM6Jbhrhb1+5k3ivyb8Sj6joJEpQPigELElUD99O0UlMRePuu0Up2I8P0UW++tw0 CMJ7fRpBiMjGAkIBjfQ4F1UAwtydTVkHUBxnTOj/kpnYEelhg0QkhE5jl2PT1oqlzkeA c1P8D0PMCyC2xccVLd0QIDNZPgaU3ASHvTvPsVihzWss5PJbWhTqvMltwRMWM536GQxV oWtTNn9wsNwQwFbqCnr8uqMvTY3PJw3AnohhBtR4FE8b2ciu8PsRfyCsMtAa2valuu4+ Emsw== 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=VNv7M7JzeDP5ZGE1uGZ+wTP2q2UpSRb3t2JkltQj0og=; b=oPp+i9ZODLbUbnhRacTTrDYUJ7RPVrum+IYAr735QdlPsrqNJ8JxteqY7uc1kYr1bX HtEYRlT8xjplojyLeqlJdXl1gULchDyYpJ7veDoiA3ebkDkxL9VQE9Y4/aUI8AxCZIhq UsyTP/Yn3Dh+O/RMHs0gvcVf9LiyyNEycpNZffojnKSb6ygiT5ni43v9cSWyKg4PaH52 HLI4XfntK70yHLqlseJ0hJycnDpkTQG8U5WX5tttxDeNoP1xuV1EEpgebhvwy43j/gdu pwJyIGM1qzfSWr0MVseEOVEPjD0BZfYbl5WL7Kupv2rZUOV7Hv6RRlfYI9L0e4uHy0Ye LQfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="XGn/k6VC"; 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 o6si12243288edr.8.2020.06.09.20.18.42; Tue, 09 Jun 2020 20:19:09 -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="XGn/k6VC"; 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 S1726129AbgFJDPe (ORCPT + 99 others); Tue, 9 Jun 2020 23:15:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:54150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbgFJDPe (ORCPT ); Tue, 9 Jun 2020 23:15:34 -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 EB39120734; Wed, 10 Jun 2020 03:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591758934; bh=SlgmI87PFCqpmWyL9oK6/1jzu0E4iRMFU98Dj5JFzPM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XGn/k6VCSvgI9gagRwQGxde4UvqpAnwNzadx5W5FnLiHaKMibfIa1whJni7Yuukf6 Yg89/3q/gjzQjPvbzpKoBTCUnvKdBFtFa9107I73VjK5386bqB5DTtf7iaiBB66f9+ lW7mknkH+OpciUhADsGqY0//X/zo7c9gZRBmGLJo= Date: Tue, 9 Jun 2020 20:15:32 -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] f2fs: add F2FS_IOC_SEC_TRIM_FILE ioctl Message-ID: <20200610031532.GA6286@sol.localdomain> References: <20200609060137.143501-1-daeho43@gmail.com> <20200609165107.GA228564@gmail.com> 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 Wed, Jun 10, 2020 at 11:05:46AM +0900, Daeho Jeong wrote: > > > Added a new ioctl to send discard commands or/and zero out > > > to whole data area of a regular file for security reason. > > > > With this ioctl available, what is the exact procedure to write and then later > > securely erase a file on f2fs? In particular, how can the user prevent f2fs > > from making multiple copies of file data blocks as part of garbage collection? > > > > To prevent the file data from garbage collecting, the user needs to > use pinfile ioctl and fallocate system call after creating the file. > The sequence is like below. > 1. create an empty file > 2. pinfile > 3. fallocate() Is that persistent? So the file will never be moved afterwards? Is there a place where this is (or should be) documented? > > > + > > > + if (f2fs_readonly(sbi->sb)) > > > + return -EROFS; > > > > Isn't this redundant with mnt_want_write_file()? > > > > Also, shouldn't write access to the file be required, i.e. > > (filp->f_mode & FMODE_WRITE)? Then the f2fs_readonly() and > > mnt_want_write_file() checks would be unnecessary. > > > > Using FMODE_WRITE is more proper for this case, since we're going to > modify the data. But I think mnt_want_write_file() is still required > to prevent the filesystem from freezing or something else. Right, the freezing check is actually still necessary. But getting write access to the mount is not necessary. I think you should use file_start_write() and file_end_write(), like vfs_write() does. > > > > > + > > > + if (get_user(flags, (u32 __user *)arg)) > > > + return -EFAULT; > > > + if (!(flags & F2FS_TRIM_FILE_MASK)) > > > + return -EINVAL; > > > > Need to reject unknown flags: > > > > if (flags & ~F2FS_TRIM_FILE_MASK) > > return -EINVAL; > > I needed a different thing here. This was to check neither discard nor > zeroing out are not here. But we still need to check unknown flags, > too. > The below might be better. > if (!flags || flags & ~F2FS_TRIM_FILE_MASK) > return -EINVAL; Sure, but please put parentheses around the second clause: if (flags == 0 || (flags & ~F2FS_TRIM_FILE_MASK)) return -EINVAL; - Eric