.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2012 Red Hat, Inc. |
---|
3 | 4 | * Copyright (C) 2012 Jeremy Kerr <jeremy.kerr@canonical.com> |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License version 2 as |
---|
7 | | - * published by the Free Software Foundation. |
---|
8 | 5 | */ |
---|
9 | 6 | |
---|
10 | 7 | #include <linux/efi.h> |
---|
.. | .. |
---|
54 | 51 | } else { |
---|
55 | 52 | inode_lock(inode); |
---|
56 | 53 | i_size_write(inode, datasize + sizeof(attributes)); |
---|
| 54 | + inode->i_mtime = current_time(inode); |
---|
57 | 55 | inode_unlock(inode); |
---|
58 | 56 | } |
---|
59 | 57 | |
---|
.. | .. |
---|
75 | 73 | ssize_t size = 0; |
---|
76 | 74 | int err; |
---|
77 | 75 | |
---|
78 | | - while (!__ratelimit(&file->f_cred->user->ratelimit)) { |
---|
79 | | - if (!msleep_interruptible(50)) |
---|
80 | | - return -EINTR; |
---|
81 | | - } |
---|
| 76 | + while (!__ratelimit(&file->f_cred->user->ratelimit)) |
---|
| 77 | + msleep(50); |
---|
82 | 78 | |
---|
83 | 79 | err = efivar_entry_size(var, &datasize); |
---|
84 | 80 | |
---|
.. | .. |
---|
110 | 106 | return size; |
---|
111 | 107 | } |
---|
112 | 108 | |
---|
113 | | -static int |
---|
114 | | -efivarfs_ioc_getxflags(struct file *file, void __user *arg) |
---|
| 109 | +static inline unsigned int efivarfs_getflags(struct inode *inode) |
---|
115 | 110 | { |
---|
116 | | - struct inode *inode = file->f_mapping->host; |
---|
117 | 111 | unsigned int i_flags; |
---|
118 | 112 | unsigned int flags = 0; |
---|
119 | 113 | |
---|
120 | 114 | i_flags = inode->i_flags; |
---|
121 | 115 | if (i_flags & S_IMMUTABLE) |
---|
122 | 116 | flags |= FS_IMMUTABLE_FL; |
---|
| 117 | + return flags; |
---|
| 118 | +} |
---|
| 119 | + |
---|
| 120 | +static int |
---|
| 121 | +efivarfs_ioc_getxflags(struct file *file, void __user *arg) |
---|
| 122 | +{ |
---|
| 123 | + struct inode *inode = file->f_mapping->host; |
---|
| 124 | + unsigned int flags = efivarfs_getflags(inode); |
---|
123 | 125 | |
---|
124 | 126 | if (copy_to_user(arg, &flags, sizeof(flags))) |
---|
125 | 127 | return -EFAULT; |
---|
.. | .. |
---|
132 | 134 | struct inode *inode = file->f_mapping->host; |
---|
133 | 135 | unsigned int flags; |
---|
134 | 136 | unsigned int i_flags = 0; |
---|
| 137 | + unsigned int oldflags = efivarfs_getflags(inode); |
---|
135 | 138 | int error; |
---|
136 | 139 | |
---|
137 | 140 | if (!inode_owner_or_capable(inode)) |
---|
.. | .. |
---|
143 | 146 | if (flags & ~FS_IMMUTABLE_FL) |
---|
144 | 147 | return -EOPNOTSUPP; |
---|
145 | 148 | |
---|
146 | | - if (!capable(CAP_LINUX_IMMUTABLE)) |
---|
147 | | - return -EPERM; |
---|
148 | | - |
---|
149 | 149 | if (flags & FS_IMMUTABLE_FL) |
---|
150 | 150 | i_flags |= S_IMMUTABLE; |
---|
151 | 151 | |
---|
.. | .. |
---|
155 | 155 | return error; |
---|
156 | 156 | |
---|
157 | 157 | inode_lock(inode); |
---|
| 158 | + |
---|
| 159 | + error = vfs_ioc_setflags_prepare(inode, oldflags, flags); |
---|
| 160 | + if (error) |
---|
| 161 | + goto out; |
---|
| 162 | + |
---|
158 | 163 | inode_set_flags(inode, i_flags, S_IMMUTABLE); |
---|
| 164 | +out: |
---|
159 | 165 | inode_unlock(inode); |
---|
160 | | - |
---|
161 | 166 | mnt_drop_write_file(file); |
---|
162 | | - |
---|
163 | | - return 0; |
---|
| 167 | + return error; |
---|
164 | 168 | } |
---|
165 | 169 | |
---|
166 | 170 | static long |
---|