lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20070110121806.GB28862@2ka.mipt.ru>
Date:	Wed, 10 Jan 2007 15:18:06 +0300
From:	Evgeniy Polyakov <johnpol@....mipt.ru>
To:	Jeff Garzik <jeff@...zik.org>
Cc:	David Miller <davem@...emloft.net>,
	Ulrich Drepper <drepper@...hat.com>,
	Andrew Morton <akpm@...l.org>, netdev <netdev@...r.kernel.org>,
	Zach Brown <zach.brown@...cle.com>,
	Christoph Hellwig <hch@...radead.org>,
	Chase Venters <chase.venters@...entec.com>,
	Johann Borck <johann.borck@...sedata.com>,
	linux-kernel@...r.kernel.org, Jamal Hadi Salim <hadi@...erus.ca>,
	Ingo Molnar <mingo@...e.hu>, linux-fsdevel@...r.kernel.org
Subject: Kevent bonus: epoll implementaion over kevent.

As a usage scenario, compile-tested only.
Replace fs/eventpoll.c with this code and see,
how your kernel crashes. Or works.

:)

Signed-off-by: Evgeniy Polyakov <johnpol@....mipt.ru>

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/kevent.h>
#include <linux/ukevent.h>
#include <linux/syscalls.h>
#include <asm/poll.h>
#include <asm/uaccess.h>
#include <linux/eventpoll.h>

asmlinkage long sys_epoll_create(int size)
{
	return sys_kevent_init(NULL, 0, 0);
}

#define EP_PRIVATE_BITS (EPOLLONESHOT | EPOLLET)

asmlinkage long sys_epoll_ctl(int epfd, int op, int fd, struct epoll_event __user *event)
{
	struct epoll_event epds;
	struct ukevent uk;
	int cmd, err;

	switch (op) {
		case EPOLL_CTL_DEL:
			cmd = KEVENT_CTL_REMOVE;
			break;
		case EPOLL_CTL_ADD:
			cmd = KEVENT_CTL_ADD;
			break;
		case EPOLL_CTL_MOD:
			cmd = KEVENT_CTL_MODIFY;
			break;
		default:
			err = -EINVAL;
			goto err_out_exit;
	}

	if (copy_from_user(&epds, event, sizeof(struct epoll_event))) {
		err = -EFAULT;
		goto err_out_exit;
	}

	memset(&uk, 0, sizeof(struct ukevent));

	uk.id.raw[0] = fd;
	memcpy(uk.user, &epds.data, sizeof(u64));
	uk.type = KEVENT_POLL;
	uk.event = (epds.events & ~EP_PRIVATE_BITS)| POLLERR | POLLHUP;
	uk.req_flags = KEVENT_REQ_ALWAYS_QUEUE | KEVENT_REQ_LAST_CHECK;
	if (epds.events & EPOLLONESHOT)
		uk.req_flags |= KEVENT_REQ_ONESHOT;
	if (epds.events & EPOLLET)
		uk.req_flags |= KEVENT_REQ_ET;

	return sys_kevent_ctl(epfd, cmd, 1, &uk);

err_out_exit:
	return err;
}

asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events,
			       int maxevents, int timeout)
{
	struct ukevent uk[3];
	struct timespec ts;
	long num, i;
	int err;
	
	if (!access_ok(VERIFY_WRITE, events, maxevents * sizeof(struct epoll_event))) {
		err = -EFAULT;
		goto err_out_exit;
	}

	memset(uk, 0, sizeof(uk));

	ts.tv_sec = timeout/1000;
	ts.tv_nsec = (timeout - ts.tv_sec*1000)*1000;

	num = sys_kevent_get_events(epfd, 1, min(3, maxevents), ts, uk, 0);
	if (num <= 0)
		return num;

	for (i=0; i<num; ++i) {
		__u64 data;

		memcpy(&data, &uk[i].user, sizeof(u64));

		if (__put_user(uk[i].ret_data[0], &events[i].events) ||
		    __put_user(data, &events[i].data))
			return -EFAULT;
	}

	return num;

err_out_exit:
	return err;
}


-- 
	Evgeniy Polyakov
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ