From 06bad7ebfc12a3d2fff3f091b5b6f162e49cb0b8 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Tue, 12 Jul 2016 11:34:05 +0000 Subject: [PATCH] 7019 zfsdev_ioctl skips secpolicy when FKIOCTL is set 7020 sdev_cleandir can loop forever Note that the bulk of the upstream change is not applicable to FreeBSD and the affected files are not even in the vendor area. illumos/illumos-gate@45b1747515a17db45e8971501ee84a26bdff37b2 https://github.com/illumos/illumos-gate/commit/45b1747515a17db45e8971501ee84a26bdff37b2 https://www.illumos.org/issues/7019 Currently zfsdev_ioctl, when confronted by a request with the FKIOCTL flag set, skips all processing of secpolicy functions. This means that ZFS is not doing any kind of verification of the credentials or access rights of the caller and assuming that (as it is an in-kernel client) all such checks have already been done. This turns out to be quite a dangerous assumption, especially with respect to sdev. In general I don't think it's particularly reasonable to offload this enforcement of access rights onto other kernel subsystems when ZFS has some particular local semantics in this area (delegated datasets etc) and does not provide any kind of API to allow other subsystems to avoid code duplication when doing it. ZFS should apply its normal access policy to requests from within the kernel, and callers should take care to give it the correct credentials and call it from the correct context in order to get the results they need. You can observe the currently unfortunate consequences of this bug in any non- global zone that has access to /dev/zvol or any subset of it via sdev profiles. In particular, a zone used to contain a KVM or similar which has a single zvol passed through to it using a 0t1234::pid2proc | ::walk thread | ::findstack -v [ ffffd001efcd3310 _resume_from_idle+0x112() ] ffffd001efcd3360 apix_hilevel_intr_epilog+0xc1(ffffd001efcd33d0, 0) ffffd001efcd33c0 apix_do_interrupt+0x34a(ffffd001efcd33d0, 0) ffffd001efcd33d0 _sys_rtt_ints_disabled+8() ffffd001efcd3550 rw_enter+0x58() ffffd001efcd35e0 sdev_cleandir+0x60(ffffd0631b6d75d8, 0, 0) ffffd001efcd3630 devzvol_prunedir+0xec(ffffd0631b6d76e8) ffffd001efcd36d0 devzvol_readdir+0x150(ffffd06333250e00, ffffd001efcd3790, ffffd062dc990e18, ffffd001efcd37dc, 0, 0) ffffd001efcd3760 fop_readdir+0x6b(ffffd06333250e00, ffffd001efcd3790, ffffd062dc990e18, ffffd001efcd37dc, 0, 0) ffffd001efcd3830 walk_dir+0xee(ffffd06333250e00, ffffd0669e4483c8, fffffffffbbdf410) ffffd001efcd3850 prof_make_names_walk+0x2e(ffffd0669e4483c8, fffffffffbbdf410) ffffd001efcd38b0 prof_make_names+0xfc(ffffd0669e4483c8) Reviewed by: Robert Mustacchi Reviewed by: Richard Lowe Reviewed by: Matthew Ahrens Approved by: Dan McDonald Author: Alex Wilson --- uts/common/fs/zfs/zfs_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uts/common/fs/zfs/zfs_ioctl.c b/uts/common/fs/zfs/zfs_ioctl.c index 63ec19b8f8ba..a7feada44f2c 100644 --- a/uts/common/fs/zfs/zfs_ioctl.c +++ b/uts/common/fs/zfs/zfs_ioctl.c @@ -25,7 +25,7 @@ * Portions Copyright 2011 Martin Matuska * Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved. * Copyright 2015 Nexenta Systems, Inc. All rights reserved. - * Copyright (c) 2014, Joyent, Inc. All rights reserved. + * Copyright (c) 2014, 2016 Joyent, Inc. All rights reserved. * Copyright (c) 2011, 2015 by Delphix. All rights reserved. * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. * Copyright (c) 2013 Steven Hartland. All rights reserved. @@ -6022,7 +6022,7 @@ zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) } - if (error == 0 && !(flag & FKIOCTL)) + if (error == 0) error = vec->zvec_secpolicy(zc, innvl, cr); if (error != 0)