lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1b2aacd80703091610h9b5bc0ep1b5b58c53ca58e86@mail.gmail.com>
Date:	Fri, 9 Mar 2007 16:10:29 -0800
From:	"Luong Ngo" <luong.ngo@...il.com>
To:	"Parav K Pandit" <parav_pandit@...dtree.com>
Cc:	"Robert Hancock" <hancockr@...w.ca>,
	linux-kernel <linux-kernel@...r.kernel.org>, tglx@...utronix.de
Subject: Re: Sleeping thread not receive signal until it wakes up

On 3/8/07, Parav K Pandit <parav_pandit@...dtree.com> wrote:
> -----Original Message-----
> From: linux-kernel-owner@...r.kernel.org
> [mailto:linux-kernel-owner@...r.kernel.org] On Behalf Of Luong Ngo
> Sent: Friday, March 09, 2007 8:54 AM
> To: Robert Hancock
> Cc: linux-kernel; tglx@...utronix.de
> Subject: Re: Sleeping thread not receive signal until it wakes up
>
> On 3/8/07, Robert Hancock <hancockr@...w.ca> wrote:
> > Luong Ngo wrote:
> > > Hi Thomas and Dick,
> > > I appreciate all the responses. They are very good information to me.
> > > Actually, it wasn't me working on the driver but it's been there long
> > > time. I thought I just need to add the signal and signal handling
> > > part, not expecting it would lead me to the driver space.
> > > Here is what I have in the driver. Maybe racing condition could happen
> > > in scenario that the ioctl realease the lock but befor going to sleep,
> > > the ISR is invoked and call waking up on the queue, hence the ioctl
> > > will not be waken up since the wak up cal already executed. But I
> > > believe in our system, this could be tolerant since the hardware would
> > > keep raising interrupt if the abnormal condition still exists (Due to
> > > the ioctl being blocked so user app nevers get a chance to service the
> > > device). But is this the reason why my signal handler not get executed
> > > at all? Theoretically, according to the Richard Stevens book, I think
> > > the process should be waken up and received the signal even if it gets
> > > blocked in the IOCTL call, am i right?
> >
> > ..
> >
> > > static int ats89_ioctl(struct inode *inode, struct file *file, u_int
> > > cmd, u_long arg)
> > > {
> > >
> > >          switch(cmd){
> > >           case GET_IRQ_CMD: {
> > >            u32  regMask32;
> > >
> > >           spin_lock_irq(dev->lock);
> > >           while ((dev->irqMask & dev->irqEvent) == 0) {
> > >                 // Sleep until board interrupt happens
> > >                 spin_unlock_irq(dev->lock);
> > >                 interruptible_sleep_on(&(dev->boardIRQWaitQueue));
> > >                 if (uncond_wakeup) {
> > >                     /* don't go back to loop */
> > >                     break;
> > >                 }
> > >                 spin_lock_irq(dev->lock);
> > >             }
> >
> > Kernel code does not get pre-empted by signals. If the code needs to be
> > interruptible by signals this has to be handled explicitly.
> > interruptible_sleep on will stop waiting if your task gets a signal, but
> > your code doesn't check the signal_pending flag to know whether it
> > should exit the loop. If signal_pending(current) is set after the sleep
> > you should likely be returning -ERESTARTSYS to allow the task to handle
> > the signal. Then after the signal handler from the task returns, the
> > ioctl will get called again.
> >
> > Also, as was pointed out, you should not use the sleep_on family of
> > functions, use the wait_event functions intead. sleep_on is racy, if the
> > interrupt happened just before you do the sleep, you'll sit there
> > waiting for something that already occurred.
> >
> > --
> > Robert Hancock      Saskatoon, SK, Canada
> > To email, remove "nospam" from hancockr@...pamshaw.ca
> > Home Page: http://www.roberthancock.com/
> >
> >
> > Robert, thanks a lot for your suggestion
> > But I have added the signal_pending(current) check and signal handler
> > is not invoked
>
> >           spin_lock_irq(dev->lock);
> >           while ((dev->irqMask & dev->irqEvent) == 0) {
> >                 // Sleep until board interrupt happens
> >                 spin_unlock_irq(dev->lock);
> >                 interruptible_sleep_on(&(dev->boardIRQWaitQueue));
> >
> >                 if(signal_pending(current) {
> >                           return -ERESTARTSYS;
> >                 }
> >
> >                 if (uncond_wakeup) {
> >                     /* don't go back to loop */
> >                     break;
> >                 }
> >                 spin_lock_irq(dev->lock);
> >             }
> >Still no luck yet.
> >LNgo
> >-
>
> I guess you need to call allow_signal(xxx) before you go for sleep.
> Parav
>
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
>
> DISCLAIMER:
> This message (including attachment if any) is confidential and may be privileged. Before opening attachments please check them for viruses and defects. MindTree Consulting Limited (MindTree) will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside. If you have received this message by mistake please notify the sender by return  e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited.  Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.
>
Thanks Parav, adding singal_allow(SIGALRM) wakeup the blocking
interruptible_sleep_on and checking the signal_pending would return
true now. But a quick question is when detecting signal_pending, I
return -ERESTARTSYS, but the user process receive the return value of
ioctl call is -1, shouldn't it be -4 for EINTR?

Thanks all for the responses,
-LNgo
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ