From patchwork Tue Oct 9 23:03:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10633361 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4275D3CF1 for ; Tue, 9 Oct 2018 23:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328F4299A4 for ; Tue, 9 Oct 2018 23:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26E22299AD; Tue, 9 Oct 2018 23:04:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7826299A4 for ; Tue, 9 Oct 2018 23:04:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFA3288E4F; Tue, 9 Oct 2018 23:04:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BF317F622; Tue, 9 Oct 2018 23:04:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 434E2180BAD1; Tue, 9 Oct 2018 23:04:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w99N406W023038 for ; Tue, 9 Oct 2018 19:04:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7ACFF7E3A4; Tue, 9 Oct 2018 23:04:00 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 3A8397E12B; Tue, 9 Oct 2018 23:03:57 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Tue, 09 Oct 2018 18:03:56 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Tue, 9 Oct 2018 18:03:07 -0500 Message-Id: <1539126196-28926-11-git-send-email-bmarzins@redhat.com> In-Reply-To: <1539126196-28926-1-git-send-email-bmarzins@redhat.com> References: <1539126196-28926-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v4 10/19] libmultipath: fix memory issue in path_latency prio X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 09 Oct 2018 23:04:02 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Benjamin Marzinski --- libmultipath/prioritizers/path_latency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmultipath/prioritizers/path_latency.c b/libmultipath/prioritizers/path_latency.c index 765265c..eeee01e 100644 --- a/libmultipath/prioritizers/path_latency.c +++ b/libmultipath/prioritizers/path_latency.c @@ -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) {