Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3500587pxf; Mon, 22 Mar 2021 07:52:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww4Ch2cuTFlZ4h2xAgkKrvN4qexrOimPulMyp3ktT/wfIT325zI2rjatpBaPdh/yqIUtPq X-Received: by 2002:a05:6402:5113:: with SMTP id m19mr26562791edd.78.1616424776021; Mon, 22 Mar 2021 07:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616424776; cv=none; d=google.com; s=arc-20160816; b=O8nm/10Fri023DDb8v1AhGz76t2n2TtmEB64ZRAGW7i/Fl0Yz6GCoz/bYQqpB7SCcZ RCWmJFvc+zSN9lVRi3fMkzImoclfeAbwjkSDcZPvfKDEzVVasz8Z1aByDV9IvdikSi/L 8WfkI2m01yGs3klMO1jZad7wnFXQ0Qh22KRlVWfjqW26c18yb4IqxhwkE21tkvqX6W25 rqgzdVAOxqlfJJCxMTJaTddG0D/p7tcHsALlmSoCxb0WxgkE3kixYgDNDJy+5qi+9jml D6Kj3P2IhrztZflrq/L7ZH2fit7y46PPfYqen0S2gkh9vd65zBSLUvb5fGIvvBdoW7ZF tlOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5u9SppafS3lTo/ie9QXPmsGSZMKkK44cjZgzUVYcroI=; b=loe7xSanapuYH2x3jDuOMBE/V9xrIi0XxiNCneJ8HYfrXaZNQlJBgHopFxkU4l4tj6 47YMuyx1oQDCswuO1cwzM7KPkfQ66iqPfAs/WLTPm/BAyyDadaEA5Z5Aayu5vDMSyH3W MOPTwgwBq1L/AuqRGIdazxBxpyjLNPDzvy/wmGMizgDreEAnlXYwIIYCqoLNlkoXcIeu r9WN5aP4NxmEUtP2hqUOrGJysKBJVyU2thFEnaQqxe6QSv5OwsQCyD/2n85ueQJcWrEz EGOHS4dV8//WOk0iN35gVXB+MloZ2J5P3cGWaFl8l0G/0y4Fzijb+XdohjCYoiVjJcjd DEcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P4XOGpPN; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v2si11308171ejg.251.2021.03.22.07.52.34; Mon, 22 Mar 2021 07:52:56 -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=@redhat.com header.s=mimecast20190719 header.b=P4XOGpPN; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbhCVOvR (ORCPT + 99 others); Mon, 22 Mar 2021 10:51:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44190 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbhCVOt2 (ORCPT ); Mon, 22 Mar 2021 10:49:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616424568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5u9SppafS3lTo/ie9QXPmsGSZMKkK44cjZgzUVYcroI=; b=P4XOGpPNE7WbGeAcSx6P6UmAvCSVUEQajMk5Pu5K01Wlh//d0KfhHYjKTnzaZGpzjLgLCd T8UF/u/rU6+hBCRChV+KVNJfeRTml84W7NNjBDr7kXBouA725yslYzNNyNqyGXoFYmLxcH X8EsdwsYcWhfh8HGblxb0A2PKJyj2dg= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-4YDro30cMzmX2D84Slb1JA-1; Mon, 22 Mar 2021 10:49:26 -0400 X-MC-Unique: 4YDro30cMzmX2D84Slb1JA-1 Received: by mail-ed1-f72.google.com with SMTP id w16so27574631edc.22 for ; Mon, 22 Mar 2021 07:49:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5u9SppafS3lTo/ie9QXPmsGSZMKkK44cjZgzUVYcroI=; b=WKWaWfcp2wtQHYvZRkMsfwKjQ3sLoncOtNNMCK58ygF6pDuqYfH0plv6dnGmCacgk1 iYO0LWdkCExa9+yYeOjbWNMEfJxoUBjjShUcN24vyaWkQUrjnaRsH5VRyXqKWUhq4Pxp JbrTQ8TFBdtICGX9DBhSYqtvILVkXgmb1dTT01vYliDGRGoK8y5BaVH4w2jLia9Gf5RA ZEu5LYsXE3ossVm714kjVgyDaSq0lFkYVSzYo/aq/yLQCUp826qr6vu07r1X8aaYZtCC 6BilEiN/awSc/qflhQInkCty8jYmQ99CUTUHC6aRvb5Vi835NeksqD6HY+rUPewI4zrt DYQw== X-Gm-Message-State: AOAM530P8bU3qfvNgT1XePBHM4KzGK8Wgrh9PNNTjbqith4NMxAIsIfh ZArXrJKMWrUIERfKbU0XuSykmwdOqbjXNUVFayNxRlaU69sRsONifxYqqQi2ZAiuZ1qMJIFwgej cocatTmsQqylEQOSAujEcRITu X-Received: by 2002:a17:907:7684:: with SMTP id jv4mr92162ejc.231.1616424565058; Mon, 22 Mar 2021 07:49:25 -0700 (PDT) X-Received: by 2002:a17:907:7684:: with SMTP id jv4mr92149ejc.231.1616424564916; Mon, 22 Mar 2021 07:49:24 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-86-101-169-67.catv.broadband.hu. [86.101.169.67]) by smtp.gmail.com with ESMTPSA id r4sm9793117ejd.125.2021.03.22.07.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 07:49:24 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Al Viro , linux-kernel@vger.kernel.org, Christoph Hellwig , Jan Kara Subject: [PATCH v2 05/18] ext2: convert to miscattr Date: Mon, 22 Mar 2021 15:49:03 +0100 Message-Id: <20210322144916.137245-6-mszeredi@redhat.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322144916.137245-1-mszeredi@redhat.com> References: <20210322144916.137245-1-mszeredi@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the miscattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi Cc: Jan Kara --- fs/ext2/ext2.h | 7 ++-- fs/ext2/file.c | 2 ++ fs/ext2/ioctl.c | 88 ++++++++++++++++++------------------------------- fs/ext2/namei.c | 2 ++ 4 files changed, 39 insertions(+), 60 deletions(-) diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 3309fb2d327a..b58f27b1412b 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -283,8 +283,6 @@ static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags) /* * ioctl commands */ -#define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS -#define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS #define EXT2_IOC_GETVERSION FS_IOC_GETVERSION #define EXT2_IOC_SETVERSION FS_IOC_SETVERSION #define EXT2_IOC_GETRSVSZ _IOR('f', 5, long) @@ -293,8 +291,6 @@ static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags) /* * ioctl commands in 32 bit emulation */ -#define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS -#define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS #define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION #define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION @@ -772,6 +768,9 @@ extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len); /* ioctl.c */ +extern int ext2_miscattr_get(struct dentry *dentry, struct miscattr *ma); +extern int ext2_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma); extern long ext2_ioctl(struct file *, unsigned int, unsigned long); extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long); diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 96044f5dbc0e..096c03612129 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -204,4 +204,6 @@ const struct inode_operations ext2_file_inode_operations = { .get_acl = ext2_get_acl, .set_acl = ext2_set_acl, .fiemap = ext2_fiemap, + .miscattr_get = ext2_miscattr_get, + .miscattr_set = ext2_miscattr_set, }; diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c index b399cbb7022d..f841d4439c62 100644 --- a/fs/ext2/ioctl.c +++ b/fs/ext2/ioctl.c @@ -16,69 +16,51 @@ #include #include #include +#include - -long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +int ext2_miscattr_get(struct dentry *dentry, struct miscattr *ma) { - struct inode *inode = file_inode(filp); - struct ext2_inode_info *ei = EXT2_I(inode); - unsigned int flags; - unsigned short rsv_window_size; - int ret; + struct ext2_inode_info *ei = EXT2_I(d_inode(dentry)); - ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg); + miscattr_fill_flags(ma, ei->i_flags & EXT2_FL_USER_VISIBLE); - switch (cmd) { - case EXT2_IOC_GETFLAGS: - flags = ei->i_flags & EXT2_FL_USER_VISIBLE; - return put_user(flags, (int __user *) arg); - case EXT2_IOC_SETFLAGS: { - unsigned int oldflags; + return 0; +} - ret = mnt_want_write_file(filp); - if (ret) - return ret; +int ext2_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma) +{ + struct inode *inode = d_inode(dentry); + struct ext2_inode_info *ei = EXT2_I(inode); - if (!inode_owner_or_capable(&init_user_ns, inode)) { - ret = -EACCES; - goto setflags_out; - } + if (miscattr_has_xattr(ma)) + return -EOPNOTSUPP; - if (get_user(flags, (int __user *) arg)) { - ret = -EFAULT; - goto setflags_out; - } + /* Is it quota file? Do not allow user to mess with it */ + if (IS_NOQUOTA(inode)) + return -EPERM; - flags = ext2_mask_flags(inode->i_mode, flags); + ei->i_flags = (ei->i_flags & ~EXT2_FL_USER_MODIFIABLE) | + (ma->flags & EXT2_FL_USER_MODIFIABLE); - inode_lock(inode); - /* Is it quota file? Do not allow user to mess with it */ - if (IS_NOQUOTA(inode)) { - inode_unlock(inode); - ret = -EPERM; - goto setflags_out; - } - oldflags = ei->i_flags; + ext2_set_inode_flags(inode); + inode->i_ctime = current_time(inode); + mark_inode_dirty(inode); - ret = vfs_ioc_setflags_prepare(inode, oldflags, flags); - if (ret) { - inode_unlock(inode); - goto setflags_out; - } + return 0; +} - flags = flags & EXT2_FL_USER_MODIFIABLE; - flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE; - ei->i_flags = flags; - ext2_set_inode_flags(inode); - inode->i_ctime = current_time(inode); - inode_unlock(inode); +long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + struct ext2_inode_info *ei = EXT2_I(inode); + unsigned short rsv_window_size; + int ret; - mark_inode_dirty(inode); -setflags_out: - mnt_drop_write_file(filp); - return ret; - } + ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg); + + switch (cmd) { case EXT2_IOC_GETVERSION: return put_user(inode->i_generation, (int __user *) arg); case EXT2_IOC_SETVERSION: { @@ -163,12 +145,6 @@ long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { /* These are just misnamed, they actually get/put from/to user an int */ switch (cmd) { - case EXT2_IOC32_GETFLAGS: - cmd = EXT2_IOC_GETFLAGS; - break; - case EXT2_IOC32_SETFLAGS: - cmd = EXT2_IOC_SETFLAGS; - break; case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break; diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c index 3367384d344d..c0fd2e025d49 100644 --- a/fs/ext2/namei.c +++ b/fs/ext2/namei.c @@ -427,6 +427,8 @@ const struct inode_operations ext2_dir_inode_operations = { .get_acl = ext2_get_acl, .set_acl = ext2_set_acl, .tmpfile = ext2_tmpfile, + .miscattr_get = ext2_miscattr_get, + .miscattr_set = ext2_miscattr_set, }; const struct inode_operations ext2_special_inode_operations = { -- 2.30.2