diff options
| author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-05-15 10:20:16 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-05-15 10:20:16 +0200 |
| commit | 2c3266e8829eb5a611a08cddca97f79c05ed28db (patch) | |
| tree | b7aaa09c1ee1f738acd83b9a46ae2d135f89b22c /0014-tty-n_r3964-properly-reference-count-pids.patch | |
| parent | cf6fd4d72fe78061c68af7a241387ec2d26dc161 (diff) | |
| download | patches-2c3266e8829eb5a611a08cddca97f79c05ed28db.tar.gz | |
tty patches added
Diffstat (limited to '0014-tty-n_r3964-properly-reference-count-pids.patch')
| -rw-r--r-- | 0014-tty-n_r3964-properly-reference-count-pids.patch | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/0014-tty-n_r3964-properly-reference-count-pids.patch b/0014-tty-n_r3964-properly-reference-count-pids.patch new file mode 100644 index 00000000000000..68aec18727fa26 --- /dev/null +++ b/0014-tty-n_r3964-properly-reference-count-pids.patch @@ -0,0 +1,103 @@ +From 4607af3f8237114c8c679e5d976ef00fe7053123 Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +Date: Fri, 25 Jan 2019 16:47:16 +0100 +Subject: [PATCH 14/15] tty: n_r3964: properly reference count pids + +The driver likes to look up things based on the current pid, yet the +structure is never properly reference counted when passing around the +pointer. Luckily when it is saved off it is correct, but for all other +usages, we need to handle the reference properly. + +The function find_client_current() is created to handle some of the +common housekeeping when trying to lookup a structure on the current +pid. + +Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> +--- + drivers/tty/n_r3964.c | 28 ++++++++++++++++++++++------ + 1 file changed, 22 insertions(+), 6 deletions(-) + +diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c +index a00c34ea9c27..aef0befd068d 100644 +--- a/drivers/tty/n_r3964.c ++++ b/drivers/tty/n_r3964.c +@@ -770,6 +770,18 @@ static struct r3964_client_info *findClient(struct r3964_info *pInfo, + return pClient; + } + ++/* Find a client that refers to the pid of the current task */ ++static struct r3964_client_info *find_client_current(struct r3964_info *info) ++{ ++ struct r3964_client_info *client; ++ struct pid *pid; ++ ++ pid = get_pid(task_pid(current)); ++ client = findClient(info, pid); ++ put_pid(pid); ++ return client; ++} ++ + static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg) + { + struct r3964_client_info *pClient; +@@ -1121,7 +1133,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file, + return -ERESTARTSYS; + } + +- pClient = findClient(pInfo, task_pid(current)); ++ pClient = find_client_current(pInfo); + if (pClient) { + pMsg = remove_msg(pClient); + if (pMsg == NULL) { +@@ -1208,7 +1220,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file, + pHeader->length = count; + pHeader->owner = NULL; + +- pClient = findClient(pInfo, task_pid(current)); ++ pClient = find_client_current(pInfo); + if (pClient) { + pHeader->owner = pClient; + } +@@ -1232,6 +1244,7 @@ static int r3964_ioctl(struct tty_struct *tty, struct file *file, + unsigned int cmd, unsigned long arg) + { + struct r3964_info *pInfo = tty->disc_data; ++ struct pid *pid; + unsigned long flags; + int retval = 0; + +@@ -1249,7 +1262,9 @@ static int r3964_ioctl(struct tty_struct *tty, struct file *file, + return -ERESTARTSYS; + } + +- retval = enable_signals(pInfo, task_pid(current), arg); ++ pid = get_pid(task_pid(current)); ++ retval = enable_signals(pInfo, pid, arg); ++ put_pid(pid); + + mutex_unlock(&pInfo->read_lock); + break; +@@ -1269,8 +1284,9 @@ static int r3964_ioctl(struct tty_struct *tty, struct file *file, + spin_unlock_irqrestore(&pInfo->lock, flags); + break; + case R3964_READ_TELEGRAM: +- retval = read_telegram(pInfo, task_pid(current), +- (unsigned char __user *)arg); ++ pid = get_pid(task_pid(current)); ++ retval = read_telegram(pInfo, pid, (unsigned char __user *)arg); ++ put_pid(pid); + break; + default: + retval = -ENOIOCTLCMD; +@@ -1311,7 +1327,7 @@ static __poll_t r3964_poll(struct tty_struct *tty, struct file *file, + + TRACE_L("POLL"); + +- pClient = findClient(pInfo, task_pid(current)); ++ pClient = find_client_current(pInfo); + if (pClient) { + poll_wait(file, &tty->read_wait, wait); + spin_lock_irqsave(&pClient->lock, flags); +-- +2.21.0 + |
