aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>1998-09-09 20:21:18 +0000
committerBruce Evans <bde@FreeBSD.org>1998-09-09 20:21:18 +0000
commit5d207357dbc8421e67c169b0f4d3fd74e118ede6 (patch)
tree9fd5e2d5f4d0302059c6bad7d78b39227bc9a31c /sys
parentddf0071c0137b8afc92dfb56aa6b037fc9f6e294 (diff)
Notes
Diffstat (limited to 'sys')
-rw-r--r--sys/gnu/ext2fs/ext2_vfsops.c36
-rw-r--r--sys/gnu/fs/ext2fs/ext2_vfsops.c36
2 files changed, 70 insertions, 2 deletions
diff --git a/sys/gnu/ext2fs/ext2_vfsops.c b/sys/gnu/ext2fs/ext2_vfsops.c
index a9cf8fb627e3..c9b8e4a62e01 100644
--- a/sys/gnu/ext2fs/ext2_vfsops.c
+++ b/sys/gnu/ext2fs/ext2_vfsops.c
@@ -187,6 +187,7 @@ ext2_mount(mp, path, data, ndp, p)
register struct ext2_sb_info *fs;
u_int size;
int error, flags;
+ mode_t accessmode;
if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
return (error);
@@ -217,8 +218,24 @@ ext2_mount(mp, path, data, ndp, p)
error = ext2_reload(mp, ndp->ni_cnd.cn_cred, p);
if (error)
return (error);
- if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR))
+ if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
+ /*
+ * If upgrade to read-write by non-root, then verify
+ * that user has necessary permissions on the device.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ devvp = ump->um_devvp;
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
+ if (error = VOP_ACCESS(devvp, VREAD | VWRITE,
+ p->p_ucred, p)) {
+ VOP_UNLOCK(devvp, 0, p);
+ return (error);
+ }
+ VOP_UNLOCK(devvp, 0, p);
+ }
+
fs->s_rd_only = 0;
+ }
if (fs->s_rd_only == 0) {
/* don't say it's clean */
fs->s_es->s_state &= ~EXT2_VALID_FS;
@@ -248,6 +265,23 @@ ext2_mount(mp, path, data, ndp, p)
vrele(devvp);
return (ENXIO);
}
+
+ /*
+ * If mount by non-root, then verify that user has necessary
+ * permissions on the device.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ accessmode = VREAD;
+ if ((mp->mnt_flag & MNT_RDONLY) == 0)
+ accessmode |= VWRITE;
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
+ if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) {
+ vput(devvp);
+ return (error);
+ }
+ VOP_UNLOCK(devvp, 0, p);
+ }
+
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
if (bdevsw[major(devvp->v_rdev)]->d_flags & D_NOCLUSTERR)
mp->mnt_flag |= MNT_NOCLUSTERR;
diff --git a/sys/gnu/fs/ext2fs/ext2_vfsops.c b/sys/gnu/fs/ext2fs/ext2_vfsops.c
index a9cf8fb627e3..c9b8e4a62e01 100644
--- a/sys/gnu/fs/ext2fs/ext2_vfsops.c
+++ b/sys/gnu/fs/ext2fs/ext2_vfsops.c
@@ -187,6 +187,7 @@ ext2_mount(mp, path, data, ndp, p)
register struct ext2_sb_info *fs;
u_int size;
int error, flags;
+ mode_t accessmode;
if (error = copyin(data, (caddr_t)&args, sizeof (struct ufs_args)))
return (error);
@@ -217,8 +218,24 @@ ext2_mount(mp, path, data, ndp, p)
error = ext2_reload(mp, ndp->ni_cnd.cn_cred, p);
if (error)
return (error);
- if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR))
+ if (fs->s_rd_only && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
+ /*
+ * If upgrade to read-write by non-root, then verify
+ * that user has necessary permissions on the device.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ devvp = ump->um_devvp;
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
+ if (error = VOP_ACCESS(devvp, VREAD | VWRITE,
+ p->p_ucred, p)) {
+ VOP_UNLOCK(devvp, 0, p);
+ return (error);
+ }
+ VOP_UNLOCK(devvp, 0, p);
+ }
+
fs->s_rd_only = 0;
+ }
if (fs->s_rd_only == 0) {
/* don't say it's clean */
fs->s_es->s_state &= ~EXT2_VALID_FS;
@@ -248,6 +265,23 @@ ext2_mount(mp, path, data, ndp, p)
vrele(devvp);
return (ENXIO);
}
+
+ /*
+ * If mount by non-root, then verify that user has necessary
+ * permissions on the device.
+ */
+ if (p->p_ucred->cr_uid != 0) {
+ accessmode = VREAD;
+ if ((mp->mnt_flag & MNT_RDONLY) == 0)
+ accessmode |= VWRITE;
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
+ if (error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p)) {
+ vput(devvp);
+ return (error);
+ }
+ VOP_UNLOCK(devvp, 0, p);
+ }
+
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
if (bdevsw[major(devvp->v_rdev)]->d_flags & D_NOCLUSTERR)
mp->mnt_flag |= MNT_NOCLUSTERR;