* [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
@ 2012-01-02 17:22 Konstantin Khlebnikov
2012-01-02 17:28 ` Greg KH
2012-01-03 8:51 ` Konstantin Khlebnikov
0 siblings, 2 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-02 17:22 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-kernel
cleanup hack added in v2.6.27-3203-g15582d3
comment from that patch:
: pty: If the administrator creates a device for a ptmx slave we should not error
:
: The open path for ptmx slaves is via the ptmx device. Opening them any
: other way is not allowed. Vegard Nossum found that previously this was not
: the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
:
: Signed-off-by: Alan Cox <alan@redhat.com>
: Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
devpts_get_tty() returns non-null only for inodes on devpts, but there is no
inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
Thus we can completely forbid lookup for master-devices and eliminate that hack in
tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
drivers/tty/pty.c | 8 +++-----
drivers/tty/tty_io.c | 12 ++----------
include/linux/tty.h | 3 +--
3 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index e18604b..d2bf3c1 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -526,10 +526,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
struct inode *ptm_inode, int idx)
{
- struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
- if (tty)
- tty = tty->link;
- return tty;
+ /* Master must be open via /dev/ptmx */
+ return ERR_PTR(-EIO);
}
/**
@@ -685,7 +683,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
mutex_lock(&tty_mutex);
tty_lock();
- tty = tty_init_dev(ptm_driver, index, 1);
+ tty = tty_init_dev(ptm_driver, index);
mutex_unlock(&tty_mutex);
if (IS_ERR(tty)) {
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 05085be..7cddf91 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1366,7 +1366,6 @@ static int tty_reopen(struct tty_struct *tty)
* @driver: tty driver we are opening a device on
* @idx: device index
* @ret_tty: returned tty structure
- * @first_ok: ok to open a new device (used by ptmx)
*
* Prepare a tty device. This may not be a "new" clean device but
* could also be an active device. The pty drivers require special
@@ -1386,18 +1385,11 @@ static int tty_reopen(struct tty_struct *tty)
* relaxed for the (most common) case of reopening a tty.
*/
-struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok)
+struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
{
struct tty_struct *tty;
int retval;
- /* Check if pty master is being opened multiple times */
- if (driver->subtype == PTY_TYPE_MASTER &&
- (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
- return ERR_PTR(-EIO);
- }
-
/*
* First time open is complex, especially for PTY devices.
* This code guarantees that either everything succeeds and the
@@ -1909,7 +1901,7 @@ got_driver:
if (retval)
tty = ERR_PTR(retval);
} else
- tty = tty_init_dev(driver, index, 0);
+ tty = tty_init_dev(driver, index);
mutex_unlock(&tty_mutex);
tty_driver_kref_put(driver);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5dbb3cb..d3ebd76 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -480,8 +480,7 @@ extern void free_tty_struct(struct tty_struct *tty);
extern void initialize_tty_struct(struct tty_struct *tty,
struct tty_driver *driver, int idx);
extern void deinitialize_tty_struct(struct tty_struct *tty);
-extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok);
+extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
extern int tty_release(struct inode *inode, struct file *filp);
extern int tty_init_termios(struct tty_struct *tty);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-02 17:22 [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master Konstantin Khlebnikov
@ 2012-01-02 17:28 ` Greg KH
2012-01-02 22:29 ` Konstantin Khlebnikov
2012-01-03 8:51 ` Konstantin Khlebnikov
1 sibling, 1 reply; 10+ messages in thread
From: Greg KH @ 2012-01-02 17:28 UTC (permalink / raw)
To: Konstantin Khlebnikov; +Cc: linux-kernel
On Mon, Jan 02, 2012 at 09:22:31PM +0400, Konstantin Khlebnikov wrote:
> cleanup hack added in v2.6.27-3203-g15582d3
>
> comment from that patch:
>
> : pty: If the administrator creates a device for a ptmx slave we should not error
> :
> : The open path for ptmx slaves is via the ptmx device. Opening them any
> : other way is not allowed. Vegard Nossum found that previously this was not
> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
> :
> : Signed-off-by: Alan Cox <alan@redhat.com>
> : Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Any reason why you didn't include these two people on this patch?
Perhaps they might wish to review it...
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-02 17:28 ` Greg KH
@ 2012-01-02 22:29 ` Konstantin Khlebnikov
2012-01-03 1:08 ` Greg KH
0 siblings, 1 reply; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-02 22:29 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
Greg KH wrote:
> On Mon, Jan 02, 2012 at 09:22:31PM +0400, Konstantin Khlebnikov wrote:
>> cleanup hack added in v2.6.27-3203-g15582d3
>>
>> comment from that patch:
>>
>> : pty: If the administrator creates a device for a ptmx slave we should not error
>> :
>> : The open path for ptmx slaves is via the ptmx device. Opening them any
>> : other way is not allowed. Vegard Nossum found that previously this was not
>> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
>> :
>> : Signed-off-by: Alan Cox<alan@redhat.com>
>> : Signed-off-by: Linus Torvalds<torvalds@linux-foundation.org>
>
> Any reason why you didn't include these two people on this patch?
> Perhaps they might wish to review it...
This is just simple cleanup patch.
>
> greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-02 22:29 ` Konstantin Khlebnikov
@ 2012-01-03 1:08 ` Greg KH
0 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2012-01-03 1:08 UTC (permalink / raw)
To: Konstantin Khlebnikov; +Cc: linux-kernel
On Tue, Jan 03, 2012 at 02:29:08AM +0400, Konstantin Khlebnikov wrote:
> Greg KH wrote:
> >On Mon, Jan 02, 2012 at 09:22:31PM +0400, Konstantin Khlebnikov wrote:
> >>cleanup hack added in v2.6.27-3203-g15582d3
> >>
> >>comment from that patch:
> >>
> >>: pty: If the administrator creates a device for a ptmx slave we should not error
> >>:
> >>: The open path for ptmx slaves is via the ptmx device. Opening them any
> >>: other way is not allowed. Vegard Nossum found that previously this was not
> >>: the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
> >>:
> >>: Signed-off-by: Alan Cox<alan@redhat.com>
> >>: Signed-off-by: Linus Torvalds<torvalds@linux-foundation.org>
> >
> >Any reason why you didn't include these two people on this patch?
> >Perhaps they might wish to review it...
>
> This is just simple cleanup patch.
Even so, please resend and copy them.
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-02 17:22 [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master Konstantin Khlebnikov
2012-01-02 17:28 ` Greg KH
@ 2012-01-03 8:51 ` Konstantin Khlebnikov
2012-01-03 16:16 ` Linus Torvalds
2012-01-05 0:23 ` Greg KH
1 sibling, 2 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-03 8:51 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Alan Cox, Linus Torvalds, linux-kernel
cleanup hack added in v2.6.27-3203-g15582d3
comment from that patch:
: pty: If the administrator creates a device for a ptmx slave we should not error
:
: The open path for ptmx slaves is via the ptmx device. Opening them any
: other way is not allowed. Vegard Nossum found that previously this was not
: the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
:
: Signed-off-by: Alan Cox <alan@redhat.com>
: Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
devpts_get_tty() returns non-null only for inodes on devpts, but there is no
inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
Thus we can completely forbid lookup for master-devices and eliminate that hack in
tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
drivers/tty/pty.c | 8 +++-----
drivers/tty/tty_io.c | 12 ++----------
include/linux/tty.h | 3 +--
3 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index e18604b..d2bf3c1 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -526,10 +526,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
struct inode *ptm_inode, int idx)
{
- struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
- if (tty)
- tty = tty->link;
- return tty;
+ /* Master must be open via /dev/ptmx */
+ return ERR_PTR(-EIO);
}
/**
@@ -685,7 +683,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
mutex_lock(&tty_mutex);
tty_lock();
- tty = tty_init_dev(ptm_driver, index, 1);
+ tty = tty_init_dev(ptm_driver, index);
mutex_unlock(&tty_mutex);
if (IS_ERR(tty)) {
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 05085be..7cddf91 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1366,7 +1366,6 @@ static int tty_reopen(struct tty_struct *tty)
* @driver: tty driver we are opening a device on
* @idx: device index
* @ret_tty: returned tty structure
- * @first_ok: ok to open a new device (used by ptmx)
*
* Prepare a tty device. This may not be a "new" clean device but
* could also be an active device. The pty drivers require special
@@ -1386,18 +1385,11 @@ static int tty_reopen(struct tty_struct *tty)
* relaxed for the (most common) case of reopening a tty.
*/
-struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok)
+struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
{
struct tty_struct *tty;
int retval;
- /* Check if pty master is being opened multiple times */
- if (driver->subtype == PTY_TYPE_MASTER &&
- (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
- return ERR_PTR(-EIO);
- }
-
/*
* First time open is complex, especially for PTY devices.
* This code guarantees that either everything succeeds and the
@@ -1909,7 +1901,7 @@ got_driver:
if (retval)
tty = ERR_PTR(retval);
} else
- tty = tty_init_dev(driver, index, 0);
+ tty = tty_init_dev(driver, index);
mutex_unlock(&tty_mutex);
tty_driver_kref_put(driver);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5dbb3cb..d3ebd76 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -480,8 +480,7 @@ extern void free_tty_struct(struct tty_struct *tty);
extern void initialize_tty_struct(struct tty_struct *tty,
struct tty_driver *driver, int idx);
extern void deinitialize_tty_struct(struct tty_struct *tty);
-extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok);
+extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
extern int tty_release(struct inode *inode, struct file *filp);
extern int tty_init_termios(struct tty_struct *tty);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-03 8:51 ` Konstantin Khlebnikov
@ 2012-01-03 16:16 ` Linus Torvalds
2012-01-04 13:26 ` Konstantin Khlebnikov
2012-01-05 0:23 ` Greg KH
1 sibling, 1 reply; 10+ messages in thread
From: Linus Torvalds @ 2012-01-03 16:16 UTC (permalink / raw)
To: Konstantin Khlebnikov; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel
Looks ok as far as I can tell, and does indeed clean things up. I
assume somebody tested the case that we used to have issues with?
Linus
On Tue, Jan 3, 2012 at 12:51 AM, Konstantin Khlebnikov
<khlebnikov@openvz.org> wrote:
> cleanup hack added in v2.6.27-3203-g15582d3
>
> comment from that patch:
>
> : pty: If the administrator creates a device for a ptmx slave we should not error
> :
> : The open path for ptmx slaves is via the ptmx device. Opening them any
> : other way is not allowed. Vegard Nossum found that previously this was not
> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
> :
> : Signed-off-by: Alan Cox <alan@redhat.com>
> : Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
>
> devpts_get_tty() returns non-null only for inodes on devpts, but there is no
> inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
> Thus we can completely forbid lookup for master-devices and eliminate that hack in
> tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
>
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
> ---
> drivers/tty/pty.c | 8 +++-----
> drivers/tty/tty_io.c | 12 ++----------
> include/linux/tty.h | 3 +--
> 3 files changed, 6 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> index e18604b..d2bf3c1 100644
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c
> @@ -526,10 +526,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
> static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
> struct inode *ptm_inode, int idx)
> {
> - struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
> - if (tty)
> - tty = tty->link;
> - return tty;
> + /* Master must be open via /dev/ptmx */
> + return ERR_PTR(-EIO);
> }
>
> /**
> @@ -685,7 +683,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
>
> mutex_lock(&tty_mutex);
> tty_lock();
> - tty = tty_init_dev(ptm_driver, index, 1);
> + tty = tty_init_dev(ptm_driver, index);
> mutex_unlock(&tty_mutex);
>
> if (IS_ERR(tty)) {
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 05085be..7cddf91 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -1366,7 +1366,6 @@ static int tty_reopen(struct tty_struct *tty)
> * @driver: tty driver we are opening a device on
> * @idx: device index
> * @ret_tty: returned tty structure
> - * @first_ok: ok to open a new device (used by ptmx)
> *
> * Prepare a tty device. This may not be a "new" clean device but
> * could also be an active device. The pty drivers require special
> @@ -1386,18 +1385,11 @@ static int tty_reopen(struct tty_struct *tty)
> * relaxed for the (most common) case of reopening a tty.
> */
>
> -struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
> - int first_ok)
> +struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
> {
> struct tty_struct *tty;
> int retval;
>
> - /* Check if pty master is being opened multiple times */
> - if (driver->subtype == PTY_TYPE_MASTER &&
> - (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
> - return ERR_PTR(-EIO);
> - }
> -
> /*
> * First time open is complex, especially for PTY devices.
> * This code guarantees that either everything succeeds and the
> @@ -1909,7 +1901,7 @@ got_driver:
> if (retval)
> tty = ERR_PTR(retval);
> } else
> - tty = tty_init_dev(driver, index, 0);
> + tty = tty_init_dev(driver, index);
>
> mutex_unlock(&tty_mutex);
> tty_driver_kref_put(driver);
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index 5dbb3cb..d3ebd76 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -480,8 +480,7 @@ extern void free_tty_struct(struct tty_struct *tty);
> extern void initialize_tty_struct(struct tty_struct *tty,
> struct tty_driver *driver, int idx);
> extern void deinitialize_tty_struct(struct tty_struct *tty);
> -extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
> - int first_ok);
> +extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
> extern int tty_release(struct inode *inode, struct file *filp);
> extern int tty_init_termios(struct tty_struct *tty);
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-03 16:16 ` Linus Torvalds
@ 2012-01-04 13:26 ` Konstantin Khlebnikov
0 siblings, 0 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-04 13:26 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Greg Kroah-Hartman, Alan Cox, linux-kernel
Linus Torvalds wrote:
> Looks ok as far as I can tell, and does indeed clean things up. I
> assume somebody tested the case that we used to have issues with?
Yes of course I tested it.
>
> Linus
>
> On Tue, Jan 3, 2012 at 12:51 AM, Konstantin Khlebnikov
> <khlebnikov@openvz.org> wrote:
>> cleanup hack added in v2.6.27-3203-g15582d3
>>
>> comment from that patch:
>>
>> : pty: If the administrator creates a device for a ptmx slave we should not error
>> :
>> : The open path for ptmx slaves is via the ptmx device. Opening them any
>> : other way is not allowed. Vegard Nossum found that previously this was not
>> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
>> :
>> : Signed-off-by: Alan Cox<alan@redhat.com>
>> : Signed-off-by: Linus Torvalds<torvalds@linux-foundation.org>
>>
>> devpts_get_tty() returns non-null only for inodes on devpts, but there is no
>> inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
>> Thus we can completely forbid lookup for master-devices and eliminate that hack in
>> tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
>>
>> Signed-off-by: Konstantin Khlebnikov<khlebnikov@openvz.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-03 8:51 ` Konstantin Khlebnikov
2012-01-03 16:16 ` Linus Torvalds
@ 2012-01-05 0:23 ` Greg KH
2012-01-05 9:04 ` [PATCH for tty-next] " Konstantin Khlebnikov
2012-01-05 9:13 ` [PATCH] " Konstantin Khlebnikov
1 sibling, 2 replies; 10+ messages in thread
From: Greg KH @ 2012-01-05 0:23 UTC (permalink / raw)
To: Konstantin Khlebnikov
Cc: Greg Kroah-Hartman, Alan Cox, Linus Torvalds, linux-kernel
On Tue, Jan 03, 2012 at 12:51:11PM +0400, Konstantin Khlebnikov wrote:
> cleanup hack added in v2.6.27-3203-g15582d3
>
> comment from that patch:
>
> : pty: If the administrator creates a device for a ptmx slave we should not error
> :
> : The open path for ptmx slaves is via the ptmx device. Opening them any
> : other way is not allowed. Vegard Nossum found that previously this was not
> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
> :
> : Signed-off-by: Alan Cox <alan@redhat.com>
> : Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
>
> devpts_get_tty() returns non-null only for inodes on devpts, but there is no
> inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
> Thus we can completely forbid lookup for master-devices and eliminate that hack in
> tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
>
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
What tree did you make this patch against? I get fuzz warnings when
applying it to the tty-next branch (it's in the linux-next releases).
Please rediff it and resend it.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH for tty-next] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-05 0:23 ` Greg KH
@ 2012-01-05 9:04 ` Konstantin Khlebnikov
2012-01-05 9:13 ` [PATCH] " Konstantin Khlebnikov
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-05 9:04 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-kernel
cleanup hack added in v2.6.27-3203-g15582d3
comment from that patch:
: pty: If the administrator creates a device for a ptmx slave we should not error
:
: The open path for ptmx slaves is via the ptmx device. Opening them any
: other way is not allowed. Vegard Nossum found that previously this was not
: the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
:
: Signed-off-by: Alan Cox <alan@redhat.com>
: Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
devpts_get_tty() returns non-null only for inodes on devpts, but there is no
inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
Thus we can completely forbid lookup for master-devices and eliminate that hack in
tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
---
drivers/tty/pty.c | 8 +++-----
drivers/tty/tty_io.c | 12 ++----------
include/linux/tty.h | 3 +--
3 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index d8653ab..03147fa 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -515,10 +515,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
struct inode *ptm_inode, int idx)
{
- struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
- if (tty)
- tty = tty->link;
- return tty;
+ /* Master must be open via /dev/ptmx */
+ return ERR_PTR(-EIO);
}
/**
@@ -677,7 +675,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
mutex_lock(&tty_mutex);
tty_lock();
- tty = tty_init_dev(ptm_driver, index, 1);
+ tty = tty_init_dev(ptm_driver, index);
mutex_unlock(&tty_mutex);
if (IS_ERR(tty)) {
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 57c3743..a4fd717 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1365,7 +1365,6 @@ static int tty_reopen(struct tty_struct *tty)
* @driver: tty driver we are opening a device on
* @idx: device index
* @ret_tty: returned tty structure
- * @first_ok: ok to open a new device (used by ptmx)
*
* Prepare a tty device. This may not be a "new" clean device but
* could also be an active device. The pty drivers require special
@@ -1385,18 +1384,11 @@ static int tty_reopen(struct tty_struct *tty)
* relaxed for the (most common) case of reopening a tty.
*/
-struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok)
+struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
{
struct tty_struct *tty;
int retval;
- /* Check if pty master is being opened multiple times */
- if (driver->subtype == PTY_TYPE_MASTER &&
- (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
- return ERR_PTR(-EIO);
- }
-
/*
* First time open is complex, especially for PTY devices.
* This code guarantees that either everything succeeds and the
@@ -1950,7 +1942,7 @@ retry_open:
if (retval)
tty = ERR_PTR(retval);
} else
- tty = tty_init_dev(driver, index, 0);
+ tty = tty_init_dev(driver, index);
mutex_unlock(&tty_mutex);
if (driver)
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5dbb3cb..d3ebd76 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -480,8 +480,7 @@ extern void free_tty_struct(struct tty_struct *tty);
extern void initialize_tty_struct(struct tty_struct *tty,
struct tty_driver *driver, int idx);
extern void deinitialize_tty_struct(struct tty_struct *tty);
-extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
- int first_ok);
+extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
extern int tty_release(struct inode *inode, struct file *filp);
extern int tty_init_termios(struct tty_struct *tty);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master
2012-01-05 0:23 ` Greg KH
2012-01-05 9:04 ` [PATCH for tty-next] " Konstantin Khlebnikov
@ 2012-01-05 9:13 ` Konstantin Khlebnikov
1 sibling, 0 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2012-01-05 9:13 UTC (permalink / raw)
To: Greg KH; +Cc: Greg Kroah-Hartman, Alan Cox, Linus Torvalds, linux-kernel
Greg KH wrote:
> On Tue, Jan 03, 2012 at 12:51:11PM +0400, Konstantin Khlebnikov wrote:
>> cleanup hack added in v2.6.27-3203-g15582d3
>>
>> comment from that patch:
>>
>> : pty: If the administrator creates a device for a ptmx slave we should not error
>> :
>> : The open path for ptmx slaves is via the ptmx device. Opening them any
>> : other way is not allowed. Vegard Nossum found that previously this was not
>> : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics
>> :
>> : Signed-off-by: Alan Cox<alan@redhat.com>
>> : Signed-off-by: Linus Torvalds<torvalds@linux-foundation.org>
>>
>> devpts_get_tty() returns non-null only for inodes on devpts, but there is no
>> inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them.
>> Thus we can completely forbid lookup for master-devices and eliminate that hack in
>> tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().
>>
>> Signed-off-by: Konstantin Khlebnikov<khlebnikov@openvz.org>
>
> What tree did you make this patch against? I get fuzz warnings when
> applying it to the tty-next branch (it's in the linux-next releases).
>
> Please rediff it and resend it.
Sorry for that, I did not expect such activity in tty-layer =)
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-01-05 9:13 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-02 17:22 [PATCH] tty: cleanup prohibition of direct opening for unix98 pty master Konstantin Khlebnikov
2012-01-02 17:28 ` Greg KH
2012-01-02 22:29 ` Konstantin Khlebnikov
2012-01-03 1:08 ` Greg KH
2012-01-03 8:51 ` Konstantin Khlebnikov
2012-01-03 16:16 ` Linus Torvalds
2012-01-04 13:26 ` Konstantin Khlebnikov
2012-01-05 0:23 ` Greg KH
2012-01-05 9:04 ` [PATCH for tty-next] " Konstantin Khlebnikov
2012-01-05 9:13 ` [PATCH] " Konstantin Khlebnikov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.