hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/fs/autofs/inode.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
34 * Copyright 2005-2006 Ian Kent <raven@themaw.net>
4
- *
5
- * This file is part of the Linux kernel and is made available under
6
- * the terms of the GNU General Public License, version 2, or at your
7
- * option, any later version, incorporated herein by reference.
85 */
96
107 #include <linux/seq_file.h>
....@@ -36,7 +33,7 @@
3633
3734 void autofs_free_ino(struct autofs_info *ino)
3835 {
39
- kfree(ino);
36
+ kfree_rcu(ino, rcu);
4037 }
4138
4239 void autofs_kill_sb(struct super_block *sb)
....@@ -82,16 +79,20 @@
8279 seq_printf(m, ",maxproto=%d", sbi->max_proto);
8380
8481 if (autofs_type_offset(sbi->type))
85
- seq_printf(m, ",offset");
82
+ seq_puts(m, ",offset");
8683 else if (autofs_type_direct(sbi->type))
87
- seq_printf(m, ",direct");
84
+ seq_puts(m, ",direct");
8885 else
89
- seq_printf(m, ",indirect");
86
+ seq_puts(m, ",indirect");
87
+ if (sbi->flags & AUTOFS_SBI_STRICTEXPIRE)
88
+ seq_puts(m, ",strictexpire");
89
+ if (sbi->flags & AUTOFS_SBI_IGNORE)
90
+ seq_puts(m, ",ignore");
9091 #ifdef CONFIG_CHECKPOINT_RESTORE
9192 if (sbi->pipe)
9293 seq_printf(m, ",pipe_ino=%ld", file_inode(sbi->pipe)->i_ino);
9394 else
94
- seq_printf(m, ",pipe_ino=-1");
95
+ seq_puts(m, ",pipe_ino=-1");
9596 #endif
9697 return 0;
9798 }
....@@ -109,7 +110,8 @@
109110 };
110111
111112 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
112
- Opt_indirect, Opt_direct, Opt_offset};
113
+ Opt_indirect, Opt_direct, Opt_offset, Opt_strictexpire,
114
+ Opt_ignore};
113115
114116 static const match_table_t tokens = {
115117 {Opt_fd, "fd=%u"},
....@@ -121,24 +123,29 @@
121123 {Opt_indirect, "indirect"},
122124 {Opt_direct, "direct"},
123125 {Opt_offset, "offset"},
126
+ {Opt_strictexpire, "strictexpire"},
127
+ {Opt_ignore, "ignore"},
124128 {Opt_err, NULL}
125129 };
126130
127
-static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,
128
- int *pgrp, bool *pgrp_set, unsigned int *type,
129
- int *minproto, int *maxproto)
131
+static int parse_options(char *options,
132
+ struct inode *root, int *pgrp, bool *pgrp_set,
133
+ struct autofs_sb_info *sbi)
130134 {
131135 char *p;
132136 substring_t args[MAX_OPT_ARGS];
133137 int option;
138
+ int pipefd = -1;
139
+ kuid_t uid;
140
+ kgid_t gid;
134141
135
- *uid = current_uid();
136
- *gid = current_gid();
142
+ root->i_uid = current_uid();
143
+ root->i_gid = current_gid();
137144
138
- *minproto = AUTOFS_MIN_PROTO_VERSION;
139
- *maxproto = AUTOFS_MAX_PROTO_VERSION;
145
+ sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
146
+ sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
140147
141
- *pipefd = -1;
148
+ sbi->pipefd = -1;
142149
143150 if (!options)
144151 return 1;
....@@ -152,22 +159,25 @@
152159 token = match_token(p, tokens, args);
153160 switch (token) {
154161 case Opt_fd:
155
- if (match_int(args, pipefd))
162
+ if (match_int(args, &pipefd))
156163 return 1;
164
+ sbi->pipefd = pipefd;
157165 break;
158166 case Opt_uid:
159167 if (match_int(args, &option))
160168 return 1;
161
- *uid = make_kuid(current_user_ns(), option);
162
- if (!uid_valid(*uid))
169
+ uid = make_kuid(current_user_ns(), option);
170
+ if (!uid_valid(uid))
163171 return 1;
172
+ root->i_uid = uid;
164173 break;
165174 case Opt_gid:
166175 if (match_int(args, &option))
167176 return 1;
168
- *gid = make_kgid(current_user_ns(), option);
169
- if (!gid_valid(*gid))
177
+ gid = make_kgid(current_user_ns(), option);
178
+ if (!gid_valid(gid))
170179 return 1;
180
+ root->i_gid = gid;
171181 break;
172182 case Opt_pgrp:
173183 if (match_int(args, &option))
....@@ -178,27 +188,33 @@
178188 case Opt_minproto:
179189 if (match_int(args, &option))
180190 return 1;
181
- *minproto = option;
191
+ sbi->min_proto = option;
182192 break;
183193 case Opt_maxproto:
184194 if (match_int(args, &option))
185195 return 1;
186
- *maxproto = option;
196
+ sbi->max_proto = option;
187197 break;
188198 case Opt_indirect:
189
- set_autofs_type_indirect(type);
199
+ set_autofs_type_indirect(&sbi->type);
190200 break;
191201 case Opt_direct:
192
- set_autofs_type_direct(type);
202
+ set_autofs_type_direct(&sbi->type);
193203 break;
194204 case Opt_offset:
195
- set_autofs_type_offset(type);
205
+ set_autofs_type_offset(&sbi->type);
206
+ break;
207
+ case Opt_strictexpire:
208
+ sbi->flags |= AUTOFS_SBI_STRICTEXPIRE;
209
+ break;
210
+ case Opt_ignore:
211
+ sbi->flags |= AUTOFS_SBI_IGNORE;
196212 break;
197213 default:
198214 return 1;
199215 }
200216 }
201
- return (*pipefd < 0);
217
+ return (sbi->pipefd < 0);
202218 }
203219
204220 int autofs_fill_super(struct super_block *s, void *data, int silent)
....@@ -206,7 +222,6 @@
206222 struct inode *root_inode;
207223 struct dentry *root;
208224 struct file *pipe;
209
- int pipefd;
210225 struct autofs_sb_info *sbi;
211226 struct autofs_info *ino;
212227 int pgrp = 0;
....@@ -222,12 +237,12 @@
222237 sbi->magic = AUTOFS_SBI_MAGIC;
223238 sbi->pipefd = -1;
224239 sbi->pipe = NULL;
225
- sbi->catatonic = 1;
226240 sbi->exp_timeout = 0;
227241 sbi->oz_pgrp = NULL;
228242 sbi->sb = s;
229243 sbi->version = 0;
230244 sbi->sub_version = 0;
245
+ sbi->flags = AUTOFS_SBI_CATATONIC;
231246 set_autofs_type_indirect(&sbi->type);
232247 sbi->min_proto = 0;
233248 sbi->max_proto = 0;
....@@ -264,9 +279,7 @@
264279 root->d_fsdata = ino;
265280
266281 /* Can this call block? */
267
- if (parse_options(data, &pipefd, &root_inode->i_uid, &root_inode->i_gid,
268
- &pgrp, &pgrp_set, &sbi->type, &sbi->min_proto,
269
- &sbi->max_proto)) {
282
+ if (parse_options(data, root_inode, &pgrp, &pgrp_set, sbi)) {
270283 pr_err("called with bogus options\n");
271284 goto fail_dput;
272285 }
....@@ -305,8 +318,9 @@
305318 root_inode->i_fop = &autofs_root_operations;
306319 root_inode->i_op = &autofs_dir_inode_operations;
307320
308
- pr_debug("pipe fd = %d, pgrp = %u\n", pipefd, pid_nr(sbi->oz_pgrp));
309
- pipe = fget(pipefd);
321
+ pr_debug("pipe fd = %d, pgrp = %u\n",
322
+ sbi->pipefd, pid_nr(sbi->oz_pgrp));
323
+ pipe = fget(sbi->pipefd);
310324
311325 if (!pipe) {
312326 pr_err("could not open pipe file descriptor\n");
....@@ -316,8 +330,7 @@
316330 if (ret < 0)
317331 goto fail_fput;
318332 sbi->pipe = pipe;
319
- sbi->pipefd = pipefd;
320
- sbi->catatonic = 0;
333
+ sbi->flags &= ~AUTOFS_SBI_CATATONIC;
321334
322335 /*
323336 * Success! Install the root dentry now to indicate completion.