public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Patch: Fix serial module use count (2.4.16 _and_ 2.5)
@ 2001-11-29 16:06 Balbir Singh
  2001-11-29 16:17 ` Russell King
  2001-11-29 18:03 ` Jeff Randall
  0 siblings, 2 replies; 17+ messages in thread
From: Balbir Singh @ 2001-11-29 16:06 UTC (permalink / raw)
  To: rmk; +Cc: linux-kernel

>Err,
>	close(-ENOMEM);

>What's that going to close?  Hint: you _can't_ close
a descriptor that
>failed to open, since you don't have a descriptor to
close.  You can
>only try to close an error code, but that's not going
to make it anywhere
>near the kernel driver level.


Let me make it clearer to you,

lets say I call rs_open() on /dev/ttyS0 and if it
fails then I should not call rs_close() after a failed
rs_open().

I hope this is clear now.





> The same thing applies to the code below. I think
that the open routine
> should instead set tty->driver_data to NULL upon
failure.

>Here's an example why that'd be real bad:

>1. process A opens /dev/ttyS0 as a normal device. 
>This initialises
>   tty->driver_data.
>2. process B tries to open /dev/cua0
>3. process B fails with -EBUSY since the normal
>device is open and active
>   (see block_til_ready)
>4. since rs_open failed, we set tty->driver_data to
>be NULL (note that this
>   is the same tty device pointer as (1) above.
>5. process A writes to /dev/ttyS0
>6. rs_write does the following:

>        struct async_struct *info = (struct
async_struct *)tty->driver_data;

>7. Oops.

Lets see what happens with your approach

1. I call rs_open(), it fails, ref_count set to 1

2. I am sane enough not to call rs_close() on the
device which failed to open with rs_open the first
time, count is set to 1, driver never unloads.

I do not have access to block_til_ready currently.
But, I will see that function and revert with more
comments.

Comments,
Balbir Singh.


--
Russell King (rmk@arm.linux.org.uk)                The
developer of ARM Linux
            
http://www.arm.linux.org.uk/personal/aboutme.html



__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Patch: Fix serial module use count (2.4.16 _and_ 2.5)
@ 2001-11-29 13:10 Russell King
  2001-11-29 13:48 ` BALBIR SINGH
  0 siblings, 1 reply; 17+ messages in thread
From: Russell King @ 2001-11-29 13:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Marcelo Tosatti

Hi,

The existing serial.c contains a nice module use count bug which is easily
triggerable.  Without anything connected to ttyS0, do:

 stty -clocal -F /dev/ttyS0
 stty -aF /dev/ttyS0

Hit ^c, lsmod shows use count of -1.  Repeat to decrement further.

Here's a patch that fixes this bogosity - please see the comment within
the patch for the reason.

Marcelo, please apply to both 2.4.
Linus, please apply to 2.5 as a stop-gap until my new serial drivers are
ready to be merged.

Thanks.

--- linux-orig/drivers/char/serial.c	Tue Nov 13 12:37:12 2001
+++ linux/drivers/char/serial.c	Thu Nov 29 13:07:52 2001
@@ -3133,6 +3133,10 @@
  * enables interrupts for a serial port, linking in its async structure into
  * the IRQ chain.   It also performs the serial-specific
  * initialization for the tty structure.
+ *
+ * Note that on failure, we don't decrement the module use count - the tty
+ * later will call rs_close, which will decrement it for us as long as
+ * tty->driver_data is set non-NULL. --rmk
  */
 static int rs_open(struct tty_struct *tty, struct file * filp)
 {
@@ -3153,10 +3157,8 @@
 	}
 	tty->driver_data = info;
 	info->tty = tty;
-	if (serial_paranoia_check(info, tty->device, "rs_open")) {
-		MOD_DEC_USE_COUNT;		
+	if (serial_paranoia_check(info, tty->device, "rs_open"))
 		return -ENODEV;
-	}
 
 #ifdef SERIAL_DEBUG_OPEN
 	printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
@@ -3171,10 +3173,8 @@
 	 */
 	if (!tmp_buf) {
 		page = get_zeroed_page(GFP_KERNEL);
-		if (!page) {
-			MOD_DEC_USE_COUNT;
+		if (!page)
 			return -ENOMEM;
-		}
 		if (tmp_buf)
 			free_page(page);
 		else
@@ -3188,7 +3188,6 @@
 	    (info->flags & ASYNC_CLOSING)) {
 		if (info->flags & ASYNC_CLOSING)
 			interruptible_sleep_on(&info->close_wait);
-		MOD_DEC_USE_COUNT;
 #ifdef SERIAL_DO_RESTART
 		return ((info->flags & ASYNC_HUP_NOTIFY) ?
 			-EAGAIN : -ERESTARTSYS);
@@ -3201,10 +3200,8 @@
 	 * Start up serial port
 	 */
 	retval = startup(info);
-	if (retval) {
-		MOD_DEC_USE_COUNT;
+	if (retval)
 		return retval;
-	}
 
 	retval = block_til_ready(tty, filp, info);
 	if (retval) {
@@ -3212,7 +3209,6 @@
 		printk("rs_open returning after block_til_ready with %d\n",
 		       retval);
 #endif
-		MOD_DEC_USE_COUNT;
 		return retval;
 	}
 


--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2001-12-01  0:21 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-29 16:06 Patch: Fix serial module use count (2.4.16 _and_ 2.5) Balbir Singh
2001-11-29 16:17 ` Russell King
2001-11-30  4:25   ` BALBIR SINGH
2001-11-30  9:36     ` Russell King
2001-11-30 22:19     ` Mike Fedyk
2001-11-30 23:06       ` Russell King
2001-12-01  0:20         ` Mike Fedyk
2001-11-29 18:03 ` Jeff Randall
2001-11-29 18:12   ` Russell King
2001-11-29 18:44     ` Jeff Randall
2001-11-29 19:05     ` James Simmons
2001-11-30 10:44   ` Maciej W. Rozycki
2001-11-30 10:56     ` Russell King
2001-11-30 12:11       ` Maciej W. Rozycki
  -- strict thread matches above, loose matches on Subject: below --
2001-11-29 13:10 Russell King
2001-11-29 13:48 ` BALBIR SINGH
2001-11-29 15:37   ` Russell King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox