2009-04-13 14:56:45

by Serge E. Hallyn

[permalink] [raw]
Subject: [PATCH] add some long-missing capabilities to fs_mask

When POSIX capabilities were introduced during the 2.1 Linux
cycle, the fs mask, which represents the capabilities which having
fsuid==0 is supposed to grant, did not include CAP_MKNOD and
CAP_LINUX_IMMUTABLE. However, before capabilities the privilege
to call these did in fact depend upon fsuid==0.

This patch introduces those capabilities into the fsmask,
restoring the old behavior.

See the thread starting at http://lkml.org/lkml/2009/3/11/157 for
reference.

Note that if this fix is deemed valid, then earlier kernel versions (2.4
and 2.2) ought to be fixed too.

Changelog:
[Mar 23] Actually delete old CAP_FS_SET definition...
[Mar 20] Updated against J. Bruce Fields's patch

Reported-by: Igor Zhbanov <[email protected]>
Signed-off-by: Serge E. Hallyn <[email protected]>
Cc: [email protected]
Cc: J. Bruce Fields <[email protected]>
---
include/linux/capability.h | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/linux/capability.h b/include/linux/capability.h
index 4864a43..c302110 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -377,7 +377,21 @@ struct cpu_vfs_cap_data {
#define CAP_FOR_EACH_U32(__capi) \
for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi)

+/*
+ * CAP_FS_MASK and CAP_NFSD_MASKS:
+ *
+ * The fs mask is all the privileges that fsuid==0 historically meant.
+ * At one time in the past, that included CAP_MKNOD and CAP_LINUX_IMMUTABLE.
+ *
+ * It has never meant setting security.* and trusted.* xattrs.
+ *
+ * We could also define fsmask as follows:
+ * 1. CAP_FS_MASK is the privilege to bypass all fs-related DAC permissions
+ * 2. The security.* and trusted.* xattrs are fs-related MAC permissions
+ */
+
# define CAP_FS_MASK_B0 (CAP_TO_MASK(CAP_CHOWN) \
+ | CAP_TO_MASK(CAP_MKNOD) \
| CAP_TO_MASK(CAP_DAC_OVERRIDE) \
| CAP_TO_MASK(CAP_DAC_READ_SEARCH) \
| CAP_TO_MASK(CAP_FOWNER) \
@@ -392,11 +406,12 @@ struct cpu_vfs_cap_data {
# define CAP_EMPTY_SET ((kernel_cap_t){{ 0, 0 }})
# define CAP_FULL_SET ((kernel_cap_t){{ ~0, ~0 }})
# define CAP_INIT_EFF_SET ((kernel_cap_t){{ ~CAP_TO_MASK(CAP_SETPCAP), ~0 }})
-# define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0, CAP_FS_MASK_B1 } })
+# define CAP_FS_SET ((kernel_cap_t){{ CAP_FS_MASK_B0 \
+ | CAP_TO_MASK(CAP_LINUX_IMMUTABLE), \
+ CAP_FS_MASK_B1 } })
# define CAP_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0 \
- | CAP_TO_MASK(CAP_SYS_RESOURCE) \
- | CAP_TO_MASK(CAP_MKNOD), \
- CAP_FS_MASK_B1 } })
+ | CAP_TO_MASK(CAP_SYS_RESOURCE), \
+ CAP_FS_MASK_B1 } })

#endif /* _KERNEL_CAPABILITY_U32S != 2 */

--
1.5.4.3


----- End forwarded message -----


2009-04-13 21:07:16

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH] add some long-missing capabilities to fs_mask

On Mon, 13 Apr 2009 09:56:14 CDT, "Serge E. Hallyn" said:
> When POSIX capabilities were introduced during the 2.1 Linux
> cycle, the fs mask, which represents the capabilities which having
> fsuid==0 is supposed to grant, did not include CAP_MKNOD and
> CAP_LINUX_IMMUTABLE. However, before capabilities the privilege
> to call these did in fact depend upon fsuid==0.

Wow. How did this manage to stay un-noticed for this long?


Attachments:
(No filename) (226.00 B)

2009-04-13 21:45:27

by Linus Torvalds

[permalink] [raw]
Subject: Re: [PATCH] add some long-missing capabilities to fs_mask



On Mon, 13 Apr 2009, [email protected] wrote:
>
> Wow. How did this manage to stay un-noticed for this long?

Because nobody uses capabilities?

Linus

2009-04-13 21:50:21

by Serge E. Hallyn

[permalink] [raw]
Subject: Re: [PATCH] add some long-missing capabilities to fs_mask

Quoting [email protected] ([email protected]):
> On Mon, 13 Apr 2009 09:56:14 CDT, "Serge E. Hallyn" said:
> > When POSIX capabilities were introduced during the 2.1 Linux
> > cycle, the fs mask, which represents the capabilities which having
> > fsuid==0 is supposed to grant, did not include CAP_MKNOD and
> > CAP_LINUX_IMMUTABLE. However, before capabilities the privilege
> > to call these did in fact depend upon fsuid==0.
>
> Wow. How did this manage to stay un-noticed for this long?

I guess setfsuid() is mainly used by NFS, and not a lot of people
do mknod over NFS?

To run into this, you'd have to do something like

1. run as root
2. setresuid(500,500,0);
3. (...)
4. setfsuid(0);
5. mknod(path, mode, dev);

so I suspect the simpler (cross-platform) thing to do was
seteuid(0) for the mknod anyway... Plus there is nowhere I've
found where the precise capabilities afforded to fsuid=0 are
documented, so noone would complain, they'd just accept it and
do seteuid()?

I'm guessing of course.

-serge