Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3502292pxf; Mon, 22 Mar 2021 07:55:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4eDZP2NafI4SzVoTAc3hEg06U/Ts9ai9pGFnXCkeO5+um/BjqrBmBZuLgKcUC1szTeiM3 X-Received: by 2002:aa7:d0c2:: with SMTP id u2mr26048892edo.158.1616424929644; Mon, 22 Mar 2021 07:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616424929; cv=none; d=google.com; s=arc-20160816; b=V78UTvQ6Nw1uPO4tnam3ApgiP1xCvInbY3CupAJ8IDI/78/9RXjFcePAtK+spohLT8 HCvl8Vwe7Umzb5ZKEHW1fRGvVA4tdDZbZie9jOoJiqLUEqbx/89DDBt7VBpGcHIfSHV4 j1hTz+s8rP+yMd76xlzB/EBlGQ96OYvZl/xKj/lf04B8Qef7j+tWvPvxELU1aw3vdj1r /EK1C4Stl+OBPQfCuZ0aaCRSD3TR8qKEC3JW2mxW5fmNEO70bVZQ8dBa5KdOyqSuLI4j fksMADMzn2X+iAHPmsRspe7wIlsIpMXUcC9/PQMWHGxl43odyiQ6U8MwMyiRSU/f0250 c20A== 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=Zh83JkhktP4ysipqS2U23lr0Hw3W6qLosekTGDxh+tI=; b=NL2XS/959ZxRPAZ2+2KQmVMU1Iel2QXWcdWM57uBNL3854m/3KL41vJfjXoxcvARvU RIEDz1WOBqEpZCeTIO4oK+kkH5e/vAaEL2GzmyNmLlPLuDL3Vi2s2Wvt8KRUW/U8UVsC yDaMSzMwRoCGNw3z4PXxqZ8nxfcMFNJbFwwNlUYtHGZTxJk803Rbu//BOhBlBkTFzicT f5Pa4DhFED3NYHVBkdzKHhOXSY6LHMYnGmeVpt0zeby4cxTFZF7r2ZgMD9+UT4K5VSyU xTh4FyCcC3MD0Ce3mZ84dErg3a4ZnmAkOefR/sTMgW4qotTcSdvw8G2ueT2l6cSu+9wv sNUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="cfh/orLx"; 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 m15si12821777edj.170.2021.03.22.07.55.07; Mon, 22 Mar 2021 07:55:29 -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="cfh/orLx"; 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 S231504AbhCVOwL (ORCPT + 99 others); Mon, 22 Mar 2021 10:52:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26530 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231251AbhCVOto (ORCPT ); Mon, 22 Mar 2021 10:49:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616424583; 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=Zh83JkhktP4ysipqS2U23lr0Hw3W6qLosekTGDxh+tI=; b=cfh/orLxmM2HrdyixQM2IFir5bllyPiVuOfdkjiJKRkvjllaKQ+BBrdh/gQ/1RYXRpWYpM cFTMGKtymmsgepRu1aXygILVp/LUyBegVAkSAw66+L5OIRtHcka3C4fcQx5dFTiVn5an7c WHSaBbdjbuybMlUsbZ3crOk2B5Sljuw= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-SZ9N214nNGCZBlJR7cVs2w-1; Mon, 22 Mar 2021 10:49:40 -0400 X-MC-Unique: SZ9N214nNGCZBlJR7cVs2w-1 Received: by mail-ej1-f71.google.com with SMTP id mj6so20029491ejb.11 for ; Mon, 22 Mar 2021 07:49:40 -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=Zh83JkhktP4ysipqS2U23lr0Hw3W6qLosekTGDxh+tI=; b=a6bC40iKEtfmKJXaWnizjTh9ASDydYTPdE+ca9solrVnPYul/yS6i15xNAsgZaNcOo KBmQUFRObB6eYrCLJ9iUNdP5sxfRs0v46hyoWPgyPCaz7hBZTX3f8SkWkGc1zE81XUZ8 p5scHndQwhgN7cJIuWOJzdpbXnOF/G0cHd/U/84Kz5Pih6W2phwqCD2nJ4cpsSXLnTm3 3m5R4EyxPcTHPkLiB06kDBKEqimbLsfhQ80dqq8EkaeebhymeO3zGxbjBH0vScynryOi CHpCaA3wQ1dLOELl9kNdmLqB3wIaJVcg71B/blXusRXxde0Nvb0xe5RwGyzI8NCT8+UZ /y7A== X-Gm-Message-State: AOAM532+nUyvVqxDvK3at5fD9G0LmVMEQ/Ir09tlMHHAZPcWfGcSxNO6 VxqINzxZokcW4SRHHL0K+aDNWXqYTaFbd0TtHKy71ZS+2/zdi6HeuxFBwiFOBMXo2JKRHvabWVm isU6grQfIz07T2luHdW8kG1HX X-Received: by 2002:a17:907:7684:: with SMTP id jv4mr93170ejc.231.1616424579025; Mon, 22 Mar 2021 07:49:39 -0700 (PDT) X-Received: by 2002:a17:907:7684:: with SMTP id jv4mr93152ejc.231.1616424578911; Mon, 22 Mar 2021 07:49:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 07:49:38 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Al Viro , linux-kernel@vger.kernel.org, Christoph Hellwig , Richard Weinberger Subject: [PATCH v2 17/18] ubifs: convert to miscattr Date: Mon, 22 Mar 2021 15:49:15 +0100 Message-Id: <20210322144916.137245-18-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: Richard Weinberger --- fs/ubifs/dir.c | 2 ++ fs/ubifs/file.c | 2 ++ fs/ubifs/ioctl.c | 74 ++++++++++++++++++++---------------------------- fs/ubifs/ubifs.h | 3 ++ 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index d9d8d7794eff..ed9a3127fcd9 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1637,6 +1637,8 @@ const struct inode_operations ubifs_dir_inode_operations = { .listxattr = ubifs_listxattr, .update_time = ubifs_update_time, .tmpfile = ubifs_tmpfile, + .miscattr_get = ubifs_miscattr_get, + .miscattr_set = ubifs_miscattr_set, }; const struct file_operations ubifs_dir_operations = { diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 0e4b4be3aa26..90bad37ed060 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1648,6 +1648,8 @@ const struct inode_operations ubifs_file_inode_operations = { .getattr = ubifs_getattr, .listxattr = ubifs_listxattr, .update_time = ubifs_update_time, + .miscattr_get = ubifs_miscattr_get, + .miscattr_set = ubifs_miscattr_set, }; const struct inode_operations ubifs_symlink_inode_operations = { diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index 2326d5122beb..87a423ee09bc 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -14,6 +14,7 @@ #include #include +#include #include "ubifs.h" /* Need to be kept consistent with checked flags in ioctl2ubifs() */ @@ -103,7 +104,7 @@ static int ubifs2ioctl(int ubifs_flags) static int setflags(struct inode *inode, int flags) { - int oldflags, err, release; + int err, release; struct ubifs_inode *ui = ubifs_inode(inode); struct ubifs_info *c = inode->i_sb->s_fs_info; struct ubifs_budget_req req = { .dirtied_ino = 1, @@ -114,11 +115,6 @@ static int setflags(struct inode *inode, int flags) return err; mutex_lock(&ui->ui_mutex); - oldflags = ubifs2ioctl(ui->flags); - err = vfs_ioc_setflags_prepare(inode, oldflags, flags); - if (err) - goto out_unlock; - ui->flags &= ~ioctl2ubifs(UBIFS_SETTABLE_IOCTL_FLAGS); ui->flags |= ioctl2ubifs(flags); ubifs_set_inode_flags(inode); @@ -132,54 +128,46 @@ static int setflags(struct inode *inode, int flags) if (IS_SYNC(inode)) err = write_inode_now(inode, 1); return err; - -out_unlock: - mutex_unlock(&ui->ui_mutex); - ubifs_release_budget(c, &req); - return err; } -long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +int ubifs_miscattr_get(struct dentry *dentry, struct miscattr *ma) { - int flags, err; - struct inode *inode = file_inode(file); + struct inode *inode = d_inode(dentry); + int flags = ubifs2ioctl(ubifs_inode(inode)->flags); - switch (cmd) { - case FS_IOC_GETFLAGS: - flags = ubifs2ioctl(ubifs_inode(inode)->flags); + dbg_gen("get flags: %#x, i_flags %#x", flags, inode->i_flags); + miscattr_fill_flags(ma, flags); - dbg_gen("get flags: %#x, i_flags %#x", flags, inode->i_flags); - return put_user(flags, (int __user *) arg); + return 0; +} - case FS_IOC_SETFLAGS: { - if (IS_RDONLY(inode)) - return -EROFS; +int ubifs_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma) +{ + struct inode *inode = d_inode(dentry); + int flags = ma->flags; - if (!inode_owner_or_capable(&init_user_ns, inode)) - return -EACCES; + if (miscattr_has_xattr(ma)) + return -EOPNOTSUPP; - if (get_user(flags, (int __user *) arg)) - return -EFAULT; + if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS) + return -EOPNOTSUPP; - if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS) - return -EOPNOTSUPP; - flags &= UBIFS_SETTABLE_IOCTL_FLAGS; + flags &= UBIFS_SETTABLE_IOCTL_FLAGS; - if (!S_ISDIR(inode->i_mode)) - flags &= ~FS_DIRSYNC_FL; + if (!S_ISDIR(inode->i_mode)) + flags &= ~FS_DIRSYNC_FL; - /* - * Make sure the file-system is read-write and make sure it - * will not become read-only while we are changing the flags. - */ - err = mnt_want_write_file(file); - if (err) - return err; - dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags); - err = setflags(inode, flags); - mnt_drop_write_file(file); - return err; - } + dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags); + return setflags(inode, flags); +} + +long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + int err; + struct inode *inode = file_inode(file); + + switch (cmd) { case FS_IOC_SET_ENCRYPTION_POLICY: { struct ubifs_info *c = inode->i_sb->s_fs_info; diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 7fdfdbda4b8a..f577cee6c548 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -2053,6 +2053,9 @@ int ubifs_recover_size(struct ubifs_info *c, bool in_place); void ubifs_destroy_size_tree(struct ubifs_info *c); /* ioctl.c */ +int ubifs_miscattr_get(struct dentry *dentry, struct miscattr *ma); +int ubifs_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma); long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); void ubifs_set_inode_flags(struct inode *inode); #ifdef CONFIG_COMPAT -- 2.30.2