hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/fs/autofs/dev-ioctl.c
....@@ -1,16 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright 2008 Red Hat, Inc. All rights reserved.
34 * Copyright 2008 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/miscdevice.h>
118 #include <linux/compat.h>
129 #include <linux/syscalls.h>
1310 #include <linux/magic.h>
11
+#include <linux/nospec.h>
1412
1513 #include "autofs_i.h"
1614
....@@ -23,7 +21,7 @@
2321 * another mount. This situation arises when starting automount(8)
2422 * or other user space daemon which uses direct mounts or offset
2523 * mounts (used for autofs lazy mount/umount of nested mount trees),
26
- * which have been left busy at at service shutdown.
24
+ * which have been left busy at service shutdown.
2725 */
2826
2927 typedef int (*ioctl_fn)(struct file *, struct autofs_sb_info *,
....@@ -151,22 +149,6 @@
151149 return err;
152150 }
153151
154
-/*
155
- * Get the autofs super block info struct from the file opened on
156
- * the autofs mount point.
157
- */
158
-static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
159
-{
160
- struct autofs_sb_info *sbi = NULL;
161
- struct inode *inode;
162
-
163
- if (f) {
164
- inode = file_inode(f);
165
- sbi = autofs_sbi(inode->i_sb);
166
- }
167
- return sbi;
168
-}
169
-
170152 /* Return autofs dev ioctl version */
171153 static int autofs_dev_ioctl_version(struct file *fp,
172154 struct autofs_sb_info *sbi,
....@@ -205,7 +187,7 @@
205187 struct path path;
206188 int err;
207189
208
- err = kern_path_mountpoint(AT_FDCWD, pathname, &path, 0);
190
+ err = kern_path(pathname, LOOKUP_MOUNTPOINT, &path);
209191 if (err)
210192 return err;
211193 err = -ENOENT;
....@@ -366,7 +348,7 @@
366348 pipefd = param->setpipefd.pipefd;
367349
368350 mutex_lock(&sbi->wq_mutex);
369
- if (!sbi->catatonic) {
351
+ if (!(sbi->flags & AUTOFS_SBI_CATATONIC)) {
370352 mutex_unlock(&sbi->wq_mutex);
371353 return -EBUSY;
372354 } else {
....@@ -393,7 +375,7 @@
393375 swap(sbi->oz_pgrp, new_pid);
394376 sbi->pipefd = pipefd;
395377 sbi->pipe = pipe;
396
- sbi->catatonic = 0;
378
+ sbi->flags &= ~AUTOFS_SBI_CATATONIC;
397379 }
398380 out:
399381 put_pid(new_pid);
....@@ -515,7 +497,7 @@
515497 * located path is the root of a mount we return 1 along with
516498 * the super magic of the mount or 0 otherwise.
517499 *
518
- * In both cases the the device number (as returned by
500
+ * In both cases the device number (as returned by
519501 * new_encode_dev()) is also returned.
520502 */
521503 static int autofs_dev_ioctl_ismountpoint(struct file *fp,
....@@ -538,8 +520,8 @@
538520
539521 if (!fp || param->ioctlfd == -1) {
540522 if (autofs_type_any(type))
541
- err = kern_path_mountpoint(AT_FDCWD,
542
- name, &path, LOOKUP_FOLLOW);
523
+ err = kern_path(name, LOOKUP_FOLLOW | LOOKUP_MOUNTPOINT,
524
+ &path);
543525 else
544526 err = find_autofs_mount(name, &path,
545527 test_by_type, &type);
....@@ -582,7 +564,7 @@
582564
583565 static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
584566 {
585
- static ioctl_fn _ioctls[] = {
567
+ static const ioctl_fn _ioctls[] = {
586568 autofs_dev_ioctl_version,
587569 autofs_dev_ioctl_protover,
588570 autofs_dev_ioctl_protosubver,
....@@ -600,7 +582,10 @@
600582 };
601583 unsigned int idx = cmd_idx(cmd);
602584
603
- return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx];
585
+ if (idx >= ARRAY_SIZE(_ioctls))
586
+ return NULL;
587
+ idx = array_index_nospec(idx, ARRAY_SIZE(_ioctls));
588
+ return _ioctls[idx];
604589 }
605590
606591 /* ioctl dispatcher */
....@@ -658,6 +643,8 @@
658643 if (cmd != AUTOFS_DEV_IOCTL_VERSION_CMD &&
659644 cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
660645 cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
646
+ struct super_block *sb;
647
+
661648 fp = fget(param->ioctlfd);
662649 if (!fp) {
663650 if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
....@@ -666,12 +653,13 @@
666653 goto out;
667654 }
668655
669
- sbi = autofs_dev_ioctl_sbi(fp);
670
- if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
656
+ sb = file_inode(fp)->i_sb;
657
+ if (sb->s_type != &autofs_fs_type) {
671658 err = -EINVAL;
672659 fput(fp);
673660 goto out;
674661 }
662
+ sbi = autofs_sbi(sb);
675663
676664 /*
677665 * Admin needs to be able to set the mount catatonic in