diff options
author | avg <avg@FreeBSD.org> | 2015-05-11 10:07:31 +0000 |
---|---|---|
committer | avg <avg@FreeBSD.org> | 2015-05-11 10:07:31 +0000 |
commit | 9f5ffddd44f79c4d1a2ef15601fbf3206884a7ff (patch) | |
tree | b8a8a1be4325768477336a683b08cee6a3dddff6 | |
parent | 4b7c07e495514c687abb5fe9c9708eb5a4f21545 (diff) | |
download | FreeBSD-src-9f5ffddd44f79c4d1a2ef15601fbf3206884a7ff.zip FreeBSD-src-9f5ffddd44f79c4d1a2ef15601fbf3206884a7ff.tar.gz |
zfs ioctls: use fget_write / fget_read instead of getf wrapper for fget
This allows to ensure that we do not write to a file that was opened
for reading only or vice versa.
Also, use the correct capability in in zfs_ioc_send_new().
Differential Revision: https://reviews.freebsd.org/D2382
Reviewed by: delphij
MFC after: 17 days
Sponsored by: ClusterHQ
-rw-r--r-- | sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c index 55e3c45..8f31e3f 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c @@ -4196,7 +4196,11 @@ zfs_ioc_recv(zfs_cmd_t *zc) return (error); fd = zc->zc_cookie; - fp = getf(fd, cap_rights_init(&rights, CAP_PREAD)); +#ifdef illumos + fp = getf(fd); +#else + fget_read(curthread, fd, cap_rights_init(&rights, CAP_PREAD), &fp); +#endif if (fp == NULL) { nvlist_free(props); return (SET_ERROR(EBADF)); @@ -4442,8 +4446,12 @@ zfs_ioc_send(zfs_cmd_t *zc) file_t *fp; cap_rights_t rights; - fp = getf(zc->zc_cookie, - cap_rights_init(&rights, CAP_WRITE)); +#ifdef illumos + fp = getf(zc->zc_cookie); +#else + fget_write(curthread, zc->zc_cookie, + cap_rights_init(&rights, CAP_WRITE), &fp); +#endif if (fp == NULL) return (SET_ERROR(EBADF)); @@ -5039,7 +5047,12 @@ zfs_ioc_diff(zfs_cmd_t *zc) offset_t off; int error; - fp = getf(zc->zc_cookie, cap_rights_init(&rights, CAP_WRITE)); +#ifdef illumos + fp = getf(zc->zc_cookie); +#else + fget_write(curthread, zc->zc_cookie, + cap_rights_init(&rights, CAP_WRITE), &fp); +#endif if (fp == NULL) return (SET_ERROR(EBADF)); @@ -5404,6 +5417,7 @@ static int zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl) { cap_rights_t rights; + file_t *fp; int error; offset_t off; char *fromname = NULL; @@ -5420,7 +5434,11 @@ zfs_ioc_send_new(const char *snapname, nvlist_t *innvl, nvlist_t *outnvl) largeblockok = nvlist_exists(innvl, "largeblockok"); embedok = nvlist_exists(innvl, "embedok"); - file_t *fp = getf(fd, cap_rights_init(&rights, CAP_READ)); +#ifdef illumos + file_t *fp = getf(fd); +#else + fget_write(curthread, fd, cap_rights_init(&rights, CAP_WRITE), &fp); +#endif if (fp == NULL) return (SET_ERROR(EBADF)); |