Skip to contentSkip to conversation

mISDN: misc timerdev fixes

PATCH Applied [email protected] 5 participants 22 messages Sep 22, 2008 – Oct 13, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/4 mISDN: misc timerdev fixes

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.
- Fix timer handler prototype to be correct
- Comment ugly SMP race I didn't fix.

---

 drivers/isdn/mISDN/timerdev.c |   22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes +6 -16
diff -puN drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes drivers/isdn/mISDN/timerdev.c
@@ -124,18 +124,6 @@ mISDN_read(struct file *filep, char *buf
 	return ret;
 }
 
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
-
-static ssize_t
-mISDN_write(struct file *filep, const char *buf, size_t count, loff_t *off)
-{
-	return -EOPNOTSUPP;
-}
-
 static unsigned int
 mISDN_poll(struct file *filep, poll_table *wait)
 {
@@ -157,8 +145,9 @@ mISDN_poll(struct file *filep, poll_tabl
 }
 
 static void
-dev_expire_timer(struct mISDNtimer *timer)
+dev_expire_timer(unsigned long data)
 {
+	struct mISDNtimer *timer = (void *)data;
 	u_long			flags;
 
 	spin_lock_irqsave(&timer->dev->lock, flags);
@@ -191,7 +180,7 @@ misdn_add_timer(struct mISDNtimerdev *de
 		spin_unlock_irqrestore(&dev->lock, flags);
 		timer->dev = dev;
 		timer->tl.data = (long)timer;
-		timer->tl.function = (void *) dev_expire_timer;
+		timer->tl.function = dev_expire_timer;
 		init_timer(&timer->tl);
 		timer->tl.expires = jiffies + ((HZ * (u_long)timeout) / 1000);
 		add_timer(&timer->tl);
@@ -211,6 +200,9 @@ misdn_del_timer(struct mISDNtimerdev *de
 	list_for_each_entry(timer, &dev->pending, list) {
 		if (timer->id == id) {
 			list_del_init(&timer->list);
+			/* RED-PEN AK: race -- timer can be still running on
+			 * other CPU. Needs reference count I think
+ 		 	 */
 			del_timer(&timer->tl);
 			ret = timer->id;
 			kfree(timer);
@@ -268,9 +260,7 @@ mISDN_ioctl(struct inode *inode, struct 
 }
 
 static struct file_operations mISDN_fops = {
-	.llseek		= mISDN_llseek,
 	.read		= mISDN_read,
-	.write		= mISDN_write,
 	.poll		= mISDN_poll,
 	.ioctl		= mISDN_ioctl,
 	.open		= mISDN_open,

_

#2 lore raw
Quoted 11 lines · David Miller

From: [email protected]
Date: Mon, 22 Sep 2008 14:51:03 -0700

Quoted 6 lines

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.
- Fix timer handler prototype to be correct
- Comment ugly SMP race I didn't fix.

Applied to net-next-2.6

I'm hoping someone takes care of the SMP race. I think the timers need all reference counting similar to other network objects to handle this cleanly.

It might be a good idea to mark it BROKEN_ON_SMP in the meantime.

-Andi

Signature · 1 line
[email protected]
#3 lore raw
Quoted 8 lines · Andi Kleen
Quoted 7 lines · David Miller

From: [email protected]
Date: Mon, 22 Sep 2008 14:51:03 -0700

Quoted 4 lines

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.
- Fix timer handler prototype to be correct
- Comment ugly SMP race I didn't fix.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Applied to net-next-2.6

I'm hoping someone takes care of the SMP race. I think the timers need all reference counting similar to other network objects to handle this cleanly.

Yes I already have some idea without refcounting, checking how much time is left if it is more as some treshhold (maybe 2 or 10 jiffies) delete the timer, if not mark it for deletion only and delete it during the run function without triggering the device. In the race case it would trigger the device too but this is not critical.
Another easier implementation could mark it only, without trying to delete it imediately. But in this case unneeded timers would hang around (on big busy PBX boxes this can be some 100) for some time.

What do you think ?

Quoted 2 lines

It might be a good idea to mark it BROKEN_ON_SMP in the meantime.

No really needed, normally the timers deleted long time before running out or never so it should never see such a race, maybe if the application is aborted and cleanup all timers this could happen but also this should be no normal case, since usually you do not kill a PBX if any connections are active.
Yes it could be used to do some deny on service kind of attack, so it should be fixed at all.

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#4 lore raw
Quoted 7 lines · Karsten Keil

No really needed, normally the timers deleted long time before running out or never so it should never see such a race, maybe if the application is aborted and cleanup all timers this could happen but also this should be no normal case, since usually you do not kill a PBX if any connections are active.
Yes it could be used to do some deny on service kind of attack, so it should be fixed at all.

All these timers are completely user controller and non-prviliegued. So this _is_ a serious issue. In fact I think we should just rip out this whole module, it's a really useless duplicate timer interface.

Gotta love merging unreviewed code.

#5 lore raw
In reply to [email protected]

drivers/isdn/mISDN/timerdev.c mISDN_read(struct file *filep, char *buf

Quoted 12 lines · On Mon, Sep 22, 2008 at 02:51:03PM -0700, [email protected] wrote:

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.

drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes +0 -6
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
 
 static struct file_operations mISDN_fops = {
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

#6 lore raw
Quoted 11 lines · On Tue, 23 Sep 2008 06:40:26 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 9 lines · On Mon, Sep 22, 2008 at 02:51:03PM -0700, [email protected] wrote:

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.

(quoted diff) +0 -5
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
Quoted 5 lines

Review

Quoted 2 lines

static struct file_operations mISDN_fops = {

(quoted diff) +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

so.. this?

drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix +1 -1
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct fil
 	init_waitqueue_head(&dev->wait);
 	filep->private_data = dev;
 	__module_get(THIS_MODULE);
-	return 0;
+	return nonseekable_open(ino, filep);
 }
 
 static int

_

#7 lore raw
Quoted 1 line · Andrew Morton

so.. this?

Much better.

drivers/isdn/mISDN/timerdev.c mISDN_open(struct inode *ino, struct fil · line 64

Quoted 8 lines
drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix +1 -1
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct fil
 	init_waitqueue_head(&dev->wait);
 	filep->private_data = dev;
 	__module_get(THIS_MODULE);
-	return 0;
+	return nonseekable_open(ino, filep);

But this also shows that mISDN is kinda stuck in a different century. Doing __module_get(THIS_MODULE) at the end of ->open is utterly racy, it really needs to set a owner field in file_operations and rip this cruft out.

Btw, can anyone explain WTF this timerdev module is doing? It's not using any functionality from the rest of mISDN, it's not exporting any functionality to it either but just provides a really awkward way to expose dumb timers to userspace. What does it provide that the normal timer syscalls can't provide?

#8 lore raw
Quoted 19 lines · Christoph Hellwig
Quoted 1 line · Andrew Morton

so.. this?

Much better.

drivers/isdn/mISDN/timerdev.c mISDN_open(struct inode *ino, struct fil · line 64

Quoted 8 lines
drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix +1 -1
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct fil
 	init_waitqueue_head(&dev->wait);
 	filep->private_data = dev;
 	__module_get(THIS_MODULE);
-	return 0;
+	return nonseekable_open(ino, filep);

But this also shows that mISDN is kinda stuck in a different century. Doing __module_get(THIS_MODULE) at the end of ->open is utterly racy, it really needs to set a owner field in file_operations and rip this cruft out.

Quoted 5 lines

Btw, can anyone explain WTF this timerdev module is doing? It's not using any functionality from the rest of mISDN, it's not exporting any functionality to it either but just provides a really awkward way to expose dumb timers to userspace. What does it provide that the normal timer syscalls can't provide?

This version only makes the programing of upper ISDN layers easier, you only need to watch /dev/mISDNtimer together with the sockets in one select call.
The next version will have a option to synchronise the timer with the ISDN hardware clock which would avoid additional jitter if you need to bridge channels in software.

Signature · 4 lines
Karsten Keil
SuSE Labs
ISDN and VOIP development
SUSE LINUX Products GmbH, Maxfeldstr.5 90409 Nuernberg, GF: Markus Rex, HRB 16746 (AG Nuernberg)
#9 lore raw
Quoted 26 lines · On Tue, 23 Sep 2008 14:00:30 +0200 Karsten Keil <[email protected]> wrote:
Quoted 19 lines · Christoph Hellwig
Quoted 1 line · Andrew Morton

so.. this?

Much better.

drivers/isdn/mISDN/timerdev.c mISDN_open(struct inode *ino, struct fil · line 64

Quoted 8 lines
drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix +1 -1
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct fil
 	init_waitqueue_head(&dev->wait);
 	filep->private_data = dev;
 	__module_get(THIS_MODULE);
-	return 0;
+	return nonseekable_open(ino, filep);

But this also shows that mISDN is kinda stuck in a different century. Doing __module_get(THIS_MODULE) at the end of ->open is utterly racy, it really needs to set a owner field in file_operations and rip this cruft out.

Quoted 5 lines

Btw, can anyone explain WTF this timerdev module is doing? It's not using any functionality from the rest of mISDN, it's not exporting any functionality to it either but just provides a really awkward way to expose dumb timers to userspace. What does it provide that the normal timer syscalls can't provide?

Quoted 3 lines

This version only makes the programing of upper ISDN layers easier, you only need to watch /dev/mISDNtimer together with the sockets in one select call.

sys_timerfd_create() can do this?

Quoted 3 lines

The next version will have a option to synchronise the timer with the ISDN hardware clock which would avoid additional jitter if you need to bridge channels in software.

hrm. If that's really really useful and actually works then I guess it might then be justifiable.

#10 lore raw
In reply to Andrew Morton
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Tue, 23 Sep 2008 06:40:26 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 9 lines · On Mon, Sep 22, 2008 at 02:51:03PM -0700, [email protected] wrote:

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.

(quoted diff) +0 -5
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
Quoted 7 lines
Quoted 5 lines

Review

Quoted 2 lines

static struct file_operations mISDN_fops = {

(quoted diff) +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

so.. this?

No, Christoph was wrong on that one. The original patch is ok. He would have been right if that was a file system, but it isn't.

-Andi

#11 lore raw

Re: [patch 4/4] mISDN: misc timerdev fixes II

In reply to Andrew Morton
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Tue, 23 Sep 2008 06:40:26 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 9 lines · On Mon, Sep 22, 2008 at 02:51:03PM -0700, [email protected] wrote:

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.

(quoted diff) +0 -5
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
Quoted 7 lines
Quoted 5 lines

Review

Quoted 2 lines

static struct file_operations mISDN_fops = {

(quoted diff) +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

so.. this?

Hmm actually on double checking it's really needed, sorry.

-Andi

#12 lore raw

Re: [patch 4/4] mISDN: misc timerdev fixes II

Quoted 9 lines · Andi Kleen
Quoted 7 lines
Quoted 5 lines

Review

Quoted 2 lines

static struct file_operations mISDN_fops = {

(quoted diff) +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

so.. this?

Hmm actually on double checking it's really needed, sorry.

Yes, unfortunately the only way it's cleared currently is through using nonseekable_open, but I've started preparing a war plan to sort this whole mess out.

#13 lore raw

Re: [patch 4/4] mISDN: misc timerdev fixes II

Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Andi Kleen
Quoted 6 lines
Quoted 5 lines

Review

Quoted 2 lines

static struct file_operations mISDN_fops = {

(quoted diff) +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

so.. this?

Hmm actually on double checking it's really needed, sorry.

Yes, unfortunately the only way it's cleared currently is through using nonseekable_open, but I've started preparing a war plan to sort this whole mess out.

Yes it would be much more logical if FMODE_SEEK was cleared on character devices by default. That is what I assumed with the original patch.

-Andi

Signature · 1 line
[email protected]
#14 lore raw

Re: [patch 4/4] mISDN: misc timerdev fixes II

Quoted 6 lines · Andi Kleen
Quoted 3 lines

Yes, unfortunately the only way it's cleared currently is through using nonseekable_open, but I've started preparing a war plan to sort this whole mess out.

Yes it would be much more logical if FMODE_SEEK was cleared on character devices by default. That is what I assumed with the original patch.

Actually I'd prefer to not have by default at all. While all filesystems should support seeking they also can easily set a .llseek instead of the current horrible default. llseek is the only file operation with a default (and a really bad one), and I'd prefer it not to have for consistency.

#16 lore raw
Quoted 3 lines · On Sun, 12 Oct 2008 07:05:10 -0400 Christoph Hellwig <[email protected]> wrote:

The bogus version which removes ->llseek just got into Linus' tree..

Well I still have this queued:

From: Andrew Morton <[email protected]>

Cc Andi Kleen <[email protected]>
Cc Karsten Keil <[email protected]>
Cc Christoph Hellwig <[email protected]>

---

 drivers/isdn/mISDN/timerdev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix +1 -1
diff -puN drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes-fix drivers/isdn/mISDN/timerdev.c
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct fil
 	init_waitqueue_head(&dev->wait);
 	filep->private_data = dev;
 	__module_get(THIS_MODULE);
-	return 0;
+	return nonseekable_open(ino, filep);
 }
 
 static int

_

So presumably whoever merged the unfixed version flubbed the fix.

If that'll fix it. Is it sufficient? I think so.

#17 lore raw
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Sun, 12 Oct 2008 07:05:10 -0400 Christoph Hellwig <[email protected]> wrote:

The bogus version which removes ->llseek just got into Linus' tree..

Well I still have this queued:

Yeah, that'll fix it.

maintainer
#18 lore raw
In reply to Andrew Morton

From: Andrew Morton <[email protected]>
Date: Sun, 12 Oct 2008 19:11:13 -0700

Quoted 4 lines
Quoted 3 lines · On Sun, 12 Oct 2008 07:05:10 -0400 Christoph Hellwig <[email protected]> wrote:

The bogus version which removes ->llseek just got into Linus' tree..

Quoted 8 lines

Well I still have this queued:

From: Andrew Morton <[email protected]>

Cc Andi Kleen <[email protected]>
Cc Karsten Keil <[email protected]>
Cc Christoph Hellwig <[email protected]>

Andrew, want me to such this into my net-2.6 tree?

#19 lore raw
Quoted 10 lines · On Sun, 12 Oct 2008 21:00:31 -0700 (PDT) David Miller <[email protected]>…

From: Andrew Morton <[email protected]>
Date: Sun, 12 Oct 2008 19:11:13 -0700

Quoted 6 lines
Quoted 3 lines · On Sun, 12 Oct 2008 07:05:10 -0400 Christoph Hellwig <[email protected]> wrote:

The bogus version which removes ->llseek just got into Linus' tree..

Well I still have this queued:

Quoted 8 lines
Quoted 6 lines

From: Andrew Morton <[email protected]>

Cc Andi Kleen <[email protected]>
Cc Karsten Keil <[email protected]>
Cc Christoph Hellwig <[email protected]>

Andrew, want me to such this into my net-2.6 tree?

yes please. I'll send it over with a slight changelog.

maintainer
#20 lore raw

From: Andrew Morton <[email protected]>
Date: Mon, 13 Oct 2008 04:56:58 -0700

Quoted 5 lines
Quoted 3 lines · On Sun, 12 Oct 2008 21:00:31 -0700 (PDT) David Miller <[email protected]>…

Andrew, want me to suck this into my net-2.6 tree?

yes please. I'll send it over with a slight changelog.

Thanks, will pull those in.

#21 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · On Mon, Sep 22, 2008 at 02:51:03PM -0700, [email protected] wrote:

From: Andi Kleen <[email protected]>

- Remove noop VFS stubs. The VFS does that on a NULL pointer anyways.

drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes +0 -5
-static loff_t
-mISDN_llseek(struct file *filep, loff_t offset, int orig)
-{
-	return -ESPIPE;
-}
Quoted 5 lines

drivers/isdn/mISDN/timerdev.c mISDN_ioctl(struct inode *inode, struct · line 271

Quoted 2 lines

static struct file_operations mISDN_fops = {

drivers/isdn/mISDN/timerdev.c renamed from drivers/isdn/mISDN/timerdev.c~misdn-misc-timerdev-fixes +0 -1
-	.llseek		= mISDN_llseek,

This is wrong. no llseek means we use default_llseek, which is different from returning -ESPIPE.

No it's correct. Character devices don't have FMODE_LSEEK set and then no_llseek is the default fallback.

-Andi

Signature · 1 line
[email protected]