Skip to content

Commit 00efb0d

Browse files
committed
Rewrite of last_siginfo_read() and eventmessage_read()
1 parent 101a0e2 commit 00efb0d

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

fs/proc/base.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include <linux/errno.h>
5353
#include <linux/time.h>
5454
#include <linux/proc_fs.h>
55-
#include <linux/signal.h>
5655
#include <linux/stat.h>
5756
#include <linux/task_io_accounting_ops.h>
5857
#include <linux/init.h>
@@ -1069,12 +1068,18 @@ static const struct file_operations proc_ctl_operations = {
10691068

10701069
static ssize_t eventmessage_read(struct file *file, char __user *buf,
10711070
size_t count, loff_t *ppos) {
1071+
int length;
10721072
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
10731073

1074-
if (count < sizeof(task->ptrace_message))
1075-
return -EIO;
1074+
length = -ESRCH;
1075+
if (!task)
1076+
goto out_no_task;
10761077

1077-
return put_user(task->ptrace_message, buf);
1078+
length = simple_read_from_buffer(buf, count, ppos,
1079+
(char *)&task->ptrace_message, sizeof(task->ptrace_message));
1080+
1081+
out_no_task:
1082+
return length;
10781083
}
10791084

10801085
static const struct file_operations proc_eventmessage_operations = {
@@ -1086,27 +1091,30 @@ static ssize_t last_siginfo_read(struct file *file, char __user *buf,
10861091
size_t count, loff_t *ppos) {
10871092
unsigned long flags;
10881093
siginfo_t info;
1089-
int error = -ESRCH;
1094+
int length;
10901095
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
10911096

1092-
if (count < sizeof(siginfo_t) && lock_task_sighand(task, &flags)) {
1093-
error = -EINVAL;
1097+
length = -ESRCH;
1098+
if (!task)
1099+
goto out_no_task;
1100+
length = -EINVAL;
1101+
1102+
if (lock_task_sighand(task, &flags)) {
1103+
length = 0;
10941104
if (likely(task->last_siginfo != NULL)) {
10951105
info = *task->last_siginfo;
1096-
error = 0;
1106+
length = sizeof(info);
10971107
}
10981108

10991109
unlock_task_sighand(task, &flags);
11001110
}
11011111

1102-
if (!error) {
1103-
error = copy_siginfo_to_user((siginfo_t __user *) buf, &info);
1104-
}
1105-
1106-
if (!error)
1107-
error = sizeof(siginfo_t);
1112+
if (length >= 0)
1113+
length = simple_read_from_buffer(buf, count,
1114+
ppos, (char *)&info, length);
11081115

1109-
return error;
1116+
out_no_task:
1117+
return length;
11101118
}
11111119

11121120
static const struct file_operations proc_last_siginfo_operations = {

kernel/signal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ static int proctrace_signal(int signr, siginfo_t *info) {
21442144
set_current_state(TASK_RUNNING);
21452145
spin_lock_irq(&current->sighand->siglock);
21462146
current->last_siginfo = NULL;
2147+
printk("PROCTRACE Ubijam last_siginfo\n");
21472148
}
21482149

21492150
return retval;

0 commit comments

Comments
 (0)