]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: fix log target removal when singlethreaded
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 5 Mar 2022 18:39:53 +0000 (19:39 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 7 Mar 2022 16:23:12 +0000 (17:23 +0100)
While running singlethreaded, the RCU code is "dormant" and rcu_free is
an immediate operation.  This results in the log target loop accessing
free'd memory if a log target removes itself while a message is printed
(which is likely to happen on e.g. error conditions.)

Just use frr_each_safe to avoid this issue.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/zlog.c

index 85606d262405764c573fc6c4af2400362b04fb70..e0bb34a258547ccbe1a9ba0e08e04ece0c0937dc 100644 (file)
@@ -401,7 +401,7 @@ void zlog_tls_buffer_flush(void)
                return;
 
        rcu_read_lock();
-       frr_each (zlog_targets, &zlog_targets, zt) {
+       frr_each_safe (zlog_targets, &zlog_targets, zt) {
                if (!zt->logfn)
                        continue;
 
@@ -431,7 +431,7 @@ static void vzlog_notls(const struct xref_logmsg *xref, int prio,
        msg->stackbufsz = sizeof(stackbuf);
 
        rcu_read_lock();
-       frr_each (zlog_targets, &zlog_targets, zt) {
+       frr_each_safe (zlog_targets, &zlog_targets, zt) {
                if (prio > zt->prio_min)
                        continue;
                if (!zt->logfn)