From: Veaceslav Falico <vfalico@redhat.com>
To: Nikolay Aleksandrov <nikolay@redhat.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH net] netconsole: fix NULL pointer dereference
Date: Thu, 24 Oct 2013 12:21:47 +0200 [thread overview]
Message-ID: <20131024102147.GD16787@redhat.com> (raw)
In-Reply-To: <1382533489-19248-1-git-send-email-nikolay@redhat.com>
On Wed, Oct 23, 2013 at 03:04:49PM +0200, Nikolay Aleksandrov wrote:
>We need to disable the netconsole (enabled = 0) before setting nt->np.dev
>to NULL because otherwise we might still have users after the
>netpoll_cleanup() since nt->enabled is set afterwards and we can
>have a message which will result in a NULL pointer dereference.
>It is very easy to hit dereferences all over the netpoll_send_udp function
>by running the following two loops in parallel:
>while [ 1 ]; do echo 1 > enabled; echo 0 > enabled; done;
>while [ 1 ]; do echo 00:11:22:33:44:55 > remote_mac; done;
>(the second loop is to generate messages, it can be done by anything)
>
>We're safe to set nt->np.dev = NULL and nt->enabled = 0 with the spinlock
>since it's required in the write_msg() function.
>
>Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
>---
>Taking the spinlock seems like the cleanest way to insure there's noone
>running in parallel, but I'm open to suggestions as I'm not satisfied with
>the looks of this. I'll prepare a net-next patchset for netconsole soon to
>clean it up properly, all of these can be easily simplified.
First when I've seen 'spin_lock(); a = 1; spin_unlock()' I've thought
"WTF?", however indeed it will stop us racing with write_msg().
FWIW...
Reviewed-by: Veacelsav Falico <vfalico@redhat.com>
>
> drivers/net/netconsole.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
>diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
>index adeee61..1505dcb 100644
>--- a/drivers/net/netconsole.c
>+++ b/drivers/net/netconsole.c
>@@ -310,6 +310,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
> const char *buf,
> size_t count)
> {
>+ unsigned long flags;
> int enabled;
> int err;
>
>@@ -342,6 +343,13 @@ static ssize_t store_enabled(struct netconsole_target *nt,
> printk(KERN_INFO "netconsole: network logging started\n");
>
> } else { /* 0 */
>+ /* We need to disable the netconsole before cleaning it up
>+ * otherwise we might end up in write_msg() with
>+ * nt->np.dev == NULL and nt->enabled == 1
>+ */
>+ spin_lock_irqsave(&target_list_lock, flags);
>+ nt->enabled = 0;
>+ spin_unlock_irqrestore(&target_list_lock, flags);
> netpoll_cleanup(&nt->np);
> }
>
>--
>1.8.1.4
>
>--
>To unsubscribe from this list: send the line "unsubscribe netdev" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-10-24 10:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-23 13:04 [PATCH net] netconsole: fix NULL pointer dereference Nikolay Aleksandrov
2013-10-24 10:21 ` Veaceslav Falico [this message]
2013-10-24 10:39 ` David Laight
2013-10-24 17:56 ` David Miller
2013-10-24 18:22 ` Nikolay Aleksandrov
2013-10-24 20:59 ` Francois Romieu
2013-10-25 14:15 ` Nikolay Aleksandrov
2013-10-25 23:06 ` Francois Romieu
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=20131024102147.GD16787@redhat.com \
--to=vfalico@redhat.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=nikolay@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.