@@ -116,67 +116,52 @@ int bpf_token_create(union bpf_attr *attr)
116
116
struct user_namespace * userns ;
117
117
struct inode * inode ;
118
118
struct file * file ;
119
+ CLASS (fd , f )(attr -> token_create .bpffs_fd );
119
120
struct path path ;
120
- struct fd f ;
121
+ struct super_block * sb ;
121
122
umode_t mode ;
122
123
int err , fd ;
123
124
124
- f = fdget (attr -> token_create .bpffs_fd );
125
- if (!fd_file (f ))
125
+ if (fd_empty (f ))
126
126
return - EBADF ;
127
127
128
128
path = fd_file (f )-> f_path ;
129
- path_get (& path );
130
- fdput (f );
129
+ sb = path .dentry -> d_sb ;
131
130
132
- if (path .dentry != path .mnt -> mnt_sb -> s_root ) {
133
- err = - EINVAL ;
134
- goto out_path ;
135
- }
136
- if (path .mnt -> mnt_sb -> s_op != & bpf_super_ops ) {
137
- err = - EINVAL ;
138
- goto out_path ;
139
- }
131
+ if (path .dentry != sb -> s_root )
132
+ return - EINVAL ;
133
+ if (sb -> s_op != & bpf_super_ops )
134
+ return - EINVAL ;
140
135
err = path_permission (& path , MAY_ACCESS );
141
136
if (err )
142
- goto out_path ;
137
+ return err ;
143
138
144
- userns = path . dentry -> d_sb -> s_user_ns ;
139
+ userns = sb -> s_user_ns ;
145
140
/*
146
141
* Enforce that creators of BPF tokens are in the same user
147
142
* namespace as the BPF FS instance. This makes reasoning about
148
143
* permissions a lot easier and we can always relax this later.
149
144
*/
150
- if (current_user_ns () != userns ) {
151
- err = - EPERM ;
152
- goto out_path ;
153
- }
154
- if (!ns_capable (userns , CAP_BPF )) {
155
- err = - EPERM ;
156
- goto out_path ;
157
- }
145
+ if (current_user_ns () != userns )
146
+ return - EPERM ;
147
+ if (!ns_capable (userns , CAP_BPF ))
148
+ return - EPERM ;
158
149
159
150
/* Creating BPF token in init_user_ns doesn't make much sense. */
160
- if (current_user_ns () == & init_user_ns ) {
161
- err = - EOPNOTSUPP ;
162
- goto out_path ;
163
- }
151
+ if (current_user_ns () == & init_user_ns )
152
+ return - EOPNOTSUPP ;
164
153
165
- mnt_opts = path . dentry -> d_sb -> s_fs_info ;
154
+ mnt_opts = sb -> s_fs_info ;
166
155
if (mnt_opts -> delegate_cmds == 0 &&
167
156
mnt_opts -> delegate_maps == 0 &&
168
157
mnt_opts -> delegate_progs == 0 &&
169
- mnt_opts -> delegate_attachs == 0 ) {
170
- err = - ENOENT ; /* no BPF token delegation is set up */
171
- goto out_path ;
172
- }
158
+ mnt_opts -> delegate_attachs == 0 )
159
+ return - ENOENT ; /* no BPF token delegation is set up */
173
160
174
161
mode = S_IFREG | ((S_IRUSR | S_IWUSR ) & ~current_umask ());
175
- inode = bpf_get_inode (path .mnt -> mnt_sb , NULL , mode );
176
- if (IS_ERR (inode )) {
177
- err = PTR_ERR (inode );
178
- goto out_path ;
179
- }
162
+ inode = bpf_get_inode (sb , NULL , mode );
163
+ if (IS_ERR (inode ))
164
+ return PTR_ERR (inode );
180
165
181
166
inode -> i_op = & bpf_token_iops ;
182
167
inode -> i_fop = & bpf_token_fops ;
@@ -185,8 +170,7 @@ int bpf_token_create(union bpf_attr *attr)
185
170
file = alloc_file_pseudo (inode , path .mnt , BPF_TOKEN_INODE_NAME , O_RDWR , & bpf_token_fops );
186
171
if (IS_ERR (file )) {
187
172
iput (inode );
188
- err = PTR_ERR (file );
189
- goto out_path ;
173
+ return PTR_ERR (file );
190
174
}
191
175
192
176
token = kzalloc (sizeof (* token ), GFP_USER );
@@ -218,15 +202,12 @@ int bpf_token_create(union bpf_attr *attr)
218
202
file -> private_data = token ;
219
203
fd_install (fd , file );
220
204
221
- path_put (& path );
222
205
return fd ;
223
206
224
207
out_token :
225
208
bpf_token_free (token );
226
209
out_file :
227
210
fput (file );
228
- out_path :
229
- path_put (& path );
230
211
return err ;
231
212
}
232
213
0 commit comments