[CRIU] [PATCH 3/3] signalfd: add ability to send any siginfo to itself

Andrey Vagin avagin at openvz.org
Thu Nov 29 11:51:51 EST 2012


The operation writes takes siginfo from a buffer and send it
in a queue. If a signalfd is created with the flag SFD_GROUP,
siginfo will be sent in a group queue, otherwise in a local queue.

rt_siginfoqueue doesn't allow to send siginfo with positive si_code,
and it's correct, because a positive si_code is reserved for kernel
signals. But if process will send "incorrect" siginfo to itself,
this operation doesn't look danger.

This functionality will be used for restoring pending signals.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 fs/signalfd.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/fs/signalfd.c b/fs/signalfd.c
index bd10b06..de001e4 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -259,6 +259,40 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,
 	return total ? total: ret;
 }
 
+static ssize_t signalfd_write(struct file *file, const char __user *buf, size_t count,
+			     loff_t *ppos)
+{
+	siginfo_t __user *siginfo;
+	bool group = file->f_flags & SFD_GROUP;
+	ssize_t ret, total = 0;
+	siginfo_t info;
+
+	count /= sizeof(struct signalfd_siginfo);
+	if (!count)
+		return -EINVAL;
+
+	siginfo = (siginfo_t __user *) buf;
+	do {
+		ret = copy_from_user(&info, siginfo, sizeof(siginfo_t));
+		if (ret < 0)
+			break;
+
+		if (!valid_signal(info.si_signo)) {
+			ret = -EINVAL;
+			break;
+		}
+
+		ret = do_send_sig_info(info.si_signo, &info, current, group);
+		if (ret < 0)
+			break;
+
+		siginfo++;
+		total += sizeof(*siginfo);
+	} while (--count);
+
+	return total ? total: ret;
+}
+
 #ifdef CONFIG_PROC_FS
 static int signalfd_show_fdinfo(struct seq_file *m, struct file *f)
 {
@@ -280,6 +314,7 @@ static const struct file_operations signalfd_fops = {
 	.release	= signalfd_release,
 	.poll		= signalfd_poll,
 	.read		= signalfd_read,
+	.write		= signalfd_write,
 	.llseek		= noop_llseek,
 };
 
-- 
1.7.11.7



More information about the CRIU mailing list