Skip to content

Commit ad8f9d9

Browse files
committed
14537 UFS should not allow directories to be unlinked
Reviewed by: Juraj Lutter <[email protected]> Reviewed by: Rich Lowe <[email protected]> Reviewed by: Robert Mustacchi <[email protected]> Reviewed by: Toomas Soome <[email protected]> Approved by: Dan McDonald <[email protected]>
1 parent e1ded6b commit ad8f9d9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

usr/src/uts/common/os/policy.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2323
* Copyright 2016 Joyent, Inc.
2424
* Copyright (c) 2016 by Delphix. All rights reserved.
25+
* Copyright 2022 Oxide Computer Company
2526
*/
2627

2728
#include <sys/types.h>
@@ -67,6 +68,19 @@
6768
int priv_debug = 0;
6869
int priv_basic_test = -1;
6970

71+
/*
72+
* Unlinking or creating new hard links to directories was historically allowed
73+
* in some file systems; e.g., UFS allows root users to do it, at the cost of
74+
* almost certain file system corruption that will require fsck to fix.
75+
*
76+
* Most modern operating systems and file systems (e.g., ZFS) do not allow this
77+
* behaviour anymore, and we have elected to stamp it out entirely for
78+
* compatibility and safety reasons. An attempt to unlink a directory will
79+
* fail with EPERM, as described in the standard. During this transition, one
80+
* can turn the behaviour back on, at their own risk, with this tuneable:
81+
*/
82+
int priv_allow_linkdir = 0;
83+
7084
/*
7185
* This file contains the majority of the policy routines.
7286
* Since the policy routines are defined by function and not
@@ -895,6 +909,23 @@ secpolicy_fs_config(const cred_t *cr, const vfs_t *vfsp)
895909
int
896910
secpolicy_fs_linkdir(const cred_t *cr, const vfs_t *vfsp)
897911
{
912+
if (priv_allow_linkdir == 0) {
913+
/*
914+
* By default, this policy check will now always return EPERM
915+
* unless overridden.
916+
*
917+
* We do so without triggering auditing or allowing privilege
918+
* debugging for two reasons: first, we intend eventually to
919+
* deprecate the PRIV_SYS_LINKDIR privilege entirely and remove
920+
* the use of this policy check from the file systems; second,
921+
* for privilege debugging in particular, because it would be
922+
* confusing to report an unlink() failure as the result of a
923+
* missing privilege when in fact we are simply no longer
924+
* allowing the operation at all.
925+
*/
926+
return (EPERM);
927+
}
928+
898929
return (PRIV_POLICY(cr, PRIV_SYS_LINKDIR, B_FALSE, EPERM, NULL));
899930
}
900931

0 commit comments

Comments
 (0)