bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/4] libdiskfs: add permission check to file_chflags


From: Justus Winter
Subject: [PATCH 3/4] libdiskfs: add permission check to file_chflags
Date: Wed, 11 Jun 2014 13:41:09 +0200

Only root is allowed to change the high 16 bits.  The TODO entry says
otherwise, but that must be a mistake.  For reference, see the glibc
sources, sysdeps/mach/hurd/bits/stat.h.

* libdiskfs/file-chflags.c (diskfs_S_file_chflags): Add permission
check.
* TODO (libdiskfs): Remove entry.
---
 TODO                     | 2 --
 libdiskfs/file-chflags.c | 6 ++++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO
index d2500dc..0387e9f 100644
--- a/TODO
+++ b/TODO
@@ -108,8 +108,6 @@ See `tasks', the exported task list.
    Rename the rest to libhurdutil or somesuch.
 
 ** libdiskfs
-*** file_chflags does not do proper permission checking (non-root isn't
-    supposed to be able to change the low bits)
 *** Add the short-circuited-but-not-builtin translator startup code from
     dir-lookup to fsys_getroot.  Compare and match carefully these two
     routines and then share common code.
diff --git a/libdiskfs/file-chflags.c b/libdiskfs/file-chflags.c
index 01dc495..9642c3c 100644
--- a/libdiskfs/file-chflags.c
+++ b/libdiskfs/file-chflags.c
@@ -25,6 +25,12 @@ diskfs_S_file_chflags (struct protid *cred,
 {
   CHANGE_NODE_FIELD (cred,
                   ({
+                     if (flags & 0xffff0000
+                         && ! idvec_contains (cred->user->uids, 0))
+                       /* Only root is allowed to change the high 16
+                          bits.  */
+                       return EPERM;
+
                     err = fshelp_isowner (&np->dn_stat, cred->user);
                     if (!err)
                       err = diskfs_validate_flags_change (np, flags);
-- 
2.0.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]