r1107 - in trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian: . patches

Christoph Hellwig hch-guest@haydn.debian.org
Sat, 14 Aug 2004 14:45:36 -0600


Author: hch-guest
Date: 2004-08-14 14:45:31 -0600 (Sat, 14 Aug 2004)
New Revision: 1107

Added:
   trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/ptmx-fix.dpatch
Modified:
   trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/changelog
   trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/00list-1
Log:

 * Add pty leak fix from Al Viro



Modified: trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/changelog
===================================================================
--- trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/changelog	2004-08-14 20:45:08 UTC (rev 1106)
+++ trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/changelog	2004-08-14 20:45:31 UTC (rev 1107)
@@ -57,6 +57,8 @@
 
   * Fix IA64 generic kernel compile on UP (Christoph Hellwig).
 
+  * Add pty leak fix from Al Viro (Christoph Hellwig).
+
  -- Andres Salomon <dilinger@voxel.net>  Sat, 14 Aug 2004 02:40:50 -0400
 
 kernel-source-2.6.7 (2.6.7-4) unstable; urgency=high

Modified: trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/00list-1
===================================================================
--- trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/00list-1	2004-08-14 20:45:08 UTC (rev 1106)
+++ trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/00list-1	2004-08-14 20:45:31 UTC (rev 1107)
@@ -24,3 +24,4 @@
 nfs-fix
 SG_IO-cap
 ia64-generic-no-smp
+ptmx-fix

Added: trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/ptmx-fix.dpatch
===================================================================
--- trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/ptmx-fix.dpatch	2004-08-14 20:45:08 UTC (rev 1106)
+++ trunk/kernel/source/kernel-source-2.6.8-2.6.8/debian/patches/ptmx-fix.dpatch	2004-08-14 20:45:31 UTC (rev 1107)
@@ -0,0 +1,190 @@
+#! /bin/sh -e 
+## <PATCHNAME>.dpatch by <PATCH_AUTHOR@EMAI>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: Description: Rewrite /dev/ptx open() handler to avoid leak
+## DP: Patch author: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>
+## DP: Upstream status: submission pending
+
+. $(dirname $0)/DPATCH
+
+@DPATCH@
+diff -urN RC8-rc3-bk4-base/drivers/char/tty_io.c RC8-rc3-bk4-current/drivers/char/tty_io.c
+--- RC8-rc3-bk4-base/drivers/char/tty_io.c	2004-08-09 20:15:43.000000000 -0400
++++ RC8-rc3-bk4-current/drivers/char/tty_io.c	2004-08-10 04:31:44.893061904 -0400
+@@ -142,6 +142,7 @@
+ ssize_t redirected_tty_write(struct file *, const char __user *, size_t, loff_t *);
+ static unsigned int tty_poll(struct file *, poll_table *);
+ static int tty_open(struct inode *, struct file *);
++static int ptmx_open(struct inode *, struct file *);
+ static int tty_release(struct inode *, struct file *);
+ int tty_ioctl(struct inode * inode, struct file * file,
+ 	      unsigned int cmd, unsigned long arg);
+@@ -377,6 +378,19 @@
+ 	.fasync		= tty_fasync,
+ };
+ 
++#ifdef CONFIG_UNIX98_PTYS
++static struct file_operations ptmx_fops = {
++	.llseek		= no_llseek,
++	.read		= tty_read,
++	.write		= tty_write,
++	.poll		= tty_poll,
++	.ioctl		= tty_ioctl,
++	.open		= ptmx_open,
++	.release	= tty_release,
++	.fasync		= tty_fasync,
++};
++#endif
++
+ static struct file_operations console_fops = {
+ 	.llseek		= no_llseek,
+ 	.read		= tty_read,
+@@ -1358,53 +1372,13 @@
+ 		return -ENODEV;
+ 	}
+ 
+-#ifdef CONFIG_UNIX98_PTYS
+-	if (device == MKDEV(TTYAUX_MAJOR,2)) {
+-		int idr_ret;
+-
+-		/* find a device that is not in use. */
+-		down(&allocated_ptys_lock);
+-		if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
+-			up(&allocated_ptys_lock);
+-			return -ENOMEM;
+-		}
+-		idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
+-		if (idr_ret < 0) {
+-			up(&allocated_ptys_lock);
+-			if (idr_ret == -EAGAIN)
+-				return -ENOMEM;
+-			return -EIO;
+-		}
+-		if (index >= pty_limit) {
+-			idr_remove(&allocated_ptys, index);
+-			up(&allocated_ptys_lock);
+-			return -EIO;
+-		}
+-		up(&allocated_ptys_lock);
+-
+-		driver = ptm_driver;
+-		retval = init_dev(driver, index, &tty);
+-		if (retval) {
+-			down(&allocated_ptys_lock);
+-			idr_remove(&allocated_ptys, index);
+-			up(&allocated_ptys_lock);
+-			return retval;
+-		}
+-
+-		set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
+-		if (devpts_pty_new(tty->link))
+-			retval = -ENOMEM;
+-	} else
+-#endif
+-	{
+-		driver = get_tty_driver(device, &index);
+-		if (!driver)
+-			return -ENODEV;
++	driver = get_tty_driver(device, &index);
++	if (!driver)
++		return -ENODEV;
+ got_driver:
+-		retval = init_dev(driver, index, &tty);
+-		if (retval)
+-			return retval;
+-	}
++	retval = init_dev(driver, index, &tty);
++	if (retval)
++		return retval;
+ 
+ 	filp->private_data = tty;
+ 	file_move(filp, &tty->tty_files);
+@@ -1431,15 +1405,6 @@
+ 		printk(KERN_DEBUG "error %d in opening %s...", retval,
+ 		       tty->name);
+ #endif
+-
+-#ifdef CONFIG_UNIX98_PTYS
+-		if (index != -1) {
+-			down(&allocated_ptys_lock);
+-			idr_remove(&allocated_ptys, index);
+-			up(&allocated_ptys_lock);
+-		}
+-#endif
+-
+ 		release_dev(filp);
+ 		if (retval != -ERESTARTSYS)
+ 			return retval;
+@@ -1467,6 +1432,62 @@
+ 	return 0;
+ }
+ 
++#ifdef CONFIG_UNIX98_PTYS
++static int ptmx_open(struct inode * inode, struct file * filp)
++{
++	struct tty_struct *tty;
++	int retval;
++	int index;
++	int idr_ret;
++
++	nonseekable_open(inode, filp);
++
++	/* find a device that is not in use. */
++	down(&allocated_ptys_lock);
++	if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
++		up(&allocated_ptys_lock);
++		return -ENOMEM;
++	}
++	idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
++	if (idr_ret < 0) {
++		up(&allocated_ptys_lock);
++		if (idr_ret == -EAGAIN)
++			return -ENOMEM;
++		return -EIO;
++	}
++	if (index >= pty_limit) {
++		idr_remove(&allocated_ptys, index);
++		up(&allocated_ptys_lock);
++		return -EIO;
++	}
++	up(&allocated_ptys_lock);
++
++	retval = init_dev(ptm_driver, index, &tty);
++	if (retval)
++		goto out;
++
++	set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
++	filp->private_data = tty;
++	file_move(filp, &tty->tty_files);
++
++	retval = -ENOMEM;
++	if (devpts_pty_new(tty->link))
++		goto out1;
++
++	check_tty_count(tty, "tty_open");
++	retval = ptm_driver->open(tty, filp);
++	if (!retval)
++		return 0;
++out1:
++	release_dev(filp);
++out:
++	down(&allocated_ptys_lock);
++	idr_remove(&allocated_ptys, index);
++	up(&allocated_ptys_lock);
++	return retval;
++}
++#endif
++
+ static int tty_release(struct inode * inode, struct file * filp)
+ {
+ 	lock_kernel();
+@@ -2441,7 +2462,7 @@
+ 	class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
+ 
+ #ifdef CONFIG_UNIX98_PTYS
+-	cdev_init(&ptmx_cdev, &tty_fops);
++	cdev_init(&ptmx_cdev, &ptmx_fops);
+ 	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
+ 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
+ 		panic("Couldn't register /dev/ptmx driver\n");