Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp262452pxu; Thu, 15 Oct 2020 03:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5vYb+00MwfU6vV0itq0+AUZsAD5dOi6XmtbglzIEwR2Bzv0HDevT3hSa6ITQ/04YqQRsz X-Received: by 2002:a17:906:2714:: with SMTP id z20mr3534793ejc.409.1602757450642; Thu, 15 Oct 2020 03:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602757450; cv=none; d=google.com; s=arc-20160816; b=FMaddvFxCE14CNDzQs1dPJsJUdg2y4RaTYEl2WF/kquiWfk+jymMAP1de14irE384p veVpIyde6dSYmE/dMmBfhg5zifUCK0z+DHgcyoRiNVOENC9dWOxC4RN/vTXwZzeMjWid +kP2ZcTNQslwwueysPg11u5WX81RUxmyiX8L9SRaDRo+1ZkBimYas24g7I1ki5Y6Ge3s SyzMObyFBBI+MxnbP2JKSdDTNFruhngRQXDFbZHht9Cm3DKLBjMoVj/hfXzrMQ0Bm7jw HHQPVJfSPhL4+VlWh3SwtWhgwk1tQxiecoUjKAg+1IATnGVm+Z7o6kQzi8SXmS/zncX8 /1EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EWEj5KWRjJiIOpXhJMkV3ajAjLi3ciMQKv+j5jRQjLA=; b=USKDpEugcW8J/PpG92IVC+aSpYjzbwNY5Tl87qA+O52fygTMoytp1pWRmpLfZgHnZV xvIx1VOy2azo/AWDRaVxCkY/dXPyBHR677lN9PmjA5PMN7HXd41vVO6KcIzd/MY1n17C WPk9hM1UVjhCVHxZdlSfSyGdM7W2PAx596VXdq3gIaO71OcfulQ9Nm8Yl4rqZJAJtreO ldipdo77qRCsVEDYszbXM3ILeHJj+z2YqzCjqxBPqNUfgCXoj60QTSnMhvW9J/kqtDa1 3ms8ZGqLL9w7YmOn/DxxTkPJoGN7IaI0J+WIMf4Qh/SV23bCcnBeUHaE9BhRpmXaTIK2 xxmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aTEkAcFC; 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 33si1736867edr.606.2020.10.15.03.23.48; Thu, 15 Oct 2020 03:24:10 -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=aTEkAcFC; 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 S1728602AbgJOEEo (ORCPT + 99 others); Thu, 15 Oct 2020 00:04:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:55868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725208AbgJOEEo (ORCPT ); Thu, 15 Oct 2020 00:04:44 -0400 Received: from sol.localdomain (172-10-235-113.lightspeed.sntcca.sbcglobal.net [172.10.235.113]) (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 87ABD221FF; Thu, 15 Oct 2020 04:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602734683; bh=SMk+hp4oh3UF1fUl7YouAMOuc2XW5qG6kfSb2Z+uKzA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aTEkAcFC98RK8nCk0vXzifTUJ3hJP1Ne7GhKEoTJNeQrYhKuFSkhH5ub5q5ggFoEQ FMXHmKRyS6SFV9jCFDgUxUhSiH9uhTeHSJxOKPvlgJcC/e8+wcVqOislMv4lQalWOz oJVy5zu4uF2YukTH+5sZ6wtOt7jlZyCgmFDLmKZE= Date: Wed, 14 Oct 2020 21:04:41 -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 2/2] f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl Message-ID: <20201015040441.GA834@sol.localdomain> References: <20201013022429.454161-1-daeho43@gmail.com> <20201013022429.454161-2-daeho43@gmail.com> <20201013061150.GC1062@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2020 at 11:27:30AM +0900, Daeho Jeong wrote: > > f2fs_readonly() is redundant with mnt_want_write_file(). > > > > Also, shouldn't this require a writable file descriptor? As-is, this ioctl can > > be called on a file owned by another user, as long as the caller has read > > access. > > > > Note: if you change this to require a writable file descriptor, then > > f2fs_readonly(), mnt_want_write_file(), and IS_IMMUTABLE() all would no longer > > be needed. > > I agree that f2fs_readonly() is redundant. > But, sorry, I don't get the rest. I thought mnt_want_write_file() is a > way to check whether the caller has a proper write permission or not. > I think just using mnt_want_write_file() is enough for this ioctl. Am > I missing something? mnt_want_write_file() checks for write permission to the mount, not to the file. I think this ioctl wants what f2fs_sec_trim_file() does: if (!(filp->f_mode & FMODE_WRITE)) return -EBADF; file_start_write(filp); inode_lock(inode); ... inode_unlock(inode); file_end_write(filp); After all you shouldn't be able to change the compression options of a file given only read access to it, right? > > I don't think the check for i_writecount == 1 accomplishes anything because it > > just means there are no *other* writable file descriptors. It doesn't mean that > > some other thread isn't concurrently trying to write to this same file > > descriptor. So the lock needs to be enough. Is it? > > This is to detect any possibility of other threads mmap-ing and > writing the file. > Using only inode lock is not enough to prevent them from making dirty pages. Well, as I said, i_writecount == 1 doesn't guarantee that other threads aren't mmap'ing or writing to the file. It just guarantees that there aren't any other writable file descriptors. (Actually, file descriptions.) Multiple threads can be using the same file descriptor (or the same file description) concurrently. - Eric