Module Name: src
Committed By: christos
Date: Sat Feb 3 22:39:27 UTC 2024
Modified Files:
src/sys/fs/cd9660: cd9660_vfsops.c
Log Message:
add checks for id and mask in the update case (thanks hannken)
To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/fs/cd9660/cd9660_vfsops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/fs/cd9660/cd9660_vfsops.c
diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.102 src/sys/fs/cd9660/cd9660_vfsops.c:1.103
--- src/sys/fs/cd9660/cd9660_vfsops.c:1.102 Sat Feb 3 13:45:50 2024
+++ src/sys/fs/cd9660/cd9660_vfsops.c Sat Feb 3 17:39:27 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660_vfsops.c,v 1.102 2024/02/03 18:45:50 christos Exp $ */
+/* $NetBSD: cd9660_vfsops.c,v 1.103 2024/02/03 22:39:27 christos Exp $ */
/*-
* Copyright (c) 1994
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.102 2024/02/03 18:45:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.103 2024/02/03 22:39:27 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -174,6 +174,44 @@ cd9660_modcmd(modcmd_t cmd, void *arg)
return (error);
}
+/* Compat with pre uid/gid/fsize/dsize mount call */
+#define OSIZE sizeof(struct { \
+ const char *fspec; \
+ struct export_args30 _pad1; \
+ int flags; \
+})
+
+static int
+iso_checkupdate(const struct vnode *devvp, const struct iso_mnt *imp,
+ const struct iso_args *args)
+{
+
+ if (devvp != imp->im_devvp && devvp->v_rdev != imp->im_devvp->v_rdev)
+ return EINVAL;
+
+ if (((imp->im_flags & ISOFSMNT_UID) && args->uid != imp->im_uid) ||
+ ((imp->im_flags & ISOFSMNT_GID) && args->gid != imp->im_gid) ||
+ args->fmask != imp->im_fmask || args->dmask != imp->im_dmask)
+ return EPERM;
+
+ return 0;
+}
+
+static void
+iso_copyidmask(struct iso_args *args, const struct iso_mnt *imp)
+{
+
+ if (imp == NULL) {
+ args->uid = args->gid = 0;
+ args->fmask = args->dmask = S_IRWXU|S_IRWXG|S_IRWXO;
+ return;
+ }
+ args->uid = imp->im_uid;
+ args->gid = imp->im_gid;
+ args->fmask = imp->im_fmask;
+ args->dmask = imp->im_dmask;
+}
+
int
cd9660_mountroot(void)
{
@@ -192,7 +230,7 @@ cd9660_mountroot(void)
}
args.flags = ISOFSMNT_ROOT;
- args.fmask = args.dmask = S_IRWXU|S_IRWXG|S_IRWXO;
+ iso_copyidmask(&args, NULL);
if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) {
vfs_unbusy(mp);
vfs_rele(mp);
@@ -204,13 +242,7 @@ cd9660_mountroot(void)
return (0);
}
-/* Compat with pre uid/gid/fsize/dsize mount call */
-#define OSIZE sizeof(struct { \
- const char *fspec; \
- struct export_args30 _pad1; \
- int flags; \
-})
-
+
/*
* VFS Operations.
*
@@ -241,10 +273,7 @@ cd9660_mount(struct mount *mp, const cha
if (*data_len == OSIZE)
return 0;
- args->uid = imp->im_uid;
- args->gid = imp->im_gid;
- args->fmask = imp->im_fmask;
- args->dmask = imp->im_dmask;
+ iso_copyidmask(args, imp);
*data_len = sizeof(*args);
return 0;
}
@@ -252,8 +281,7 @@ cd9660_mount(struct mount *mp, const cha
if (*data_len == OSIZE) {
memcpy(&aa, args, OSIZE);
args = &aa;
- args->uid = args->gid = 0;
- args->fmask = args->dmask = S_IRWXU|S_IRWXG|S_IRWXO;
+ iso_copyidmask(args, (mp->mnt_flag & MNT_UPDATE) ? imp : NULL);
}
if ((mp->mnt_flag & MNT_RDONLY) == 0)
@@ -303,11 +331,8 @@ cd9660_mount(struct mount *mp, const cha
VOP_UNLOCK(devvp);
/* reference to devvp is donated through iso_mountfs */
} else {
- if (devvp != imp->im_devvp &&
- devvp->v_rdev != imp->im_devvp->v_rdev) {
- error = EINVAL; /* needs translation */
+ if ((error = iso_checkupdate(devvp, imp, args)) != 0)
goto fail;
- }
VOP_UNLOCK(devvp);
vrele(devvp);
}