Commit c7c6effd authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

netconsole: fix multiple race conditions

In every netconsole option that can be set through configfs there's a
race when checking for nt->enabled since it can be modified at the same
time. Probably the most damage can be done by store_enabled when racing
with another instance of itself. Fix all the races with one stone by
moving the mutex lock around the ->store call for all options.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 45e526e8
...@@ -325,9 +325,7 @@ static ssize_t store_enabled(struct netconsole_target *nt, ...@@ -325,9 +325,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
return -EINVAL; return -EINVAL;
} }
mutex_lock(&nt->mutex);
if (enabled) { /* 1 */ if (enabled) { /* 1 */
/* /*
* Skip netpoll_parse_options() -- all the attributes are * Skip netpoll_parse_options() -- all the attributes are
* already configured via configfs. Just print them out. * already configured via configfs. Just print them out.
...@@ -335,13 +333,10 @@ static ssize_t store_enabled(struct netconsole_target *nt, ...@@ -335,13 +333,10 @@ static ssize_t store_enabled(struct netconsole_target *nt,
netpoll_print_options(&nt->np); netpoll_print_options(&nt->np);
err = netpoll_setup(&nt->np); err = netpoll_setup(&nt->np);
if (err) { if (err)
mutex_unlock(&nt->mutex);
return err; return err;
}
printk(KERN_INFO "netconsole: network logging started\n"); printk(KERN_INFO "netconsole: network logging started\n");
} else { /* 0 */ } else { /* 0 */
/* We need to disable the netconsole before cleaning it up /* We need to disable the netconsole before cleaning it up
* otherwise we might end up in write_msg() with * otherwise we might end up in write_msg() with
...@@ -354,7 +349,6 @@ static ssize_t store_enabled(struct netconsole_target *nt, ...@@ -354,7 +349,6 @@ static ssize_t store_enabled(struct netconsole_target *nt,
} }
nt->enabled = enabled; nt->enabled = enabled;
mutex_unlock(&nt->mutex);
return strnlen(buf, count); return strnlen(buf, count);
} }
...@@ -571,8 +565,10 @@ static ssize_t netconsole_target_attr_store(struct config_item *item, ...@@ -571,8 +565,10 @@ static ssize_t netconsole_target_attr_store(struct config_item *item,
struct netconsole_target_attr *na = struct netconsole_target_attr *na =
container_of(attr, struct netconsole_target_attr, attr); container_of(attr, struct netconsole_target_attr, attr);
mutex_lock(&nt->mutex);
if (na->store) if (na->store)
ret = na->store(nt, buf, count); ret = na->store(nt, buf, count);
mutex_unlock(&nt->mutex);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment