From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: use after free in serport
Date: Sat, 30 Oct 2010 13:16:18 +0200 [thread overview]
Message-ID: <20101030111618.GA29915@Chamillionaire.breakpoint.cc> (raw)
There is a userland tool called inputattach which binds a serial port to
a specific device lets say a touch screen. serport
(CONFIG_SERIO_SERPORT) is the couterpart in the kernel. So the userland
does the following:
- 1. open("/dev/ttySx", O_RDWR | O_NOCTTY | O_NONBLOCK);
- 2. setline()
- 3. ioctl(fd, TIOCSETD, &ldisc); with ldisc = N_MOUSE
if the ldisc class is not set (yet), it calls serport_ldisc_open()
which allocates a little bit of memory.
- 4. ioctl(fd, SPIOCSTYPE, &devt) with devt beeing the device the user
wants to attach
- 5. read(fd, NULL, 0);
this attaches the device, calls its ->connect function and the program
stays here for as long as the driver has to remain attached and
working.
- 6. ioctl(fd, TIOCSETD, &ldisc); with ldisc = 0.
this calls serport_ldisc_close() and the extra memory is gone.
- 7. close()
Now the program remains in step 5. If the user starts it again then it
behaves a little different:
- step 3 does nothing because the correct ldisc is allready set.
tty_set_ldisc() discovers that (tty->ldisc->ops->num == ldisc) is true
(Check the no-op case) so nothing happens.
- in step 5 serport_ldisc_read() discovers that it allready performing a
read() and returns with -EBUSY.
- step 6 deallocates memory which was allocated by the other process.
Now we have the struct serport freed but the first process is still
using it.
Any idea how to fix it? I've seen that it is possible to manually bind
devices via /sys so maybe we could remove serport. However I'm not sure
if this kind of bug also affects other ldisc classes.
Sebastian
next reply other threads:[~2010-10-30 11:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-30 11:16 Sebastian Andrzej Siewior [this message]
2010-10-31 9:16 ` Jiri Slaby
2010-10-31 10:41 ` Sebastian Andrzej Siewior
2010-10-31 14:13 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101030111618.GA29915@Chamillionaire.breakpoint.cc \
--to=sebastian@breakpoint.cc \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@suse.de \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®