[PATCH] nfsd: nfsd should drop CAP_MKNOD for non-root

37 views
Skip to first unread message

J. Bruce Fields

unread,
Mar 18, 2009, 12:21:56 PM3/18/09
to Linus Torvalds, linu...@vger.kernel.org, linux-...@vger.kernel.org, Igor Zhbanov, Serge Hallyn, J. Bruce Fields, sta...@kernel.org
From: J. Bruce Fields <bfi...@citi.umich.edu>

Since creating a device node is normally an operation requiring special
privilege, Igor Zhbanov points out that it is surprising (to say the
least) that a client can, for example, create a device node on a
filesystem exported with root_squash.

So, make sure CAP_MKNOD is among the capabilities dropped when an nfsd
thread handles a request from a non-root user.

Reported-by: Igor Zhbanov <izh...@gmail.com>
Cc: sta...@kernel.org
Signed-off-by: J. Bruce Fields <bfi...@citi.umich.edu>
---
include/linux/capability.h | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/capability.h b/include/linux/capability.h
index 1b98725..4864a43 100644
--- a/include/linux/capability.h
+++ b/include/linux/capability.h
@@ -393,8 +393,10 @@ struct cpu_vfs_cap_data {
# 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_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
- 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 } })

#endif /* _KERNEL_CAPABILITY_U32S != 2 */

--
1.6.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Serge E. Hallyn

unread,
Mar 18, 2009, 1:09:16 PM3/18/09
to J. Bruce Fields, Linus Torvalds, linu...@vger.kernel.org, linux-...@vger.kernel.org, Igor Zhbanov, J. Bruce Fields, sta...@kernel.org
Quoting J. Bruce Fields (bfi...@fieldses.org):
> From: J. Bruce Fields <bfi...@citi.umich.edu>
>
> Since creating a device node is normally an operation requiring special
> privilege, Igor Zhbanov points out that it is surprising (to say the
> least) that a client can, for example, create a device node on a
> filesystem exported with root_squash.
>
> So, make sure CAP_MKNOD is among the capabilities dropped when an nfsd
> thread handles a request from a non-root user.
>
> Reported-by: Igor Zhbanov <izh...@gmail.com>
> Cc: sta...@kernel.org
> Signed-off-by: J. Bruce Fields <bfi...@citi.umich.edu>

Acked-by: Serge Hallyn <se...@us.ibm.com>

I assume CAP_LINUX_IMMUTABLE simply does not apply to nfs?

And, you're adding CAP_FS_MASK_B1 in anticipation of labeled nfs?

Though, I was going to send a patch later today or tomorrow (figure I
should do some ltp testing) adding CAP_MKNOD to the whole
CAP_FS_MASK_B0 (and CAP_LINUX_IMMUTABLE and CAP_FS_MASK_B1 to
CAP_FS_SET). That will conflict with this one.

thanks,
-serge

J. Bruce Fields

unread,
Mar 18, 2009, 1:32:41 PM3/18/09
to Serge E. Hallyn, Linus Torvalds, linu...@vger.kernel.org, linux-...@vger.kernel.org, Igor Zhbanov, sta...@kernel.org
On Wed, Mar 18, 2009 at 12:08:43PM -0500, Serge E. Hallyn wrote:
> Quoting J. Bruce Fields (bfi...@fieldses.org):
> > From: J. Bruce Fields <bfi...@citi.umich.edu>
> >
> > Since creating a device node is normally an operation requiring special
> > privilege, Igor Zhbanov points out that it is surprising (to say the
> > least) that a client can, for example, create a device node on a
> > filesystem exported with root_squash.
> >
> > So, make sure CAP_MKNOD is among the capabilities dropped when an nfsd
> > thread handles a request from a non-root user.
> >
> > Reported-by: Igor Zhbanov <izh...@gmail.com>
> > Cc: sta...@kernel.org
> > Signed-off-by: J. Bruce Fields <bfi...@citi.umich.edu>
>
> Acked-by: Serge Hallyn <se...@us.ibm.com>
>
> I assume CAP_LINUX_IMMUTABLE simply does not apply to nfs?

Right. We shouldn't care how it's set.

> And, you're adding CAP_FS_MASK_B1 in anticipation of labeled nfs?

That's unchanged (would have been clearer if I hadn't re-line-wrapped in
the same patch).

> Though, I was going to send a patch later today or tomorrow (figure I
> should do some ltp testing) adding CAP_MKNOD to the whole
> CAP_FS_MASK_B0 (and CAP_LINUX_IMMUTABLE and CAP_FS_MASK_B1 to
> CAP_FS_SET). That will conflict with this one.

OK, feel free to revert this at that point if necessary.

--b.

Igor Zhbanov

unread,
Mar 18, 2009, 4:38:23 PM3/18/09
to J. Bruce Fields, Serge E. Hallyn, Linus Torvalds, linu...@vger.kernel.org, linux-...@vger.kernel.org, sta...@kernel.org
That's good and I'm glad to see patch for CAP_NFSD_MASK in git. Thanks. :-)
Waiting for CAP_FS_MASK to be fixed too.

By the way, I don't see git repository for 2.4.x kernel. Could you fix
2.4.x too?

James Morris

unread,
Mar 18, 2009, 6:29:01 PM3/18/09
to J. Bruce Fields, Linus Torvalds, linu...@vger.kernel.org, linux-...@vger.kernel.org, Igor Zhbanov, Serge Hallyn, J. Bruce Fields, sta...@kernel.org
On Wed, 18 Mar 2009, J. Bruce Fields wrote:

> From: J. Bruce Fields <bfi...@citi.umich.edu>
>
> Since creating a device node is normally an operation requiring special
> privilege, Igor Zhbanov points out that it is surprising (to say the
> least) that a client can, for example, create a device node on a
> filesystem exported with root_squash.
>
> So, make sure CAP_MKNOD is among the capabilities dropped when an nfsd
> thread handles a request from a non-root user.
>
> Reported-by: Igor Zhbanov <izh...@gmail.com>
> Cc: sta...@kernel.org
> Signed-off-by: J. Bruce Fields <bfi...@citi.umich.edu>

Acked-by: James Morris <jmo...@namei.org>

> ---
> include/linux/capability.h | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/capability.h b/include/linux/capability.h
> index 1b98725..4864a43 100644
> --- a/include/linux/capability.h
> +++ b/include/linux/capability.h
> @@ -393,8 +393,10 @@ struct cpu_vfs_cap_data {
> # 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_NFSD_SET ((kernel_cap_t){{ CAP_FS_MASK_B0|CAP_TO_MASK(CAP_SYS_RESOURCE), \
> - 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 } })
>
> #endif /* _KERNEL_CAPABILITY_U32S != 2 */
>
> --
> 1.6.0.4
>
> --

> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in


> the body of a message to majo...@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

--
James Morris
<jmo...@namei.org>

Reply all
Reply to author
Forward
0 new messages