From: Andrew Morton <akpm@osdl.org>
To: linas@austin.ibm.com (Linas Vepstas)
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
rubini@vision.unipv.it, device@lanana.org,
linux-kernel@vger.kernel.org, Amos Waterland <apw@us.ibm.com>
Subject: Re: [PATCH] Chardev checking of overlapping ranges is incorrect.
Date: Mon, 7 Aug 2006 23:47:53 -0700 [thread overview]
Message-ID: <20060807234753.ff21eb29.akpm@osdl.org> (raw)
In-Reply-To: <20060807225555.GQ10638@austin.ibm.com>
On Mon, 7 Aug 2006 17:55:55 -0500
linas@austin.ibm.com (Linas Vepstas) wrote:
> The current code in register_chrdev_region() attempts to check
> for overlapping regions of minor device numbers, but performs
> that check incorrectly. For example, if a device with minor
> numbers 128, 129, 130 is registered first, and a device with
> minor number 3,4,5 is registered later, then the later range
> is incorrectly identified as "overlapping" (since 130>3),
> when clearly this is the wrong conclusion.
>
> This patch fixes the overlap check to work correctly.
I yesterday merged the below. Do you agree that it will fix the bug?
From: Amos Waterland <apw@us.ibm.com>
The code in __register_chrdev_region checks that if the driver wishing to
register has the same major as an existing driver the new minor range is
strictly less than the existing minor range. However, it does not also
check that the new minor range is strictly greater than the existing minor
range. That is, if driver X has registered with major=x and minor=0-3,
__register_chrdev_region will allow driver Y to register with major=x and
minor=1-4.
I came across this in the context of the Xen virtual console driver, but I
imagine it causes a problem for any driver with the same major number but
different minor numbers as a driver that has registered ahead of it.
Signed-off-by: Amos Waterland <apw@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---
diff -puN fs/char_dev.c~fix-bounds-check-bug-in-__register_chrdev_region fs/char_dev.c
--- a/fs/char_dev.c~fix-bounds-check-bug-in-__register_chrdev_region
+++ a/fs/char_dev.c
@@ -109,10 +109,13 @@ __register_chrdev_region(unsigned int ma
for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
if ((*cp)->major > major ||
- ((*cp)->major == major && (*cp)->baseminor >= baseminor))
+ ((*cp)->major == major &&
+ (((*cp)->baseminor >= baseminor) ||
+ ((*cp)->baseminor + (*cp)->minorct > baseminor))))
break;
if (*cp && (*cp)->major == major &&
- (*cp)->baseminor < baseminor + minorct) {
+ (((*cp)->baseminor < baseminor + minorct) ||
+ ((*cp)->baseminor + (*cp)->minorct > baseminor))) {
ret = -EBUSY;
goto out;
}
_
next prev parent reply other threads:[~2006-08-08 6:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-07 22:55 [PATCH] Chardev checking of overlapping ranges is incorrect Linas Vepstas
2006-08-07 23:00 ` Linas Vepstas
2006-08-08 6:47 ` Andrew Morton [this message]
2006-08-08 20:52 ` Amos Waterland
2006-08-08 21:33 ` Linas Vepstas
2006-08-08 22:20 ` Amos Waterland
2006-08-09 1:15 ` Linas Vepstas
2006-08-09 17:06 ` Amos Waterland
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=20060807234753.ff21eb29.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=apw@us.ibm.com \
--cc=device@lanana.org \
--cc=linas@austin.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rubini@vision.unipv.it \
/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