mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Dmitry Adamushko" <dmitry.adamushko@gmail.com>
To: "Linux Kernel" <linux-kernel@vger.kernel.org>
Cc: mingo@elte.hu
Subject: [BUG: kernel/irq/proc.c] unprotected iteration over the IRQ action list in name_unique()
Date: Wed, 14 Mar 2007 17:26:07 +0100	[thread overview]
Message-ID: <b647ffbd0703140926v1aa861alecd1a2eb4c6d0f5d@mail.gmail.com> (raw)

Hi,

1-st issue:  unprotected iteration over the IRQ action list in name_unique()


the racing sequences:

[ 1 ]  request_irq() -> setup_irq() -> register_handler_proc() ->
name_unique() -> iterate over the action list (*)

setup_irq() releases a desc->lock before calling register_handler_proc().

[ 2 ]  free_irq() -> delete some element while (*) is still in progress -> bum!

something like this should make it safe :

--- kernel/irq/proc-old.c       2007-03-14 16:34:52.828981000 +0100
+++ kernel/irq/proc.c   2007-03-14 16:59:47.236950000 +0100
@@ -66,11 +66,18 @@ static int name_unique(unsigned int irq,
 {
        struct irq_desc *desc = irq_desc + irq;
        struct irqaction *action;
+       unsigned long flags;
+
+       spin_lock_irqsave(&desc->lock, flags);

        for (action = desc->action ; action; action = action->next)
                if ((action != new_action) && action->name &&
-                               !strcmp(new_action->name, action->name))
+                               !strcmp(new_action->name, action->name)) {
+                       spin_unlock_irqrestore(&desc->lock, flags);
                        return 0;
+               }
+
+       spin_unlock_irqrestore(&desc->lock, flags);
        return 1;
 }


2-nd issue:  now it's about register_irq_proc() which is also called
by setup_irq().

register_irq_proc() is called for all descriptors for which

(irq_desc[irq].chip == &no_irq_chip) != 0           (*)

at startup time from init_irq_proc().

Let's suppose (*) is not true for some desc at startup and changes at
some point later.

If so, register_irq_proc() takes effect being called from setup_irq().

Now let's suppose request_irq() is called on 2 cpus for the same
interrupt line and both end up in (%) below

[ request_irq() -> setup_irq() -> register_irq_proc() ]

void register_irq_proc(unsigned int irq)
{
        char name [MAX_NAMELEN];

        if (!root_irq_dir ||
                (irq_desc[irq].chip == &no_irq_chip) ||
                        irq_desc[irq].dir)
                return;

            (%)  <=== both are here

        memset(name, 0, MAX_NAMELEN);
        sprintf(name, "%d", irq);

        /* create /proc/irq/1234 */
        irq_desc[irq].dir = proc_mkdir(name, root_irq_dir);
...

Both will try to initialize "irq_desc[irq].dir" and "smp_affinity"
entry... Not bum, but a possible leak indeed.


TIA,

-- 
Best regards,
Dmitry Adamushko

             reply	other threads:[~2007-03-14 16:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-14 16:26 Dmitry Adamushko [this message]
2007-03-15  9:53 ` Dmitry Adamushko

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=b647ffbd0703140926v1aa861alecd1a2eb4c6d0f5d@mail.gmail.com \
    --to=dmitry.adamushko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®