Skip to content

Commit c7c6eff

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
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: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 45e526e commit c7c6eff

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎drivers/net/netconsole.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,18 @@ static ssize_t store_enabled(struct netconsole_target *nt,
325325
return -EINVAL;
326326
}
327327

328-
mutex_lock(&nt->mutex);
329328
if (enabled) { /* 1 */
330-
331329
/*
332330
* Skip netpoll_parse_options() -- all the attributes are
333331
* already configured via configfs. Just print them out.
334332
*/
335333
netpoll_print_options(&nt->np);
336334

337335
err = netpoll_setup(&nt->np);
338-
if (err) {
339-
mutex_unlock(&nt->mutex);
336+
if (err)
340337
return err;
341-
}
342338

343339
printk(KERN_INFO "netconsole: network logging started\n");
344-
345340
} else { /* 0 */
346341
/* We need to disable the netconsole before cleaning it up
347342
* otherwise we might end up in write_msg() with
@@ -354,7 +349,6 @@ static ssize_t store_enabled(struct netconsole_target *nt,
354349
}
355350

356351
nt->enabled = enabled;
357-
mutex_unlock(&nt->mutex);
358352

359353
return strnlen(buf, count);
360354
}
@@ -571,8 +565,10 @@ static ssize_t netconsole_target_attr_store(struct config_item *item,
571565
struct netconsole_target_attr *na =
572566
container_of(attr, struct netconsole_target_attr, attr);
573567

568+
mutex_lock(&nt->mutex);
574569
if (na->store)
575570
ret = na->store(nt, buf, count);
571+
mutex_unlock(&nt->mutex);
576572

577573
return ret;
578574
}

0 commit comments

Comments
 (0)