public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* in_group_p test for another process?
@ 2008-05-28 13:02 Markku Savela
  0 siblings, 0 replies; 2+ messages in thread
From: Markku Savela @ 2008-05-28 13:02 UTC (permalink / raw)
  To: linux-kernel


If I have a PID and some GID at hand, how do I find whether the OHTER
process identified by PID has the GID in its supplementary set of
groups?

I can find the "in_group_p" test, but that does it only for current process.

Do I have to write my own function that uses the "tasklist_lock",
finds task by "find_task_by_pid", and then calls
"groups_search(task->group_info, gid)"?

Can I do this in a module, or do I have to patch the "kernel/sys.c"
myself for a privately modified version of the kernel?


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: in_group_p test for another process?
       [not found] <aytzW-rV-23@gated-at.bofh.it>
@ 2008-06-04 11:18 ` Markku Savela
  0 siblings, 0 replies; 2+ messages in thread
From: Markku Savela @ 2008-06-04 11:18 UTC (permalink / raw)
  To: linux-kernel

Some time ago, I asked...

Markku Savela <msa@moth.iki.fi> writes:
> If I have a PID and some GID at hand, how do I find whether the OHTER
> process identified by PID has the GID in its supplementary set of
> groups?
>
> I can find the "in_group_p" test, but that does it only for current process.
>
> Do I have to write my own function that uses the "tasklist_lock",
> finds task by "find_task_by_pid", and then calls
> "groups_search(task->group_info, gid)"?
>
> Can I do this in a module, or do I have to patch the "kernel/sys.c"
> myself for a privately modified version of the kernel?

Well, I've wrote a modification to the kernel/sys.c and it seems to
work for me. As I'm not really a hard core kernel expert, I'm not
quite sure the solution is bullet proof. Thus, here is my added
function that I use in my privately modified kernel for comments, if
any:


--- include/linux/sched-orig.h	2008-05-01 16:53:02.000000000 +0300
+++ include/linux/sched.h	2008-05-30 11:18:35.000000000 +0300
@@ -1582,6 +1582,7 @@
 
 extern int in_group_p(gid_t);
 extern int in_egroup_p(gid_t);
+extern int pid_in_egroup_p(gid_t, pid_t);
 
 extern void proc_caches_init(void);
 extern void flush_signals(struct task_struct *);
--- kernel/sys-orig.c	2008-02-11 07:51:11.000000000 +0200
+++ kernel/sys.c	2008-05-30 11:17:52.000000000 +0300
@@ -1338,6 +1338,29 @@
 
 EXPORT_SYMBOL(in_egroup_p);
 
+int pid_in_egroup_p(gid_t grp, pid_t pid)
+{
+	int retval = 1;
+	struct task_struct *p;
+
+	if (pid <= 0)
+		return 0;
+
+	read_lock(&tasklist_lock);
+	p = find_task_by_vpid(pid);
+	if (p) {
+		task_lock(p);
+		if (grp != p->egid)
+			retval = groups_search(p->group_info, grp);
+		task_unlock(p);
+	}
+	else
+		retval = 0;
+	read_unlock(&tasklist_lock);
+	return retval;
+}
+EXPORT_SYMBOL(pid_in_egroup_p);
+
 DECLARE_RWSEM(uts_sem);
 
 EXPORT_SYMBOL(uts_sem);


-- 
Markku Savela

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-04 11:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <aytzW-rV-23@gated-at.bofh.it>
2008-06-04 11:18 ` in_group_p test for another process? Markku Savela
2008-05-28 13:02 Markku Savela

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox