Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1519851pxb; Wed, 4 Nov 2020 11:07:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYJQ/d8hqwwbaEVa/8g1NraOZLNbGquixAit/Gbc5RyBCcYdTrqWBY/6GuHIfNqq/HNOGe X-Received: by 2002:a17:906:1317:: with SMTP id w23mr19390610ejb.120.1604516820140; Wed, 04 Nov 2020 11:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604516820; cv=none; d=google.com; s=arc-20160816; b=aLwP+Se+OHVNCy6+Fcb+vv7SGbJBqcQADGyo53pq7jAtnHp0KRyzLg1RWhUBEgyrFD pMukInVZmEAOncnhQTCWxK9yPpSOjwpALsD0x9F+OpFluCQeij8wvUrlz7AQ+xzeVd2A 2dh11mXKt5yZl4xaNpJWYaX4JwLQt3FSufD2oKJrA9EjGfMKkfpC0FBlYybybiA3qLPg bxde0t0mN8fxR6I34RHyzP36Z69/168vLo6M1+7c0VQUkfdkB1IcLBLxjvXdkQ6iPmjl bMQnNwDZTk5h3YFjIxsLlCQGsmzBr1quVmvzSShNDaPgAcmpm/q9oYh8sSN0JQme2g1D Xzmg== 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=MUyujG+o/uFazLBHHQPbjub0OYd9bRzM587cv8Fplt4=; b=D8dK5O3qNqzYuXz4VufKt6c+0sxygzeym/IsHyThrpEHmHxAjFokL49/JDwc0/lKz5 uM+48oH56noeScyk++GtteH6oGW65cpFYyklATuQb+0aTZg9D3TO/YzpxdvvNlzxl2r6 Jo9vfBcOfkqvnXrzlt+Ga9BZTFVWQ4JMlIfutsO9mQpYZcIVg7A2j3oXluAejPXJBUZY HWjQ9h2AcUlKHFIcw4V4qgO8EmI3tGRMAMmo/3H8onkpkUTUQgmM72ZScX0+sZtrDdh3 +/ibT68CCCwDsr/s3F6AA6ljEIXD8Se9gGf+wIdD4J7xhS5oBYDD7/xQs7o1DMC5hi/o RBRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n7Q3If8p; 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 lf14si1962663ejb.359.2020.11.04.11.06.37; Wed, 04 Nov 2020 11:07:00 -0800 (PST) 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=n7Q3If8p; 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 S1732165AbgKDSBz (ORCPT + 99 others); Wed, 4 Nov 2020 13:01:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:39480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730314AbgKDSBz (ORCPT ); Wed, 4 Nov 2020 13:01:55 -0500 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 DCD93206F4; Wed, 4 Nov 2020 18:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604512915; bh=wXUW33CCdia8aWj2B1exrXaEYZ1hCuHd8oBpvcyoMJ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=n7Q3If8p8K2mQRqrN1dUJltaVQy3W4JMJhMnyK4k1/mqlXg10IbonyhycJTIDMNK7 zByMKMGDWRA0L9J3TKWsxhXmPljH+0S1iNAgGl7ZTgDHU0hoOS0EfpTZVCqUiaYoXb 6pVhsOkKq80hhHFp/YNeikg5OMisOdbFAMaT1gFo= Date: Wed, 4 Nov 2020 10:01:53 -0800 From: Eric Biggers To: Chao Yu Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v2 2/2] f2fs: fix compat F2FS_IOC_{MOVE, GARBAGE_COLLECT}_RANGE Message-ID: <20201104180153.GB846@sol.localdomain> References: <20201104064310.15769-1-yuchao0@huawei.com> <20201104064310.15769-2-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201104064310.15769-2-yuchao0@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 04, 2020 at 02:43:10PM +0800, Chao Yu wrote: > +static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) > +{ > + struct f2fs_gc_range range; > + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); > + > + if (!capable(CAP_SYS_ADMIN)) > + return -EPERM; > + if (f2fs_readonly(sbi->sb)) > + return -EROFS; > + if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg, > + sizeof(range))) > + return -EFAULT; > + > + return __f2fs_ioc_gc_range(filp, &range); > +} [...] > #ifdef CONFIG_COMPAT > +static int f2fs_compat_ioc_gc_range(struct file *file, unsigned long arg) > +{ > + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(file)); > + struct compat_f2fs_gc_range __user *urange; > + struct f2fs_gc_range range; > + int err; > + > + if (unlikely(f2fs_cp_error(sbi))) > + return -EIO; > + if (!f2fs_is_checkpoint_ready(sbi)) > + return -ENOSPC; > + if (!capable(CAP_SYS_ADMIN)) > + return -EPERM; > + if (f2fs_readonly(sbi->sb)) > + return -EROFS; > + > + urange = compat_ptr(arg); > + err = get_user(range.sync, &urange->sync); > + err |= get_user(range.start, &urange->start); > + err |= get_user(range.len, &urange->len); > + if (err) > + return -EFAULT; > + > + return __f2fs_ioc_gc_range(file, &range); > +} It would be better to have __f2fs_ioc_gc_range() handle the f2fs_cp_error(), f2fs_is_checkpoint_ready(), capable(), and f2fs_readonly() checks, so that they don't have to be duplicated in the native and compat cases. Similarly for "move range". - Eric