aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2006-12-13 03:35:10 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-13 12:05:53 -0500
commit3cec556a84be02bcd8755422eec61f1b9bee4e2f (patch)
tree9abfef8aa9d62225e161f4d200be5bb70ead1ab6
parentb3f13debd593dbd7242a4ecf6c9b4d529805e5a0 (diff)
[PATCH] n_r3964: Use struct pid to track user space clients
Currently this driver tracks user space clients it should send signals to. In the presenct of file descriptor passing this is appears susceptible to confusion from pid wrap around issues. Replacing this with a struct pid prevents us from getting confused, and prepares for a pid namespace implementation. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/char/n_r3964.c37
-rw-r--r--include/linux/n_r3964.h2
2 files changed, 18 insertions, 21 deletions
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 103d338f21e2..dc6d41841457 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -125,8 +125,8 @@ static void transmit_block(struct r3964_info *pInfo);
125static void receive_char(struct r3964_info *pInfo, const unsigned char c); 125static void receive_char(struct r3964_info *pInfo, const unsigned char c);
126static void receive_error(struct r3964_info *pInfo, const char flag); 126static void receive_error(struct r3964_info *pInfo, const char flag);
127static void on_timeout(unsigned long priv); 127static void on_timeout(unsigned long priv);
128static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg); 128static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg);
129static int read_telegram(struct r3964_info *pInfo, pid_t pid, unsigned char __user *buf); 129static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf);
130static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg, 130static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
131 int error_code, struct r3964_block_header *pBlock); 131 int error_code, struct r3964_block_header *pBlock);
132static struct r3964_message* remove_msg(struct r3964_info *pInfo, 132static struct r3964_message* remove_msg(struct r3964_info *pInfo,
@@ -829,7 +829,7 @@ static void on_timeout(unsigned long priv)
829} 829}
830 830
831static struct r3964_client_info *findClient( 831static struct r3964_client_info *findClient(
832 struct r3964_info *pInfo, pid_t pid) 832 struct r3964_info *pInfo, struct pid *pid)
833{ 833{
834 struct r3964_client_info *pClient; 834 struct r3964_client_info *pClient;
835 835
@@ -843,7 +843,7 @@ static struct r3964_client_info *findClient(
843 return NULL; 843 return NULL;
844} 844}
845 845
846static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg) 846static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
847{ 847{
848 struct r3964_client_info *pClient; 848 struct r3964_client_info *pClient;
849 struct r3964_client_info **ppClient; 849 struct r3964_client_info **ppClient;
@@ -858,7 +858,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg)
858 858
859 if(pClient->pid == pid) 859 if(pClient->pid == pid)
860 { 860 {
861 TRACE_PS("removing client %d from client list", pid); 861 TRACE_PS("removing client %d from client list", pid_nr(pid));
862 *ppClient = pClient->next; 862 *ppClient = pClient->next;
863 while(pClient->msg_count) 863 while(pClient->msg_count)
864 { 864 {
@@ -869,6 +869,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg)
869 TRACE_M("enable_signals - msg kfree %p",pMsg); 869 TRACE_M("enable_signals - msg kfree %p",pMsg);
870 } 870 }
871 } 871 }
872 put_pid(pClient->pid);
872 kfree(pClient); 873 kfree(pClient);
873 TRACE_M("enable_signals - kfree %p",pClient); 874 TRACE_M("enable_signals - kfree %p",pClient);
874 return 0; 875 return 0;
@@ -892,10 +893,10 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg)
892 if(pClient==NULL) 893 if(pClient==NULL)
893 return -ENOMEM; 894 return -ENOMEM;
894 895
895 TRACE_PS("add client %d to client list", pid); 896 TRACE_PS("add client %d to client list", pid_nr(pid));
896 spin_lock_init(&pClient->lock); 897 spin_lock_init(&pClient->lock);
897 pClient->sig_flags=arg; 898 pClient->sig_flags=arg;
898 pClient->pid = pid; 899 pClient->pid = get_pid(pid);
899 pClient->next=pInfo->firstClient; 900 pClient->next=pInfo->firstClient;
900 pClient->first_msg = NULL; 901 pClient->first_msg = NULL;
901 pClient->last_msg = NULL; 902 pClient->last_msg = NULL;
@@ -908,7 +909,7 @@ static int enable_signals(struct r3964_info *pInfo, pid_t pid, int arg)
908 return 0; 909 return 0;
909} 910}
910 911
911static int read_telegram(struct r3964_info *pInfo, pid_t pid, unsigned char __user *buf) 912static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf)
912{ 913{
913 struct r3964_client_info *pClient; 914 struct r3964_client_info *pClient;
914 struct r3964_block_header *block; 915 struct r3964_block_header *block;
@@ -1005,7 +1006,7 @@ queue_the_message:
1005 /* Send SIGIO signal to client process: */ 1006 /* Send SIGIO signal to client process: */
1006 if(pClient->sig_flags & R3964_USE_SIGIO) 1007 if(pClient->sig_flags & R3964_USE_SIGIO)
1007 { 1008 {
1008 kill_proc(pClient->pid, SIGIO, 1); 1009 kill_pid(pClient->pid, SIGIO, 1);
1009 } 1010 }
1010} 1011}
1011 1012
@@ -1042,7 +1043,7 @@ static void remove_client_block(struct r3964_info *pInfo,
1042{ 1043{
1043 struct r3964_block_header *block; 1044 struct r3964_block_header *block;
1044 1045
1045 TRACE_PS("remove_client_block PID %d", pClient->pid); 1046 TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
1046 1047
1047 block=pClient->next_block_to_read; 1048 block=pClient->next_block_to_read;
1048 if(block) 1049 if(block)
@@ -1157,6 +1158,7 @@ static void r3964_close(struct tty_struct *tty)
1157 TRACE_M("r3964_close - msg kfree %p",pMsg); 1158 TRACE_M("r3964_close - msg kfree %p",pMsg);
1158 } 1159 }
1159 } 1160 }
1161 put_pid(pClient->pid);
1160 kfree(pClient); 1162 kfree(pClient);
1161 TRACE_M("r3964_close - client kfree %p",pClient); 1163 TRACE_M("r3964_close - client kfree %p",pClient);
1162 pClient=pNext; 1164 pClient=pNext;
@@ -1193,12 +1195,11 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1193 struct r3964_client_message theMsg; 1195 struct r3964_client_message theMsg;
1194 DECLARE_WAITQUEUE (wait, current); 1196 DECLARE_WAITQUEUE (wait, current);
1195 1197
1196 int pid = current->pid;
1197 int count; 1198 int count;
1198 1199
1199 TRACE_L("read()"); 1200 TRACE_L("read()");
1200 1201
1201 pClient=findClient(pInfo, pid); 1202 pClient=findClient(pInfo, task_pid(current));
1202 if(pClient) 1203 if(pClient)
1203 { 1204 {
1204 pMsg = remove_msg(pInfo, pClient); 1205 pMsg = remove_msg(pInfo, pClient);
@@ -1252,7 +1253,6 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file,
1252 struct r3964_block_header *pHeader; 1253 struct r3964_block_header *pHeader;
1253 struct r3964_client_info *pClient; 1254 struct r3964_client_info *pClient;
1254 unsigned char *new_data; 1255 unsigned char *new_data;
1255 int pid;
1256 1256
1257 TRACE_L("write request, %d characters", count); 1257 TRACE_L("write request, %d characters", count);
1258/* 1258/*
@@ -1295,9 +1295,7 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file,
1295 pHeader->locks = 0; 1295 pHeader->locks = 0;
1296 pHeader->owner = NULL; 1296 pHeader->owner = NULL;
1297 1297
1298 pid=current->pid; 1298 pClient=findClient(pInfo, task_pid(current));
1299
1300 pClient=findClient(pInfo, pid);
1301 if(pClient) 1299 if(pClient)
1302 { 1300 {
1303 pHeader->owner = pClient; 1301 pHeader->owner = pClient;
@@ -1328,7 +1326,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file,
1328 switch(cmd) 1326 switch(cmd)
1329 { 1327 {
1330 case R3964_ENABLE_SIGNALS: 1328 case R3964_ENABLE_SIGNALS:
1331 return enable_signals(pInfo, current->pid, arg); 1329 return enable_signals(pInfo, task_pid(current), arg);
1332 case R3964_SETPRIORITY: 1330 case R3964_SETPRIORITY:
1333 if(arg<R3964_MASTER || arg>R3964_SLAVE) 1331 if(arg<R3964_MASTER || arg>R3964_SLAVE)
1334 return -EINVAL; 1332 return -EINVAL;
@@ -1341,7 +1339,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file,
1341 pInfo->flags &= ~R3964_BCC; 1339 pInfo->flags &= ~R3964_BCC;
1342 return 0; 1340 return 0;
1343 case R3964_READ_TELEGRAM: 1341 case R3964_READ_TELEGRAM:
1344 return read_telegram(pInfo, current->pid, (unsigned char __user *)arg); 1342 return read_telegram(pInfo, task_pid(current), (unsigned char __user *)arg);
1345 default: 1343 default:
1346 return -ENOIOCTLCMD; 1344 return -ENOIOCTLCMD;
1347 } 1345 }
@@ -1357,7 +1355,6 @@ static unsigned int r3964_poll(struct tty_struct * tty, struct file * file,
1357 struct poll_table_struct *wait) 1355 struct poll_table_struct *wait)
1358{ 1356{
1359 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1357 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data;
1360 int pid=current->pid;
1361 struct r3964_client_info *pClient; 1358 struct r3964_client_info *pClient;
1362 struct r3964_message *pMsg=NULL; 1359 struct r3964_message *pMsg=NULL;
1363 unsigned long flags; 1360 unsigned long flags;
@@ -1365,7 +1362,7 @@ static unsigned int r3964_poll(struct tty_struct * tty, struct file * file,
1365 1362
1366 TRACE_L("POLL"); 1363 TRACE_L("POLL");
1367 1364
1368 pClient=findClient(pInfo,pid); 1365 pClient=findClient(pInfo, task_pid(current));
1369 if(pClient) 1366 if(pClient)
1370 { 1367 {
1371 poll_wait(file, &pInfo->read_wait, wait); 1368 poll_wait(file, &pInfo->read_wait, wait);
diff --git a/include/linux/n_r3964.h b/include/linux/n_r3964.h
index db4f3776978a..de24af79ebd3 100644
--- a/include/linux/n_r3964.h
+++ b/include/linux/n_r3964.h
@@ -116,7 +116,7 @@ struct r3964_message;
116 116
117struct r3964_client_info { 117struct r3964_client_info {
118 spinlock_t lock; 118 spinlock_t lock;
119 pid_t pid; 119 struct pid *pid;
120 unsigned int sig_flags; 120 unsigned int sig_flags;
121 121
122 struct r3964_client_info *next; 122 struct r3964_client_info *next;