libmultipath: fix memory issue in path_latency prio
authorBenjamin Marzinski <bmarzins@redhat.com>
Tue, 9 Oct 2018 23:03:07 +0000 (18:03 -0500)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 10 Oct 2018 06:09:36 +0000 (08:09 +0200)
The path_latency prioriziter was assuming that prepare_directio_read()
always succeeds. However, it doesn't, and when it fails, the prioritizer
used buf without it pointing to alloced memory. Found by coverity.

Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
libmultipath/prioritizers/path_latency.c

index 765265c..eeee01e 100644 (file)
@@ -237,7 +237,8 @@ int getprio(struct path *pp, char *args, unsigned int timeout)
        lg_maxavglatency = log(MAX_AVG_LATENCY) / lg_base;
        lg_minavglatency = log(MIN_AVG_LATENCY) / lg_base;
 
-       prepare_directio_read(pp->fd, &blksize, &buf, &restore_flags);
+       if (prepare_directio_read(pp->fd, &blksize, &buf, &restore_flags) < 0)
+               return PRIO_UNDEF;
 
        temp = io_num;
        while (temp-- > 0) {