From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oren Laadan Subject: [C/R v20][PATCH 72/96] Expose may_setuid() in user.h and add may_setgid() (v2) Date: Wed, 17 Mar 2010 12:09:00 -0400 Message-ID: <1268842164-5590-73-git-send-email-orenl@cs.columbia.edu> References: <1268842164-5590-1-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-2-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-3-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-4-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-5-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-6-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-7-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-8-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-9-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-10-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-11-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-12-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-13-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-14-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-15-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-16-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-17-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-18-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-19-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-20-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-21-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-22-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-23-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-24-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-25-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-26-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-27-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-28-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-29-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-30-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-31-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-32-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-33-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-34-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-35-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-36-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-37-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-38-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-39-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-40-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-41-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-42-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-43-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-44-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-45-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-46-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-47-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-48-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-49-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-50-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-51-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-52-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-53-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-54-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-55-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-56-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-57-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-58-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-59-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-60-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-61-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-62-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-63-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-64-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-65-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-66-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-67-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-68-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-69-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-70-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-71-git-send-email-orenl@cs.columbia.edu> <1268842164-5590-72-git-send-email-orenl@cs.columbia.edu> Return-path: In-Reply-To: <1268842164-5590-72-git-send-email-orenl@cs.columbia.edu> Sender: owner-linux-mm@kvack.org To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Serge Hallyn , Ingo Molnar , containers@lists.linux-foundation.org, Dan Smith List-Id: linux-api@vger.kernel.org From: Dan Smith Make these helpers available to others. Changes in v2: - Avoid checking the groupinfo in ctx->realcred against the current in may_setgid() Signed-off-by: Dan Smith Acked-by: Serge E. Hallyn Tested-by: Serge E. Hallyn --- include/linux/user.h | 9 +++++++++ kernel/user.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/include/linux/user.h b/include/linux/user.h index 68daf84..c231e9c 100644 --- a/include/linux/user.h +++ b/include/linux/user.h @@ -1 +1,10 @@ +#ifndef _LINUX_USER_H +#define _LINUX_USER_H + #include +#include + +extern int may_setuid(struct user_namespace *ns, uid_t uid); +extern int may_setgid(gid_t gid); + +#endif diff --git a/kernel/user.c b/kernel/user.c index 15f762c..8ddafea 100644 --- a/kernel/user.c +++ b/kernel/user.c @@ -604,7 +604,7 @@ int checkpoint_user(struct ckpt_ctx *ctx, void *ptr) return do_checkpoint_user(ctx, (struct user_struct *) ptr); } -static int may_setuid(struct user_namespace *ns, uid_t uid) +int may_setuid(struct user_namespace *ns, uid_t uid) { /* * this next check will one day become @@ -631,6 +631,17 @@ static int may_setuid(struct user_namespace *ns, uid_t uid) return 0; } +int may_setgid(gid_t gid) +{ + if (capable(CAP_SETGID)) + return 1; + + if (in_egroup_p(gid)) + return 1; + + return 0; +} + static struct user_struct *do_restore_user(struct ckpt_ctx *ctx) { struct user_struct *u; -- 1.6.3.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org