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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160316094805.GK2231@uranus.lan>
Date:	Wed, 16 Mar 2016 12:48:05 +0300
From:	Cyrill Gorcunov <gorcunov@...il.com>
To:	Jiri Slaby <jslaby@...e.cz>, LKML <linux-kernel@...r.kernel.org>
Cc:	Peter Hurley <peter@...leysoftware.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Andrey Vagin <avagin@...tuozzo.com>,
	Konstantin Khorenko <khorenko@...tuozzo.com>,
	Vladimir Davydov <vdavydov@...tuozzo.com>,
	Pavel Emelianov <xemul@...tuozzo.com>
Subject: [PATCH v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread
 data

On Sun, Mar 13, 2016 at 01:35:23PM +0300, Cyrill Gorcunov wrote:
> On Sun, Mar 13, 2016 at 11:14:46AM +0100, Jiri Slaby wrote:
> > On 03/12/2016, 03:18 PM, Cyrill Gorcunov wrote:
> > > --- linux-ml.git.orig/include/uapi/asm-generic/ioctls.h
> > > +++ linux-ml.git/include/uapi/asm-generic/ioctls.h
> > > @@ -77,6 +77,7 @@
> > >  #define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
> > >  #define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
> > >  #define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
> > > +#define TIOCPEEKRAW	_IOR('T', 0x41, void *)
> > 
> > Hi, this is not 32/64bit compatible and would need a compat ioctl number
> > and a wrapper. Since it is char *, could you make it just 'char'?
> 
> Hi Jiri, sure, thanks! Lets wait for more feedback, maybe there some
> other more elegant solution possible, which I failed to invent.

Here is an updated one. Hopefully I didn't miss anything. Any comments
are highly appreciated.
---
From: Cyrill Gorcunov <gorcunov@...tuozzo.com>
Subject: [PATCH v2] tty: n_tty -- Add new TIOCPEEKRAW ioctl to peek unread data

Currently when we checkpoint PTY connections we ignore data queued inside
read buffer of ldisk, such data is barely lost after the restore. So we
would like to have an ability to dump and restore it.

Here is a new ioctl code which simply copies data from read buffer
into the userspace without any additional processing (just like
terminal is sitting in a raw mode).

The idea behind is when we checkpointing PTY pairs we peek
this unread data into images on disk and on restore phase
we find the linked peer and write it back thus reading
peer will see it in read buffer.

I tried several approaches (including simply reuse of
canon_copy_from_read_buf and copy_from_read_buf) but
it not always do the trick: for example if data queued
doesn't have \n symbol the input_available_p helper
returns false and I shouldn't call for the helpers
above. So I end up in plain copying.

v2:
 - Use @char in ioctl definition.

Signed-off-by: Cyrill Gorcunov <gorcunov@...tuozzo.com>
CC: Jiri Slaby <jslaby@...e.com>
CC: Peter Hurley <peter@...leysoftware.com>
CC: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC: Andrey Vagin <avagin@...tuozzo.com>
CC: Pavel Emelianov <xemul@...tuozzo.com>
CC: Vladimir Davydov <vdavydov@...tuozzo.com>
CC: Konstantin Khorenko <khorenko@...tuozzo.com>
---
 drivers/tty/n_tty.c               |   22 ++++++++++++++++++++++
 include/uapi/asm-generic/ioctls.h |    1 +
 2 files changed, 23 insertions(+)

Index: linux-ml.git/drivers/tty/n_tty.c
===================================================================
--- linux-ml.git.orig/drivers/tty/n_tty.c
+++ linux-ml.git/drivers/tty/n_tty.c
@@ -2485,6 +2485,26 @@ static unsigned long inq_canon(struct n_
 	return nr;
 }
 
+static ssize_t n_tty_peek_raw(struct tty_struct *tty, unsigned char __user *buf)
+{
+	struct n_tty_data *ldata = tty->disc_data;
+	ssize_t retval;
+
+	if (!mutex_trylock(&ldata->atomic_read_lock))
+		return -EAGAIN;
+
+	down_read(&tty->termios_rwsem);
+	retval = read_cnt(ldata);
+	if (retval) {
+		const unsigned char *from = read_buf_addr(ldata, ldata->read_tail);
+		if (copy_to_user(buf, from, retval))
+			retval = -EFAULT;
+	}
+	up_read(&tty->termios_rwsem);
+	mutex_unlock(&ldata->atomic_read_lock);
+	return retval;
+}
+
 static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
 		       unsigned int cmd, unsigned long arg)
 {
@@ -2502,6 +2522,8 @@ static int n_tty_ioctl(struct tty_struct
 			retval = read_cnt(ldata);
 		up_write(&tty->termios_rwsem);
 		return put_user(retval, (unsigned int __user *) arg);
+	case TIOCPEEKRAW:
+		return n_tty_peek_raw(tty, (unsigned char __user *) arg);
 	default:
 		return n_tty_ioctl_helper(tty, file, cmd, arg);
 	}
Index: linux-ml.git/include/uapi/asm-generic/ioctls.h
===================================================================
--- linux-ml.git.orig/include/uapi/asm-generic/ioctls.h
+++ linux-ml.git/include/uapi/asm-generic/ioctls.h
@@ -77,6 +77,7 @@
 #define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
 #define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
 #define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
+#define TIOCPEEKRAW	_IOR('T', 0x41, char)
 
 #define FIONCLEX	0x5450
 #define FIOCLEX		0x5451

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ