From: ebiederm@xmission.com (Eric W. Biederman)
To: <linux-kernel@vger.kernel.org>
Cc: <vserver@list.linux-vserver.org>,
Herbert Poetzl <herbert@13thfloor.at>,
"Serge E. Hallyn" <serue@us.ibm.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Dave Hansen <haveblue@us.ibm.com>,
Arjan van de Ven <arjan@infradead.org>,
Suleiman Souhlal <ssouhlal@FreeBSD.org>,
Hubertus Franke <frankeh@watson.ibm.com>,
Cedric Le Goater <clg@fr.ibm.com>,
Kyle Moffett <mrmacman_g4@mac.com>
Subject: [PATCH 5/5] file: Modify struct fown_struct to contain a tref
Date: Sun, 29 Jan 2006 00:35:09 -0700 [thread overview]
Message-ID: <m14q3na3ma.fsf_-_@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <m18xsza3p4.fsf_-_@ebiederm.dsl.xmission.com> (Eric W. Biederman's message of "Sun, 29 Jan 2006 00:33:27 -0700")
File handles can be requested to send sigio and sigurg
to processes. This code modifies the code to track
those processes making the interface safe from pid
wrap around issues.
It's not a big deal deal but since it is easy to track
the proceses we might as well.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
fs/fcntl.c | 45 ++++++++++++++++++++++++---------------------
fs/file_table.c | 1 +
include/linux/fs.h | 1 +
net/socket.c | 5 ++++-
4 files changed, 30 insertions(+), 22 deletions(-)
4c0475dcf7c47c1590c5d7dd06c28a457ebabe33
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 5f96786..af1b02a 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -251,8 +251,17 @@ static int setfl(int fd, struct file * f
static void f_modown(struct file *filp, unsigned long pid,
uid_t uid, uid_t euid, int force)
{
+
+ enum pid_type type;
+ int who = pid;
+ type = PIDTYPE_PID;
+ if (who < 0) {
+ type = PIDTYPE_PGID;
+ who = -who;
+ }
write_lock_irq(&filp->f_owner.lock);
if (force || !filp->f_owner.pid) {
+ tref_set(&filp->f_owner.tref, tref_get_by_pid(who, type));
filp->f_owner.pid = pid;
filp->f_owner.uid = uid;
filp->f_owner.euid = euid;
@@ -317,7 +326,9 @@ static long do_fcntl(int fd, unsigned in
* current syscall conventions, the only way
* to fix this will be in libc.
*/
- err = filp->f_owner.pid;
+ err = 0;
+ if (filp->f_owner.tref->task)
+ err = filp->f_owner.pid;
force_successful_syscall_return();
break;
case F_SETOWN:
@@ -469,6 +480,7 @@ static void send_sigio_to_task(struct ta
void send_sigio(struct fown_struct *fown, int fd, int band)
{
struct task_struct *p;
+ enum pid_type type;
int pid;
read_lock(&fown->lock);
@@ -477,16 +489,11 @@ void send_sigio(struct fown_struct *fown
goto out_unlock_fown;
read_lock(&tasklist_lock);
- if (pid > 0) {
- p = find_task_by_pid(pid);
- if (p) {
- send_sigio_to_task(p, fown, fd, band);
- }
- } else {
- do_each_task_pid(-pid, PIDTYPE_PGID, p) {
- send_sigio_to_task(p, fown, fd, band);
- } while_each_task_pid(-pid, PIDTYPE_PGID, p);
- }
+ type = fown->tref->type;
+ p = fown->tref->task;
+ do_each_task(p, type) {
+ send_sigio_to_task(p, fown, fd, band);
+ } while_each_task(p, type);
read_unlock(&tasklist_lock);
out_unlock_fown:
read_unlock(&fown->lock);
@@ -503,6 +510,7 @@ int send_sigurg(struct fown_struct *fown
{
struct task_struct *p;
int pid, ret = 0;
+ enum pid_type type;
read_lock(&fown->lock);
pid = fown->pid;
@@ -512,16 +520,11 @@ int send_sigurg(struct fown_struct *fown
ret = 1;
read_lock(&tasklist_lock);
- if (pid > 0) {
- p = find_task_by_pid(pid);
- if (p) {
- send_sigurg_to_task(p, fown);
- }
- } else {
- do_each_task_pid(-pid, PIDTYPE_PGID, p) {
- send_sigurg_to_task(p, fown);
- } while_each_task_pid(-pid, PIDTYPE_PGID, p);
- }
+ type = fown->tref->type;
+ p = fown->tref->task;
+ do_each_task(p, type) {
+ send_sigurg_to_task(p, fown);
+ } while_each_task(p, type);
read_unlock(&tasklist_lock);
out_unlock_fown:
read_unlock(&fown->lock);
diff --git a/fs/file_table.c b/fs/file_table.c
index 768b581..fb70a30 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -97,6 +97,7 @@ struct file *get_empty_filp(void)
rwlock_init(&f->f_owner.lock);
/* f->f_version: 0 */
INIT_LIST_HEAD(&f->f_u.fu_list);
+ f->f_owner.tref = &init_tref;
return f;
over:
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 84bb449..35449c2 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -587,6 +587,7 @@ extern struct block_device *I_BDEV(struc
struct fown_struct {
rwlock_t lock; /* protects pid, uid, euid fields */
+ struct task_ref *tref; /* Reference to the task/process group */
int pid; /* pid or -pgrp where SIGIO should be sent */
uid_t uid, euid; /* uid/euid of process setting the owner */
void *security;
diff --git a/net/socket.c b/net/socket.c
index b38a263..4294a77 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -855,7 +855,10 @@ static long sock_ioctl(struct file *file
break;
case FIOGETOWN:
case SIOCGPGRP:
- err = put_user(sock->file->f_owner.pid, (int __user *)argp);
+ pid = 0;
+ if (sock->file->f_owner.tref->task)
+ pid = sock->file->f_owner.pid;
+ err = put_user(pid, (int __user *)argp);
break;
case SIOCGIFBR:
case SIOCSIFBR:
--
1.1.5.g3480
next prev parent reply other threads:[~2006-01-29 7:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-29 7:19 [RFC][PATCH 0/5] Task references Eric W. Biederman
2006-01-29 7:22 ` [PATCH 1/5] pid: Implement task references Eric W. Biederman
2006-01-29 7:24 ` [PATCH 2/5] pid: Add macros for interating through tasks by type Eric W. Biederman
2006-01-29 7:28 ` [PATCH 3/5] pid: Implement kill_tref Eric W. Biederman
2006-01-29 7:33 ` [PATCH 4/5] vt: Update spawnpid to use a task_ref Eric W. Biederman
2006-01-29 7:35 ` Eric W. Biederman [this message]
2006-01-29 8:43 ` [PATCH 5/5] file: Modify struct fown_struct to contain a tref Suleiman Souhlal
2006-01-29 9:18 ` Eric W. Biederman
2006-01-30 10:51 ` [PATCH 4/5] vt: Update spawnpid to use a task_ref Pavel Machek
2006-01-30 20:39 ` Eric W. Biederman
2006-01-30 21:05 ` Pavel Machek
2006-01-30 21:15 ` Eric W. Biederman
2006-01-29 8:46 ` [PATCH 1/5] pid: Implement task references Suleiman Souhlal
2006-01-29 19:05 ` Greg KH
2006-01-29 21:58 ` Eric W. Biederman
2006-01-30 4:51 ` Greg KH
2006-01-30 5:19 ` Eric Dumazet
2006-01-30 5:35 ` Kyle Moffett
2006-01-30 5:46 ` Eric Dumazet
2006-01-30 6:46 ` Kyle Moffett
2006-01-30 18:43 ` Greg KH
2006-01-30 19:58 ` Eric Dumazet
2006-01-30 20:45 ` Eric W. Biederman
2006-01-30 21:32 ` Eric Dumazet
2006-01-30 21:51 ` Eric W. Biederman
2006-01-30 20:13 ` Eric W. Biederman
2006-01-31 6:58 ` Greg KH
2006-01-31 16:04 ` Eric W. Biederman
2006-01-29 8:05 ` [RFC][PATCH 0/5] Task references Kyle Moffett
2006-02-06 8:09 ` Eric W. Biederman
2006-02-06 14:36 ` Serge E. Hallyn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m14q3na3ma.fsf_-_@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=clg@fr.ibm.com \
--cc=frankeh@watson.ibm.com \
--cc=haveblue@us.ibm.com \
--cc=herbert@13thfloor.at \
--cc=linux-kernel@vger.kernel.org \
--cc=mrmacman_g4@mac.com \
--cc=serue@us.ibm.com \
--cc=ssouhlal@FreeBSD.org \
--cc=vserver@list.linux-vserver.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®