]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: fnc->obuf could be accessed without a lock 15476/head
authorDonald Sharp <sharpd@nvidia.com>
Mon, 4 Mar 2024 23:07:42 +0000 (18:07 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 4 Mar 2024 23:08:06 +0000 (18:08 -0500)
Found by coverity.  Let's just lock the writeable
amount to see if it is possible.  It's ok because
we want to know if we have room *now*.  If another
pthread runs it will only remove data from fnc->obuf
and make more room.  So this is ok.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
zebra/dplane_fpm_nl.c

index 7ae1b2a0901a63efb89dcdb34cc96d38e8d60567..ef4824028fb6fef4a2fb23ae94081c778ec8d76d 100644 (file)
@@ -1394,8 +1394,14 @@ static void fpm_process_queue(struct event *t)
        uint64_t processed_contexts = 0;
 
        while (true) {
+               size_t writeable_amount;
+
+               frr_with_mutex (&fnc->obuf_mutex) {
+                       writeable_amount = STREAM_WRITEABLE(fnc->obuf);
+               }
+
                /* No space available yet. */
-               if (STREAM_WRITEABLE(fnc->obuf) < NL_PKT_BUF_SIZE) {
+               if (writeable_amount < NL_PKT_BUF_SIZE) {
                        no_bufs = true;
                        break;
                }