1. 16 11月, 2011 2 次提交
  2. 19 10月, 2011 5 次提交
    • G
      Revert "TTY: call tty_driver_lookup_tty unconditionally" · a0340703
      Greg Kroah-Hartman 提交于
      This reverts commit 631180ac.
      
      It caused problems when /dev/tty is a pty:
      	https://lkml.org/lkml/2011/10/12/401
      
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: stable <stable@vger.kernel.org>
      Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
      Cc: Alan Cox <alan@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      a0340703
    • J
      TTY: call tty_driver_lookup_tty unconditionally · 631180ac
      Jiri Slaby 提交于
      Commit 4a2b5fdd (Move tty lookup/reopen to caller) made the call to
      tty_driver_lookup_tty conditional in tty_open. It doesn't look like it
      was an intention. Or if it was, it was not documented in the changelog
      and the code now looks weird. For example there would be no need to
      remember the tty driver and tty index. Further the condition depends
      on a tty which we drop a reference of already.
      
      If I'm looking correctly, this should not matter thanks to the locking
      currently done there. Thus, tty_driver->ttys[idx] cannot change under
      our hands. But anyway, it makes sense to change that to the old
      behaviour.
      
      Introduced-in: v2.6.28-rc2
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: stable <stable@vger.kernel.org>
      Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
      Cc: Alan Cox <alan@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      631180ac
    • J
      TTY: make tty_add_file non-failing · fa90e1c9
      Jiri Slaby 提交于
      If tty_add_file fails at the point it is now, we have to revert all
      the changes we did to the tty. It means either decrease all refcounts
      if this was a tty reopen or delete the tty if it was newly allocated.
      
      There was a try to fix this in v3.0-rc2 using tty_release in 0259894c
      (TTY: fix fail path in tty_open). But instead it introduced a NULL
      dereference. It's because tty_release dereferences
      filp->private_data, but that one is set even in our tty_add_file. And
      when tty_add_file fails, it's still NULL/garbage. Hence tty_release
      cannot be called there.
      
      To circumvent the original leak (and the current NULL deref) we split
      tty_add_file into two functions, making the latter non-failing. In
      that case we may do the former early in open, where handling failures
      is easy. The latter stays as it is now. So there is no change in
      functionality.
      
      The original bug (leak) was introduced by f573bd17 (tty: Remove
      __GFP_NOFAIL from tty_add_file()). Thanks Dan for reporting this.
      
      Later, we may split tty_release into more functions and call only some
      of them in this fail path instead. (If at all possible.)
      
      Introduced-in: v2.6.37-rc2
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Cc: stable <stable@vger.kernel.org>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: Pekka Enberg <penberg@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fa90e1c9
    • J
      TTY: drop driver reference in tty_open fail path · c290f835
      Jiri Slaby 提交于
      When tty_driver_lookup_tty fails in tty_open, we forget to drop a
      reference to the tty driver. This was added by commit 4a2b5fdd (Move
      tty lookup/reopen to caller).
      
      Fix that by adding tty_driver_kref_put to the fail path.
      
      I will refactor the code later. This is for the ease of backporting to
      stable.
      
      Introduced-in: v2.6.28-rc2
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: stable <stable@vger.kernel.org>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Acked-by: NSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      c290f835
    • T
      tty: Support compat_ioctl get/set termios_locked · 8193c429
      Thomas Meyer 提交于
      When running a Fedora 15 (x86) on an x86_64 kernel, in the boot process
      plymouthd complains about those two missing ioctls:
      [    2.581783] ioctl32(plymouthd:186): Unknown cmd fd(10) cmd(00005457){t:'T';sz:0} arg(ffb6a5d0) on /dev/tty1
      [    2.581803] ioctl32(plymouthd:186): Unknown cmd fd(10) cmd(00005456){t:'T';sz:0} arg(ffb6a680) on /dev/tty1
      
      both ioctl functions work on the 'struct termios' resp. 'struct termios2',
      which has the same size (36 bytes resp. 44 bytes) on x86 and x86_64,
      so it's just a matter of converting the pointer from userland.
      Signed-off-by: NThomas Meyer <thomas@m3y3r.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Signed-off-by: NAndrew Morton <akpm@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      8193c429
  3. 24 8月, 2011 1 次提交
    • J
      TTY: pty, fix pty counting · 24d406a6
      Jiri Slaby 提交于
      tty_operations->remove is normally called like:
      queue_release_one_tty
       ->tty_shutdown
         ->tty_driver_remove_tty
           ->tty_operations->remove
      
      However tty_shutdown() is called from queue_release_one_tty() only if
      tty_operations->shutdown is NULL. But for pty, it is not.
      pty_unix98_shutdown() is used there as ->shutdown.
      
      So tty_operations->remove of pty (i.e. pty_unix98_remove()) is never
      called. This results in invalid pty_count. I.e. what can be seen in
      /proc/sys/kernel/pty/nr.
      
      I see this was already reported at:
        https://lkml.org/lkml/2009/11/5/370
      But it was not fixed since then.
      
      This patch is kind of a hackish way. The problem lies in ->install. We
      allocate there another tty (so-called tty->link). So ->install is
      called once, but ->remove twice, for both tty and tty->link. The fix
      here is to count both tty and tty->link and divide the count by 2 for
      user.
      
      And to have ->remove called, let's make tty_driver_remove_tty() global
      and call that from pty_unix98_shutdown() (tty_operations->shutdown).
      
      While at it, let's document that when ->shutdown is defined,
      tty_shutdown() is not called.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Alan Cox <alan@linux.intel.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      24d406a6
  4. 02 7月, 2011 1 次提交
  5. 26 4月, 2011 1 次提交
  6. 20 4月, 2011 6 次提交
  7. 31 3月, 2011 1 次提交
  8. 02 3月, 2011 1 次提交
  9. 18 2月, 2011 4 次提交
  10. 26 1月, 2011 1 次提交
    • T
      console: rename acquire/release_console_sem() to console_lock/unlock() · ac751efa
      Torben Hohn 提交于
      The -rt patches change the console_semaphore to console_mutex.  As a
      result, a quite large chunk of the patches changes all
      acquire/release_console_sem() to acquire/release_console_mutex()
      
      This commit makes things use more neutral function names which dont make
      implications about the underlying lock.
      
      The only real change is the return value of console_trylock which is
      inverted from try_acquire_console_sem()
      
      This patch also paves the way to switching console_sem from a semaphore to
      a mutex.
      
      [akpm@linux-foundation.org: coding-style fixes]
      [akpm@linux-foundation.org: make console_trylock return 1 on success, per Geert]
      Signed-off-by: NTorben Hohn <torbenh@gmx.de>
      Cc: Thomas Gleixner <tglx@tglx.de>
      Cc: Greg KH <gregkh@suse.de>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      ac751efa
  11. 23 1月, 2011 1 次提交
  12. 17 12月, 2010 2 次提交
  13. 30 11月, 2010 2 次提交
    • J
      TTY: open/hangup race fixup · acfa747b
      Jiri Slaby 提交于
      Like in the "TTY: don't allow reopen when ldisc is changing" patch,
      this one fixes a TTY WARNING as described in the option 1) there:
      1) __tty_hangup from tty_ldisc_hangup to tty_ldisc_enable. During this
      section tty_lock is held. However tty_lock is temporarily dropped in
      the middle of the function by tty_ldisc_hangup.
      
      The fix is to introduce a new flag which we set during the unlocked
      window and check it in tty_reopen too. The flag is TTY_HUPPING and is
      cleared after TTY_HUPPED is set.
      
      While at it, remove duplicate TTY_HUPPED set_bit. The one after
      calling ops->hangup seems to be more correct. But anyway, we hold
      tty_lock, so there should be no difference.
      
      Also document the function it does that kind of crap.
      
      Nicely reproducible with two forked children:
      static void do_work(const char *tty)
      {
      	if (signal(SIGHUP, SIG_IGN) == SIG_ERR) exit(1);
      	setsid();
      	while (1) {
      		int fd = open(tty, O_RDWR|O_NOCTTY);
      		if (fd < 0) continue;
      		if (ioctl(fd, TIOCSCTTY)) continue;
      		if (vhangup()) continue;
      		close(fd);
      	}
      	exit(0);
      }
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Reported-by: <Valdis.Kletnieks@vt.edu>
      Reported-by: NKyle McMartin <kyle@mcmartin.ca>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      acfa747b
    • J
      TTY: don't allow reopen when ldisc is changing · e2efafbf
      Jiri Slaby 提交于
      There are many WARNINGs like the following reported nowadays:
      WARNING: at drivers/tty/tty_io.c:1331 tty_open+0x2a2/0x49a()
      Hardware name: Latitude E6500
      Modules linked in:
      Pid: 1207, comm: plymouthd Not tainted 2.6.37-rc3-mmotm1123 #3
      Call Trace:
       [<ffffffff8103b189>] warn_slowpath_common+0x80/0x98
       [<ffffffff8103b1b6>] warn_slowpath_null+0x15/0x17
       [<ffffffff8128a3ab>] tty_open+0x2a2/0x49a
       [<ffffffff810fd53f>] chrdev_open+0x11d/0x146
      ...
      
      This means tty_reopen is called without TTY_LDISC set. For further
      considerations, note tty_lock is held in tty_open. TTY_LDISC is cleared in:
      1) __tty_hangup from tty_ldisc_hangup to tty_ldisc_enable. During this
      section tty_lock is held. However tty_lock is temporarily dropped in
      the middle of the function by tty_ldisc_hangup.
      
      2) tty_release via tty_ldisc_release till the end of tty existence. If
      tty->count <= 1, tty_lock is taken, TTY_CLOSING bit set and then
      tty_ldisc_release called. tty_reopen checks TTY_CLOSING before checking
      TTY_LDISC.
      
      3) tty_set_ldisc from tty_ldisc_halt to tty_ldisc_enable. We:
         * take tty_lock, set TTY_LDISC_CHANGING, put tty_lock
         * call tty_ldisc_halt (clear TTY_LDISC), tty_lock is _not_ held
         * do some other work
         * take tty_lock, call tty_ldisc_enable (set TTY_LDISC), put
           tty_lock
      
      I cannot see how 2) can be a problem, as there I see no race. OTOH, 1)
      and 3) can happen without problems. This patch the case 3) by checking
      TTY_LDISC_CHANGING along with TTY_CLOSING in tty_reopen. 1) will be
      fixed in the following patch.
      
      Nicely reproducible with two processes:
      while (1) {
      	fd = open("/dev/ttyS1", O_RDWR);
      	if (fd < 0) {
      		warn("open");
      		continue;
      	}
      	close(fd);
      }
      --------
      while (1) {
              fd = open("/dev/ttyS1", O_RDWR);
              ld1 = 0; ld2 = 2;
              while (1) {
                      ioctl(fd, TIOCSETD, &ld1);
                      ioctl(fd, TIOCSETD, &ld2);
              }
              close(fd);
      }
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Reported-by: <Valdis.Kletnieks@vt.edu>
      Cc: Kyle McMartin <kyle@mcmartin.ca>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      e2efafbf
  14. 05 11月, 2010 1 次提交
  15. 23 10月, 2010 4 次提交
  16. 04 9月, 2010 1 次提交
    • N
      tty: fix tty_line must not be equal to number of allocated tty pointers in tty driver · 6eb68d6f
      Nathael Pajani 提交于
      I found a bug "by chance" in drivers/char/tty_io.c
      
      I mean "by chance" because I was just reading the code of the
      tty_find_polling_driver() to make a new tty_find_by_name() function.
      
      In tty_find_polling_driver() the driver actually test "tty_line <=
      p->num" while num refers to the number of struct tty_struct pointers
      allocated for the p->ttys (p is a tty_driver), and tty_line is scanned
      in a tty name, which can be for example ttyS2. Then tty_line equals 2.
      And if p->num is 2, we have only p->ttys[0] and p->ttys[1], but no
      p->ttys[2].
      
      This is actually unharmful, for tty_find_polling_driver() is used only
      in drivers/serial/kgdboc.c, and there's a test over there to find a
      console with a matching index, which will never happen.
      
      This is still a bug anyway.
      Signed-off-by: NNathael Pajani <nathael.pajani@ed3l.fr>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      6eb68d6f
  17. 18 8月, 2010 2 次提交
    • N
      tty: fix fu_list abuse · d996b62a
      Nick Piggin 提交于
      tty: fix fu_list abuse
      
      tty code abuses fu_list, which causes a bug in remount,ro handling.
      
      If a tty device node is opened on a filesystem, then the last link to the inode
      removed, the filesystem will be allowed to be remounted readonly. This is
      because fs_may_remount_ro does not find the 0 link tty inode on the file sb
      list (because the tty code incorrectly removed it to use for its own purpose).
      This can result in a filesystem with errors after it is marked "clean".
      
      Taking idea from Christoph's initial patch, allocate a tty private struct
      at file->private_data and put our required list fields in there, linking
      file and tty. This makes tty nodes behave the same way as other device nodes
      and avoid meddling with the vfs, and avoids this bug.
      
      The error handling is not trivial in the tty code, so for this bugfix, I take
      the simple approach of using __GFP_NOFAIL and don't worry about memory errors.
      This is not a problem because our allocator doesn't fail small allocs as a rule
      anyway. So proper error handling is left as an exercise for tty hackers.
      
      [ Arguably filesystem's device inode would ideally be divorced from the
      driver's pseudo inode when it is opened, but in practice it's not clear whether
      that will ever be worth implementing. ]
      
      Cc: linux-kernel@vger.kernel.org
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: Greg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      d996b62a
    • N
      fs: cleanup files_lock locking · ee2ffa0d
      Nick Piggin 提交于
      fs: cleanup files_lock locking
      
      Lock tty_files with a new spinlock, tty_files_lock; provide helpers to
      manipulate the per-sb files list; unexport the files_lock spinlock.
      
      Cc: linux-kernel@vger.kernel.org
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Acked-by: NAndi Kleen <ak@linux.intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      ee2ffa0d
  18. 11 8月, 2010 4 次提交