From: Andrey Panin <pazke@orbita1.ru>
To: Patrick Mochel <mochel@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] read() from driverfs files can read more bytes then requested
Date: Thu, 7 Feb 2002 12:10:53 +0300 [thread overview]
Message-ID: <20020207091053.GA4332@pazke.ipt> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 888 bytes --]
Hi all,
small program below crashes on read() from driverfs file:
int main(void)
{
int fd, ret;
char buf[16];
fd = open("/var/driver/root/pci0/status", 0);
ret = read(fd, buf, sizeof(buf));
close(fd);
}
it's because driverfs_read_file() function blindly uses entry->show()
return value without sanity check. As a result userspace process requested
16 bytes, but got ~45 and smashed stack as a bonus. You can also get this
effect pressing F3 in Midnight Commander on driverfs files.
Attached patch adds check that returned value is less then requested
byte count. I know that actual callback function device_read_status()
should also be fixed, but I found this bug after midnight and
decided to sleep a little :)
Best regards.
--
Andrey Panin | Embedded systems software engineer
pazke@orbita1.ru | PGP key: wwwkeys.eu.pgp.net
[-- Attachment #1.2: patch-driverfs --]
[-- Type: text/plain, Size: 388 bytes --]
diff -urN -X /usr/dontdiff /linux.2.5.3-dj3/fs/driverfs/inode.c /linux/fs/driverfs/inode.c
--- /linux.2.5.3-dj3/fs/driverfs/inode.c Wed Feb 6 23:42:06 2002
+++ /linux/fs/driverfs/inode.c Wed Feb 6 23:34:05 2002
@@ -255,6 +255,9 @@
len = entry->show(dev,page,count,*ppos);
+ if (len > count)
+ len = count;
+
if (len <= 0) {
if (len < 0)
retval = len;
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
next reply other threads:[~2002-02-07 9:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-07 9:10 Andrey Panin [this message]
2002-02-07 16:45 ` [PATCH] read() from driverfs files can read more bytes then requested Patrick Mochel
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=20020207091053.GA4332@pazke.ipt \
--to=pazke@orbita1.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.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