From patchwork Mon Jun 24 09:27:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012713 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 82BE91805 for ; Mon, 24 Jun 2019 09:29:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 747EE28AF5 for ; Mon, 24 Jun 2019 09:29:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66B5D28B5D; Mon, 24 Jun 2019 09:29:24 +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 01CA628AF5 for ; Mon, 24 Jun 2019 09:29:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB1C9780D9; Mon, 24 Jun 2019 09:29:14 +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 28ED060156; Mon, 24 Jun 2019 09:29:08 +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 1F4621806B18; Mon, 24 Jun 2019 09:29:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9SwOC004461 for ; Mon, 24 Jun 2019 05:28:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08F185C225; Mon, 24 Jun 2019 09:28:58 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCF4B5C22E; Mon, 24 Jun 2019 09:28:55 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0630DB2DC4; Mon, 24 Jun 2019 09:28:51 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:40 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:26 +0200 Message-Id: <20190624092756.7769-2-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:28:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:28:52 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 01/30] kpartx: dasd: fix -Waddress-of-packed-member warning from gcc9 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:23 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Fixes the following warning: dasd.c: In function ‘read_dasd_pt’: dasd.c:206:3: warning: converting a packed ‘volume_label_t’ {aka ‘struct volume_label’} pointer (alignment 1) to a ‘label_ints_t’ {aka ‘unsigned int’} pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member] 206 | label_ints_t *label = (label_ints_t *) &vlabel; | ^~~~~~~~~~~~ As volume_label_t is only used in read_dasd_pt(), and filled with memcpy(), increasing its alignment should be safe. Signed-off-by: Martin Wilck --- kpartx/dasd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpartx/dasd.h b/kpartx/dasd.h index 749af49a..8ad5d620 100644 --- a/kpartx/dasd.h +++ b/kpartx/dasd.h @@ -68,7 +68,7 @@ typedef struct volume_label char res3[28]; /* reserved */ uint8_t ldl_version; /* version number, valid for ldl format */ uint64_t formatted_blocks; /* valid when ldl_version >= f2 */ -} __attribute__ ((packed)) volume_label_t; +} __attribute__ ((packed, aligned(__alignof__(int)))) volume_label_t; typedef struct extent From patchwork Mon Jun 24 09:27:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012721 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 1DD94186E for ; Mon, 24 Jun 2019 09:29:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E7D428AF5 for ; Mon, 24 Jun 2019 09:29:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02B1A28B5B; Mon, 24 Jun 2019 09:29:57 +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 9677628B4C for ; Mon, 24 Jun 2019 09:29:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE7A17FDF4; Mon, 24 Jun 2019 09:29:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E342611B8; Mon, 24 Jun 2019 09:29:56 +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 143A7206D6; Mon, 24 Jun 2019 09:29:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9SwaJ004482 for ; Mon, 24 Jun 2019 05:28:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0DE91001E61; Mon, 24 Jun 2019 09:28:58 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C390F1001DC0; Mon, 24 Jun 2019 09:28:57 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D661480F6D; Mon, 24 Jun 2019 09:28:56 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:42 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:27 +0200 Message-Id: <20190624092756.7769-3-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:28:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:28:57 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 02/30] libmultipath: fix gcc -Wstringop-truncation warning in set_value() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:57 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Fixes the following warning: In function ‘strncat’, inlined from ‘set_value’ at parser.c:382:3: /usr/include/bits/string_fortified.h:136:10: warning: ‘__builtin_strncat’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 136 | return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ parser.c: In function ‘set_value’: parser.c:382:3: note: length computed here 382 | strncat(alloc, str, strlen(str)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc's stringop checker expects that the size argument of strncat() is derived from the destination, not source, side. See https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ Fix typo in error message along the way. Signed-off-by: Martin Wilck --- libmultipath/parser.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index 92ef7cf5..e00c5fff 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -345,17 +345,13 @@ set_value(vector strvec) if (alloc) memcpy(alloc, str, size); else - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); + goto oom; return alloc; } /* Even empty quotes counts as a value (An empty string) */ alloc = (char *) MALLOC(sizeof (char)); - if (!alloc) { - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; - } + if (!alloc) + goto oom; for (i = 2; i < VECTOR_SIZE(strvec); i++) { str = VECTOR_SLOT(strvec, i); if (!str) { @@ -373,15 +369,17 @@ set_value(vector strvec) alloc = REALLOC(alloc, sizeof (char) * len); if (!alloc) { FREE(tmp); - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; + goto oom; } if (*alloc != '\0') strncat(alloc, " ", 1); - strncat(alloc, str, strlen(str)); + strncat(alloc, str, len - strlen(alloc) - 1); } return alloc; +oom: + condlog(0, "can't allocate memory for option '%s'", + (char *)VECTOR_SLOT(strvec, 0)); + return NULL; } /* non-recursive configuration stream handler */ From patchwork Mon Jun 24 09:27:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012717 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 63ACB112C for ; Mon, 24 Jun 2019 09:29:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 538A928AF5 for ; Mon, 24 Jun 2019 09:29:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4816028B5B; Mon, 24 Jun 2019 09:29:25 +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 E740528AF5 for ; Mon, 24 Jun 2019 09:29:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98C632CE940; Mon, 24 Jun 2019 09:29:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66A6A6012D; Mon, 24 Jun 2019 09:29:11 +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 AC0E3206D1; Mon, 24 Jun 2019 09:29:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9Swr8004481 for ; Mon, 24 Jun 2019 05:28:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id C09F81001DFE; Mon, 24 Jun 2019 09:28:58 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3ADD81001E77; Mon, 24 Jun 2019 09:28:55 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9902FC05A1D8; Mon, 24 Jun 2019 09:28:52 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:44 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:28 +0200 Message-Id: <20190624092756.7769-4-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:28:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:28:53 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 03/30] libmultipath: remove 'space' argument to merge_words() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:29:24 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP merge_words() is always called with space = 1. Remove the argument. Signed-off-by: Martin Wilck --- libmultipath/dmparser.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index ac13ec06..04f675c1 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -18,12 +18,12 @@ #define WORD_SIZE 64 static int -merge_words (char ** dst, char * word, int space) +merge_words(char **dst, char *word) { char * p = *dst; int len; - len = strlen(*dst) + strlen(word) + space; + len = strlen(*dst) + strlen(word) + 1; *dst = REALLOC(*dst, len + 1); if (!*dst) { @@ -36,11 +36,8 @@ merge_words (char ** dst, char * word, int space) while (*p != '\0') p++; - while (space) { - *p = ' '; - p++; - space--; - } + *p = ' '; + ++p; strncpy(p, word, strlen(word) + 1); return 0; @@ -163,7 +160,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, if (!word) return 1; - if (merge_words(&mpp->features, word, 1)) { + if (merge_words(&mpp->features, word)) { FREE(word); return 1; } @@ -187,7 +184,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, if (!word) return 1; - if (merge_words(&mpp->hwhandler, word, 1)) { + if (merge_words(&mpp->hwhandler, word)) { FREE(word); return 1; } @@ -248,9 +245,8 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, num_pg_args = atoi(word); - if (merge_words(&mpp->selector, word, 1)) { + if (merge_words(&mpp->selector, word)) goto out1; - } FREE(word); } else { p += get_word(p, NULL); From patchwork Mon Jun 24 09:27:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012729 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 C0C8E76 for ; Mon, 24 Jun 2019 09:30:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1C1C28AF5 for ; Mon, 24 Jun 2019 09:30:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5E4628B4C; Mon, 24 Jun 2019 09:30:10 +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 522ED28B70 for ; Mon, 24 Jun 2019 09:30:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3103D3007149; Mon, 24 Jun 2019 09:30:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8F496090E; Mon, 24 Jun 2019 09:30:07 +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 63312206D6; Mon, 24 Jun 2019 09:30:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9T0RN004527 for ; Mon, 24 Jun 2019 05:29:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7BFA560FDB; Mon, 24 Jun 2019 09:28:59 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE61860BF7; Mon, 24 Jun 2019 09:28:55 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5873859473; Mon, 24 Jun 2019 09:28:53 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:46 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:29 +0200 Message-Id: <20190624092756.7769-5-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:28:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:28:53 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 04/30] libmultipath: fix -Wstringop-overflow warning in merge_words() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 24 Jun 2019 09:30:09 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Fixes the following warning from gcc 9: In file included from /usr/include/string.h:494, from dmparser.c:8: In function ‘strncpy’, inlined from ‘merge_words’ at dmparser.c:41:2: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmparser.c: In function ‘merge_words’: dmparser.c:41:19: note: length computed here 41 | strncpy(p, word, strlen(word) + 1); | ^~~~~~~~~~~~ Signed-off-by: Martin Wilck --- libmultipath/dmparser.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index 04f675c1..a8b0b71a 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -21,24 +21,21 @@ static int merge_words(char **dst, char *word) { char * p = *dst; - int len; + int len, dstlen; - len = strlen(*dst) + strlen(word) + 1; - *dst = REALLOC(*dst, len + 1); + dstlen = strlen(*dst); + len = dstlen + strlen(word) + 2; + *dst = REALLOC(*dst, len); if (!*dst) { free(p); return 1; } - p = *dst; - - while (*p != '\0') - p++; - + p = *dst + dstlen; *p = ' '; ++p; - strncpy(p, word, strlen(word) + 1); + strncpy(p, word, len - dstlen - 1); return 0; } From patchwork Mon Jun 24 09:27:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012715 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 C1894186E for ; Mon, 24 Jun 2019 09:29:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B113A28AF5 for ; Mon, 24 Jun 2019 09:29:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A522C28B5B; Mon, 24 Jun 2019 09:29:24 +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 01D6228B4C for ; Mon, 24 Jun 2019 09:29:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDEDCC0BB26F; Mon, 24 Jun 2019 09:29:16 +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 890816090E; Mon, 24 Jun 2019 09:29:12 +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 D9EEA1806B1A; Mon, 24 Jun 2019 09:29:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9SwpJ004495 for ; Mon, 24 Jun 2019 05:28:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id F0C7A5C237; Mon, 24 Jun 2019 09:28:58 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB67F5C236; Mon, 24 Jun 2019 09:28:56 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B71303086214; Mon, 24 Jun 2019 09:28:53 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:48 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:30 +0200 Message-Id: <20190624092756.7769-6-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 24 Jun 2019 09:28:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 24 Jun 2019 09:28:54 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 05/30] multipath-tools: fix more gcc 9 -Wstringop-truncation warnings 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 24 Jun 2019 09:29:23 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP More often than not, this means replacing strncpy() by strlcpy(). Signed-off-by: Martin Wilck --- libmpathpersist/mpath_persist.c | 8 ++++---- libmultipath/configure.c | 7 ++++--- libmultipath/discovery.c | 12 ++++++------ libmultipath/dmparser.c | 20 +++++++++----------- libmultipath/util.c | 2 +- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 599c5e9e..4abcaed5 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -497,8 +497,8 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, if (k < count) continue; } - strncpy(thread[count].param.dev, pp->dev, - FILE_NAME_SIZE - 1); + strlcpy(thread[count].param.dev, pp->dev, + FILE_NAME_SIZE); if (count && (thread[count].param.paramp->sa_flags & MPATH_F_SPEC_I_PT_MASK)){ /* @@ -686,8 +686,8 @@ int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope, continue; } - strncpy(thread[count].param.dev, pp->dev, - FILE_NAME_SIZE - 1); + strlcpy(thread[count].param.dev, pp->dev, + FILE_NAME_SIZE); condlog (3, "%s: sending pr out command to %s", mpp->wwid, pp->dev); rc = pthread_create (&thread[count].id, &attr, mpath_prout_pthread_fn, (void *) (&thread[count].param)); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index af4d78de..0648c0d6 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -73,7 +73,7 @@ int group_by_host_adapter(struct pathgroup *pgp, vector adapters) goto out; agp->pgp = pgp; - strncpy(agp->adapter_name, adapter_name1, SLOT_NAME_SIZE - 1); + strlcpy(agp->adapter_name, adapter_name1, SLOT_NAME_SIZE); store_adaptergroup(adapters, agp); /* create a new host port group @@ -667,7 +667,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload) if (!cmpp) { condlog(2, "%s: remove (wwid changed)", mpp->alias); dm_flush_map(mpp->alias); - strncpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE - 1); + strlcpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE); drop_multipath(curmp, cmpp_by_name->wwid, KEEP_PATHS); mpp->action = ACT_CREATE; condlog(3, "%s: set ACT_CREATE (map wwid change)", @@ -1451,7 +1451,8 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); - if (((dm_get_uuid(dev, tmpwwid)) == 0) && (strlen(tmpwwid))) { + if (((dm_get_uuid(dev, tmpwwid)) == 0) + && (strlen(tmpwwid))) { refwwid = tmpwwid; goto check; } diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 51ca2306..407e64a0 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -297,8 +297,8 @@ sysfs_get_timeout(const struct path *pp, unsigned int *timeout) return 1; } -int -sysfs_get_tgt_nodename (struct path *pp, char * node) +static int +sysfs_get_tgt_nodename(struct path *pp, char *node) { const char *tgtname, *value; struct udev_device *parent, *tgtdev; @@ -322,7 +322,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (tgtid >= 0) { pp->sg_id.proto_id = SCSI_PROTOCOL_SAS; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); return 0; } } @@ -334,7 +334,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value && !strcmp(value, "usb")) { pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC; tgtname = udev_device_get_sysname(tgtdev); - strncpy(node, tgtname, strlen(tgtname)); + strlcpy(node, tgtname, NODE_NAME_SIZE); condlog(3, "%s: skip USB device %s", pp->dev, node); return 1; } @@ -361,7 +361,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value) { pp->sg_id.proto_id = SCSI_PROTOCOL_FCP; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); udev_device_unref(tgtdev); return 0; } else @@ -390,7 +390,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value) { pp->sg_id.proto_id = SCSI_PROTOCOL_ISCSI; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); udev_device_unref(tgtdev); return 0; } diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index a8b0b71a..b856a07f 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -308,11 +308,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, if (!pp) goto out1; - strncpy(pp->dev_t, word, BLK_DEV_SIZE - 1); - strncpy(pp->dev, devname, FILE_NAME_SIZE - 1); + strlcpy(pp->dev_t, word, BLK_DEV_SIZE); + strlcpy(pp->dev, devname, FILE_NAME_SIZE); if (strlen(mpp->wwid)) { - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, + WWID_SIZE); } /* Only call this in multipath client mode */ if (!is_daemon && store_path(pathvec, pp)) @@ -320,8 +320,8 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, } else { if (!strlen(pp->wwid) && strlen(mpp->wwid)) - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, + WWID_SIZE); } FREE(word); @@ -333,23 +333,21 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, * in the get_dm_mpvec() code path */ if (!strlen(mpp->wwid)) - strncpy(mpp->wwid, pp->wwid, - WWID_SIZE - 1); + strlcpy(mpp->wwid, pp->wwid, WWID_SIZE); /* * Update wwid for paths which may not have been * active at the time the getuid callout was run */ else if (!strlen(pp->wwid)) - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, WWID_SIZE); /* * Do not allow in-use patch to change wwid */ else if (strcmp(pp->wwid, mpp->wwid) != 0) { condlog(0, "%s: path wwid appears to have changed. Using map wwid.\n", pp->dev_t); - strncpy(pp->wwid, mpp->wwid, WWID_SIZE); + strlcpy(pp->wwid, mpp->wwid, WWID_SIZE); } pgp->id ^= (long)pp; diff --git a/libmultipath/util.c b/libmultipath/util.c index 5b838d51..8a4be787 100644 --- a/libmultipath/util.c +++ b/libmultipath/util.c @@ -188,7 +188,7 @@ int devt2devname(char *devname, int devname_len, char *devt) return 1; } p++; - strncpy(devname, p, devname_len); + strlcpy(devname, p, devname_len); return 0; } } From patchwork Mon Jun 24 09:27:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012741 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 79A58186E for ; Mon, 24 Jun 2019 09:30:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 697C926E97 for ; Mon, 24 Jun 2019 09:30:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E0A428B4C; Mon, 24 Jun 2019 09:30:26 +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 2B69028AF5 for ; Mon, 24 Jun 2019 09:30:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E5A3630832E1; Mon, 24 Jun 2019 09:30:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBAA360143; Mon, 24 Jun 2019 09:30:23 +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 72EA7206D5; Mon, 24 Jun 2019 09:30:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9T9nH004758 for ; Mon, 24 Jun 2019 05:29:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 130785C225; Mon, 24 Jun 2019 09:29:09 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A12B5C22E; Mon, 24 Jun 2019 09:29:09 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 822D7C0578FA; Mon, 24 Jun 2019 09:29:00 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:50 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:31 +0200 Message-Id: <20190624092756.7769-7-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:29:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:29:00 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 06/30] multipath-tools: Fix more strncpy(X, Y, size - 1) calls 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 24 Jun 2019 09:30:24 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The compiler emitted no warnings for these, but for consistency it makes sense to fix them, too. Signed-off-by: Martin Wilck --- libmpathpersist/mpath_persist.c | 2 +- libmultipath/configure.c | 4 ++-- libmultipath/prio.c | 3 ++- libmultipath/structs_vec.c | 3 ++- multipathd/waiter.c | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 4abcaed5..53022f5b 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -618,7 +618,7 @@ int send_prout_activepath(char * dev, int rq_servact, int rq_scope, int rc; memset(&thread, 0, sizeof(thread)); - strncpy(param.dev, dev, FILE_NAME_SIZE - 1); + strlcpy(param.dev, dev, FILE_NAME_SIZE); /* Initialize and set thread joinable attribute */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 0648c0d6..52afa378 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -650,7 +650,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload) if (cmpp) { condlog(2, "%s: rename %s to %s", mpp->wwid, cmpp->alias, mpp->alias); - strncpy(mpp->alias_old, cmpp->alias, WWID_SIZE - 1); + strlcpy(mpp->alias_old, cmpp->alias, WWID_SIZE); mpp->action = ACT_RENAME; if (force_reload) { mpp->force_udev_reload = 1; @@ -1257,7 +1257,7 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, if (!deadmap(mpp)) continue; - strncpy(alias, mpp->alias, WWID_SIZE - 1); + strlcpy(alias, mpp->alias, WWID_SIZE); vector_del_slot(newmp, i); i--; diff --git a/libmultipath/prio.c b/libmultipath/prio.c index 0590218d..87de1f97 100644 --- a/libmultipath/prio.c +++ b/libmultipath/prio.c @@ -5,6 +5,7 @@ #include #include "debug.h" +#include "util.h" #include "prio.h" static LIST_HEAD(prioritizers); @@ -166,7 +167,7 @@ void prio_get (char *multipath_dir, struct prio * dst, char * name, char * args) strncpy(dst->name, src->name, PRIO_NAME_LEN); if (args) - strncpy(dst->args, args, PRIO_ARGS_LEN - 1); + strlcpy(dst->args, args, PRIO_ARGS_LEN); dst->getprio = src->getprio; dst->handle = NULL; diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index db5d19da..c43b58fb 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -2,6 +2,7 @@ #include #include +#include "util.h" #include "checkers.h" #include "vector.h" #include "defaults.h" @@ -350,7 +351,7 @@ find_existing_alias (struct multipath * mpp, vector_foreach_slot (vecs->mpvec, mp, i) if (strncmp(mp->wwid, mpp->wwid, WWID_SIZE - 1) == 0) { - strncpy(mpp->alias_old, mp->alias, WWID_SIZE - 1); + strlcpy(mpp->alias_old, mp->alias, WWID_SIZE); return; } } diff --git a/multipathd/waiter.c b/multipathd/waiter.c index 5895f157..eb8d6996 100644 --- a/multipathd/waiter.c +++ b/multipathd/waiter.c @@ -11,6 +11,7 @@ #include #include +#include "util.h" #include "vector.h" #include "memory.h" #include "checkers.h" @@ -210,7 +211,7 @@ int start_waiter_thread (struct multipath *mpp, struct vectors *vecs) if (!wp) goto out; - strncpy(wp->mapname, mpp->alias, WWID_SIZE - 1); + strlcpy(wp->mapname, mpp->alias, WWID_SIZE); wp->vecs = vecs; if (pthread_create(&wp->thread, &waiter_attr, waitevent, wp)) { From patchwork Mon Jun 24 09:27:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012719 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 E906F112C for ; Mon, 24 Jun 2019 09:29:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D684328AF5 for ; Mon, 24 Jun 2019 09:29:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5F5828B5D; Mon, 24 Jun 2019 09:29:57 +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 6A07628AF5 for ; Mon, 24 Jun 2019 09:29:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50B9381DEB; Mon, 24 Jun 2019 09:29:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22BEF600D1; Mon, 24 Jun 2019 09:29:56 +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 E1A44206D4; Mon, 24 Jun 2019 09:29:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9T8Xo004742 for ; Mon, 24 Jun 2019 05:29:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id A13E95C5FD; Mon, 24 Jun 2019 09:29:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 741125C64A; Mon, 24 Jun 2019 09:29:08 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E452EA705; Mon, 24 Jun 2019 09:29:00 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:53 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:33 +0200 Message-Id: <20190624092756.7769-9-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 07/30] libmultipath/libmpathcmd: use target length for unix socket sun_path 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 24 Jun 2019 09:29:56 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Note that sun_path doesn't necessarily need to be 0-terminated for an abstract socket name for ux_socket_listen(), this means we need to use memcpy to avoid a spurious warning. Signed-off-by: Martin Wilck --- libmpathcmd/mpath_cmd.c | 4 +++- libmultipath/uxsock.c | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index b681311b..f00bf7e1 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -103,8 +103,10 @@ int __mpath_connect(int nonblocking) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; addr.sun_path[0] = '\0'; + strncpy(&addr.sun_path[1], DEFAULT_SOCKET, sizeof(addr.sun_path) - 1); len = strlen(DEFAULT_SOCKET) + 1 + sizeof(sa_family_t); - strncpy(&addr.sun_path[1], DEFAULT_SOCKET, len); + if (len > sizeof(struct sockaddr_un)) + len = sizeof(struct sockaddr_un); fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (fd == -1) diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c index 7e5a1449..9b4e9784 100644 --- a/libmultipath/uxsock.c +++ b/libmultipath/uxsock.c @@ -66,9 +66,12 @@ int ux_socket_listen(const char *name) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; addr.sun_path[0] = '\0'; - len = strlen(name) + 1 + sizeof(sa_family_t); - strncpy(&addr.sun_path[1], name, len); + len = strlen(name) + 1; + if (len >= sizeof(addr.sun_path)) + len = sizeof(addr.sun_path) - 1; + memcpy(&addr.sun_path[1], name, len); + len += sizeof(sa_family_t); if (bind(fd, (struct sockaddr *)&addr, len) == -1) { condlog(3, "Couldn't bind to ux_socket, error %d", errno); close(fd); From patchwork Mon Jun 24 09:27:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012731 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 5BCD276 for ; Mon, 24 Jun 2019 09:30:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B73928AF5 for ; Mon, 24 Jun 2019 09:30:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FDA528B5B; Mon, 24 Jun 2019 09:30:17 +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 DCC1528AF5 for ; Mon, 24 Jun 2019 09:30:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC7BC308222F; Mon, 24 Jun 2019 09:30:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C30DF5D9C5; Mon, 24 Jun 2019 09:30:15 +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 833D8206D5; Mon, 24 Jun 2019 09:30:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TA66004800 for ; Mon, 24 Jun 2019 05:29:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 694315C22F; Mon, 24 Jun 2019 09:29:10 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 602925C225; Mon, 24 Jun 2019 09:29:08 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 219225D61E; Mon, 24 Jun 2019 09:29:01 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:55 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:34 +0200 Message-Id: <20190624092756.7769-10-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 08/30] libmultipath: inline set_default() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 24 Jun 2019 09:30:16 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This is nothing but a reimplementation of strdup(), and it causes gcc 9 warnings. Remove it. Signed-off-by: Martin Wilck --- libmultipath/debug.c | 1 + libmultipath/defaults.c | 17 ----------------- libmultipath/defaults.h | 9 ++++++++- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/libmultipath/debug.c b/libmultipath/debug.c index cbf1e570..4128cb90 100644 --- a/libmultipath/debug.c +++ b/libmultipath/debug.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "log_pthread.h" #include diff --git a/libmultipath/defaults.c b/libmultipath/defaults.c index c20bb0d2..082640d3 100644 --- a/libmultipath/defaults.c +++ b/libmultipath/defaults.c @@ -7,20 +7,3 @@ #include "memory.h" const char * const default_partition_delim = DEFAULT_PARTITION_DELIM; - -char * -set_default (char * str) -{ - int len; - char * p; - - len = strlen(str); - p = MALLOC(len + 1); - - if (!p) - return NULL; - - strncat(p, str, len); - - return p; -} diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h index 65769398..83f89f37 100644 --- a/libmultipath/defaults.h +++ b/libmultipath/defaults.h @@ -1,3 +1,5 @@ +#ifndef _DEFAULTS_H +#define _DEFAULTS_H /* * If you add or modify a value also update multipath/multipath.conf.5 * and the TEMPLATE in libmultipath/hwtable.c @@ -60,5 +62,10 @@ #define DEFAULT_CONFIG_DIR "/etc/multipath/conf.d" #define MULTIPATH_SHM_BASE "/dev/shm/multipath/" -char * set_default (char * str); + +static inline char *set_default(char *str) +{ + return strdup(str); +} extern const char *const default_partition_delim; +#endif /* _DEFAULTS_H */ From patchwork Mon Jun 24 09:27:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012725 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 9131676 for ; Mon, 24 Jun 2019 09:30:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D34B28AF5 for ; Mon, 24 Jun 2019 09:30:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E36228B5B; Mon, 24 Jun 2019 09:30:06 +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 E407128AF5 for ; Mon, 24 Jun 2019 09:30:05 +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 C6F7159474; Mon, 24 Jun 2019 09:30:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97FC75C225; Mon, 24 Jun 2019 09:30:04 +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 3F903206D5; Mon, 24 Jun 2019 09:30:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9T8XL004751 for ; Mon, 24 Jun 2019 05:29:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id D446D60BFC; Mon, 24 Jun 2019 09:29:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0B0360BF7; Mon, 24 Jun 2019 09:29:08 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5040B81F0D; Mon, 24 Jun 2019 09:29:01 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:57 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:35 +0200 Message-Id: <20190624092756.7769-11-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:01 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 09/30] libmultipath: add size argument to dm_get_uuid() 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: , 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.39]); Mon, 24 Jun 2019 09:30:05 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The length of the uuid field in libdm is DM_UUID_LEN, which happens to be one byte more than our WWID_SIZE. Handle this cleanly. Signed-off-by: Martin Wilck --- libmultipath/configure.c | 2 +- libmultipath/devmapper.c | 28 +++++++++++++++++----------- libmultipath/devmapper.h | 2 +- libmultipath/wwids.c | 3 ++- multipathd/main.c | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 52afa378..c8dd69b0 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -1451,7 +1451,7 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); - if (((dm_get_uuid(dev, tmpwwid)) == 0) + if (((dm_get_uuid(dev, tmpwwid, WWID_SIZE)) == 0) && (strlen(tmpwwid))) { refwwid = tmpwwid; goto check; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 2e79667d..0f0c3a34 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -13,7 +13,9 @@ #include #include #include +#include +#include "util.h" #include "checkers.h" #include "vector.h" #include "structs.h" @@ -554,7 +556,7 @@ out: } static int -dm_get_prefixed_uuid(const char *name, char *uuid) +dm_get_prefixed_uuid(const char *name, char *uuid, int uuid_len) { struct dm_task *dmt; const char *uuidtmp; @@ -572,7 +574,7 @@ dm_get_prefixed_uuid(const char *name, char *uuid) uuidtmp = dm_task_get_uuid(dmt); if (uuidtmp) - strcpy(uuid, uuidtmp); + strlcpy(uuid, uuidtmp, uuid_len); else uuid[0] = '\0'; @@ -582,14 +584,18 @@ uuidout: return r; } -int dm_get_uuid(const char *name, char *uuid) +int dm_get_uuid(const char *name, char *uuid, int uuid_len) { - if (dm_get_prefixed_uuid(name, uuid)) + char tmp[DM_UUID_LEN]; + + if (dm_get_prefixed_uuid(name, tmp, sizeof(tmp))) return 1; - if (!strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN)) - memmove(uuid, uuid + UUID_PREFIX_LEN, - strlen(uuid + UUID_PREFIX_LEN) + 1); + if (!strncmp(tmp, UUID_PREFIX, UUID_PREFIX_LEN)) + strlcpy(uuid, tmp + UUID_PREFIX_LEN, uuid_len); + else + uuid[0] = '\0'; + return 0; } @@ -597,12 +603,12 @@ static int is_mpath_part(const char *part_name, const char *map_name) { char *p; - char part_uuid[WWID_SIZE], map_uuid[WWID_SIZE]; + char part_uuid[DM_UUID_LEN], map_uuid[DM_UUID_LEN]; - if (dm_get_prefixed_uuid(part_name, part_uuid)) + if (dm_get_prefixed_uuid(part_name, part_uuid, sizeof(part_uuid))) return 0; - if (dm_get_prefixed_uuid(map_name, map_uuid)) + if (dm_get_prefixed_uuid(map_name, map_uuid, sizeof(map_uuid))) return 0; if (strncmp(part_uuid, "part", 4) != 0) @@ -1066,7 +1072,7 @@ struct multipath *dm_get_multipath(const char *name) if (dm_get_map(name, &mpp->size, NULL)) goto out; - dm_get_uuid(name, mpp->wwid); + dm_get_uuid(name, mpp->wwid, WWID_SIZE); dm_get_info(name, &mpp->dmi); return mpp; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index db75526c..7557a86b 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -63,7 +63,7 @@ int dm_get_major_minor (const char *name, int *major, int *minor); char * dm_mapname(int major, int minor); int dm_remove_partmaps (const char * mapname, int need_sync, int deferred_remove); -int dm_get_uuid(const char *name, char *uuid); +int dm_get_uuid(const char *name, char *uuid, int uuid_len); int dm_get_info (const char * mapname, struct dm_info ** dmi); int dm_rename (const char * old, char * new, char * delim, int skip_kpartx); int dm_reassign(const char * mapname); diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c index 53e79511..ef748125 100644 --- a/libmultipath/wwids.c +++ b/libmultipath/wwids.c @@ -294,7 +294,8 @@ should_multipath(struct path *pp1, vector pathvec, vector mpvec) char tmp_wwid[WWID_SIZE]; struct multipath *mp = find_mp_by_wwid(mpvec, pp1->wwid); - if (mp != NULL && dm_get_uuid(mp->alias, tmp_wwid) == 0 && + if (mp != NULL && + dm_get_uuid(mp->alias, tmp_wwid, WWID_SIZE) == 0 && !strncmp(tmp_wwid, pp1->wwid, WWID_SIZE)) { condlog(3, "wwid %s is already multipathed, keeping it", pp1->wwid); diff --git a/multipathd/main.c b/multipathd/main.c index eef84a39..2e4973d7 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -406,7 +406,7 @@ set_multipath_wwid (struct multipath * mpp) if (strlen(mpp->wwid)) return; - dm_get_uuid(mpp->alias, mpp->wwid); + dm_get_uuid(mpp->alias, mpp->wwid, WWID_SIZE); } static void set_no_path_retry(struct multipath *mpp) From patchwork Mon Jun 24 09:27:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012745 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 BC307112C for ; Mon, 24 Jun 2019 09:30:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB1ED285C8 for ; Mon, 24 Jun 2019 09:30:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F30028841; Mon, 24 Jun 2019 09:30:32 +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 4B510285C8 for ; Mon, 24 Jun 2019 09:30:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 413A7C04BD35; Mon, 24 Jun 2019 09:30:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B66165D9C8; Mon, 24 Jun 2019 09:30:30 +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 66957206D6; Mon, 24 Jun 2019 09:30:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TLY5005074 for ; Mon, 24 Jun 2019 05:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A8C25C22E; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1936A5C221; Mon, 24 Jun 2019 09:29:19 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AB96BBF77; Mon, 24 Jun 2019 09:29:10 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:28:58 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:36 +0200 Message-Id: <20190624092756.7769-12-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:29:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:29:10 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 10/30] multipath-tools tests: omit timestamp in log messages 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:30:31 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Martin Wilck --- tests/globals.c | 2 +- tests/hwtable.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/globals.c b/tests/globals.c index 07d970ea..aeb7723f 100644 --- a/tests/globals.c +++ b/tests/globals.c @@ -3,7 +3,7 @@ /* Required globals */ struct udev *udev; -int logsink = 0; +int logsink = -1; struct config conf = { .uid_attrs = "sd:ID_BOGUS", .verbosity = 4, diff --git a/tests/hwtable.c b/tests/hwtable.c index ad863b08..13da1d99 100644 --- a/tests/hwtable.c +++ b/tests/hwtable.c @@ -54,7 +54,7 @@ struct hwt_state { static struct config *_conf; struct udev *udev; -int logsink; +int logsink = -1; struct config *get_multipath_config(void) { From patchwork Mon Jun 24 09:27:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012757 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 3863576 for ; Mon, 24 Jun 2019 09:30:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27179285C8 for ; Mon, 24 Jun 2019 09:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BA8C28841; Mon, 24 Jun 2019 09:30:45 +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 C1638285C8 for ; Mon, 24 Jun 2019 09:30:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2748306641B; Mon, 24 Jun 2019 09:30:43 +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 CF3275D9C5; Mon, 24 Jun 2019 09:30:43 +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 677D81806B1D; Mon, 24 Jun 2019 09:30:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TMRo005105 for ; Mon, 24 Jun 2019 05:29:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1883360143; Mon, 24 Jun 2019 09:29:22 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418D1600CD; Mon, 24 Jun 2019 09:29:19 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9CCA30F1BD7; Mon, 24 Jun 2019 09:29:10 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:00 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:37 +0200 Message-Id: <20190624092756.7769-13-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 11/30] tests/hwtable: decrease log verbosity 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 24 Jun 2019 09:30:44 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Martin Wilck --- tests/hwtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hwtable.c b/tests/hwtable.c index 13da1d99..f436f52d 100644 --- a/tests/hwtable.c +++ b/tests/hwtable.c @@ -457,7 +457,7 @@ static void replicate_config(const struct hwt_state *hwt, bool local) vector hwtable; struct config *conf; - condlog(1, "--- %s: replicating %s configuration", __func__, + condlog(3, "--- %s: replicating %s configuration", __func__, local ? "local" : "full"); conf = get_multipath_config(); From patchwork Mon Jun 24 09:27:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012737 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 4E0D076 for ; Mon, 24 Jun 2019 09:30:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E48C28AF5 for ; Mon, 24 Jun 2019 09:30:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3295628B5B; Mon, 24 Jun 2019 09:30:23 +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 BACC628AF5 for ; Mon, 24 Jun 2019 09:30:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C23727FDEE; Mon, 24 Jun 2019 09:30:21 +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 8C52560605; Mon, 24 Jun 2019 09:30:21 +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 3F8BC1806B18; Mon, 24 Jun 2019 09:30:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TLuM005076 for ; Mon, 24 Jun 2019 05:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5AE2C5C231; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CE855C225; Mon, 24 Jun 2019 09:29:19 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9404307EA82; Mon, 24 Jun 2019 09:29:10 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:02 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:38 +0200 Message-Id: <20190624092756.7769-14-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 12/30] multipath-tools tests: add strlcpy() tests 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:30:22 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP As we're using strlcpy quite a bit, make sure it works as designed. Signed-off-by: Martin Wilck --- tests/util.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/tests/util.c b/tests/util.c index e6d4b9ab..4e04a480 100644 --- a/tests/util.c +++ b/tests/util.c @@ -258,10 +258,152 @@ int test_basenamecpy(void) return cmocka_run_group_tests(tests, NULL, NULL); } +static const char src_str[] = "Hello"; + +/* strlcpy with length 0 */ +static void test_strlcpy_0(void **state) +{ + char tst[] = "word"; + int rc; + + rc = strlcpy(tst, src_str, 0); + assert_int_equal(rc, strlen(src_str)); + assert_string_equal(tst, "word"); +} + +/* strlcpy with length 1 */ +static void test_strlcpy_1(void **state) +{ + char tst[] = "word"; + int rc; + + rc = strlcpy(tst, src_str, 1); + assert_int_equal(rc, strlen(src_str)); + assert_int_equal(tst[0], '\0'); + assert_string_equal(tst + 1, "ord"); +} + +/* strlcpy with length 2 */ +static void test_strlcpy_2(void **state) +{ + char tst[] = "word"; + int rc; + + rc = strlcpy(tst, src_str, 2); + assert_int_equal(rc, strlen(src_str)); + assert_int_equal(tst[0], src_str[0]); + assert_int_equal(tst[1], '\0'); + assert_string_equal(tst + 2, "rd"); +} + +/* strlcpy with dst length < src length */ +static void test_strlcpy_3(void **state) +{ + char tst[] = "word"; + int rc; + + rc = strlcpy(tst, src_str, sizeof(tst)); + assert_int_equal(rc, strlen(src_str)); + assert_int_equal(sizeof(tst) - 1, strlen(tst)); + assert_true(strncmp(tst, src_str, sizeof(tst) - 1) == 0); +} + +/* strlcpy with dst length > src length */ +static void test_strlcpy_4(void **state) +{ + static const char old[] = "0123456789"; + char *tst; + int rc; + + tst = strdup(old); + rc = strlcpy(tst, src_str, sizeof(old)); + assert_int_equal(rc, strlen(src_str)); + assert_string_equal(src_str, tst); + assert_string_equal(tst + sizeof(src_str), old + sizeof(src_str)); + free(tst); +} + +/* strlcpy with dst length = src length, dst not terminated */ +static void test_strlcpy_5(void **state) +{ + char *tst; + int rc; + + tst = malloc(sizeof(src_str)); + memset(tst, 'f', sizeof(src_str)); + + rc = strlcpy(tst, src_str, sizeof(src_str)); + assert_int_equal(rc, strlen(src_str)); + assert_string_equal(src_str, tst); + + free(tst); +} + +/* strlcpy with dst length > src length, dst not terminated */ +static void test_strlcpy_6(void **state) +{ + char *tst; + int rc; + + tst = malloc(sizeof(src_str) + 2); + memset(tst, 'f', sizeof(src_str) + 2); + + rc = strlcpy(tst, src_str, sizeof(src_str) + 2); + assert_int_equal(rc, strlen(src_str)); + assert_string_equal(src_str, tst); + assert_int_equal(tst[sizeof(src_str)], 'f'); + assert_int_equal(tst[sizeof(src_str) + 1], 'f'); + + free(tst); +} + +/* strlcpy with empty src */ +static void test_strlcpy_7(void **state) +{ + char tst[] = "word"; + static const char empty[] = ""; + int rc; + + rc = strlcpy(tst, empty, sizeof(tst)); + assert_int_equal(rc, strlen(empty)); + assert_string_equal(empty, tst); + assert_string_equal(tst + 1, "ord"); +} + +/* strlcpy with empty src, length 0 */ +static void test_strlcpy_8(void **state) +{ + char tst[] = "word"; + static const char empty[] = ""; + int rc; + + rc = strlcpy(tst, empty, 0); + assert_int_equal(rc, strlen(empty)); + assert_string_equal("word", tst); +} + +static int test_strlcpy(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_strlcpy_0), + cmocka_unit_test(test_strlcpy_1), + cmocka_unit_test(test_strlcpy_2), + cmocka_unit_test(test_strlcpy_3), + cmocka_unit_test(test_strlcpy_4), + cmocka_unit_test(test_strlcpy_5), + cmocka_unit_test(test_strlcpy_6), + cmocka_unit_test(test_strlcpy_7), + cmocka_unit_test(test_strlcpy_8), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} + int main(void) { int ret = 0; ret += test_basenamecpy(); + ret += test_strlcpy(); return ret; } From patchwork Mon Jun 24 09:27:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012761 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 0777E112C for ; Mon, 24 Jun 2019 09:30:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5B6B285C8 for ; Mon, 24 Jun 2019 09:30:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6AAE28841; Mon, 24 Jun 2019 09:30:54 +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 7C4FC285C8 for ; Mon, 24 Jun 2019 09:30:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E76046288; Mon, 24 Jun 2019 09:30:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D85460C64; Mon, 24 Jun 2019 09:30:52 +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 4B77E206D2; Mon, 24 Jun 2019 09:30:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TM1o005116 for ; Mon, 24 Jun 2019 05:29:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C6985B687; Mon, 24 Jun 2019 09:29:22 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE6985D721; Mon, 24 Jun 2019 09:29:19 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 285A5307D762; Mon, 24 Jun 2019 09:29:11 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:04 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:39 +0200 Message-Id: <20190624092756.7769-15-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 13/30] multipath-tools tests: add test for VPD parsing 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:30:53 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Add a test for parsing the WWID from VPDs, with focus on WWID buffer overflow detection and handling. Signed-off-by: Martin Wilck --- tests/Makefile | 4 +- tests/vpd.c | 790 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 793 insertions(+), 1 deletion(-) create mode 100644 tests/vpd.c diff --git a/tests/Makefile b/tests/Makefile index ef900866..bf159b2d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -3,7 +3,7 @@ include ../Makefile.inc CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka -TESTS := uevent parser util dmevents hwtable blacklist unaligned +TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd .SILENT: $(TESTS:%=%.o) .PRECIOUS: $(TESTS:%=%-test) @@ -25,6 +25,8 @@ hwtable-test_OBJDEPS := ../libmultipath/discovery.o ../libmultipath/blacklist.o hwtable-test_LIBDEPS := -ludev -lpthread -ldl blacklist-test_OBJDEPS := ../libmultipath/blacklist.o blacklist-test_LIBDEPS := -ludev +vpd-test_OBJDEPS := ../libmultipath/discovery.o +vpd-test_LIBDEPS := -ludev -lpthread -ldl lib/libchecktur.so: mkdir lib diff --git a/tests/vpd.c b/tests/vpd.c new file mode 100644 index 00000000..d9f80eaa --- /dev/null +++ b/tests/vpd.c @@ -0,0 +1,790 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (c) 2019 Martin Wilck, SUSE Linux GmbH, Nuremberg */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "unaligned.h" +#include "debug.h" +#include "vector.h" +#include "structs.h" +#include "discovery.h" +#include "globals.c" + +#define VPD_BUFSIZ 4096 + +struct vpdtest { + unsigned char vpdbuf[VPD_BUFSIZ]; + char wwid[WWID_SIZE]; +}; + +static int setup(void **state) +{ + struct vpdtest *vt = malloc(sizeof(*vt)); + + if (vt == NULL) + return -1; + *state = vt; + return 0; +} + +static int teardown(void **state) +{ + struct vpdtest *vt = *state; + + free(vt); + *state = NULL; + return 0; +} + +/* vendor_id should have less than 8 chars to test space handling */ +static const char vendor_id[] = "Linux"; +static const char test_id[] = + "A123456789AbcDefB123456789AbcDefC123456789AbcDefD123456789AbcDef"; + +int __wrap_ioctl(int fd, unsigned long request, void *param) +{ + int len; + struct sg_io_hdr *io_hdr; + unsigned char *val; + + len = mock(); + io_hdr = (struct sg_io_hdr *)param; + assert_in_range(len, 0, io_hdr->dxfer_len); + val = mock_ptr_type(unsigned char *); + io_hdr->status = 0; + memcpy(io_hdr->dxferp, val, len); + return 0; +} + + +/** + * create_vpd80() - create a "unit serial number" VPD page. + * @buf: VPD buffer + * @bufsiz: length of VPD buffer + * @id: input ID + * @size: value for the "page length" field + * @len: actual number of characters to use from @id + * + * If len < size, the content will be right aligned, as mandated by the + * SPC spec. + * + * Return: VPD length. + */ +static int create_vpd80(unsigned char *buf, size_t bufsiz, const char *id, + int size, int len) +{ + assert_true(len <= size); + + memset(buf, 0, bufsiz); + buf[1] = 0x80; + put_unaligned_be16(size, buf + 2); + + memset(buf + 4, ' ', size - len); + memcpy(buf + 4 + size - len, id, len); + return size + 4; +} + +static int _hex2bin(const char hx) +{ + assert_true(isxdigit(hx)); + if (hx >= '0' && hx <= '9') + return hx - '0'; + if (hx >= 'a' && hx <= 'f') + return hx - 'a' + 10; + if (hx >= 'A' && hx <= 'F') + return hx - 'A' + 10; + return -1; +} + +static void hex2bin(unsigned char *dst, const char *src, + size_t dstlen, size_t srclen) +{ + const char *sc; + unsigned char *ds; + + assert(srclen % 2 == 0); + for (sc = src, ds = dst; + sc < src + srclen && ds < dst + dstlen; + sc += 2, ++ds) + *ds = 16 * _hex2bin(sc[0]) + _hex2bin(sc[1]); +} + +/** + * create_t10_vendor_id_desc() - Create T10 vendor ID + * @desc: descriptor buffer + * @id: input ID + * @n: number of characters to use for ID + * (includes 8 bytes for vendor ID!) + * + * Create a "T10 vendor specific ID" designation descriptor. + * The vendor field (8 bytes) is filled with vendor_id (above). + * + * Return: descriptor length. + */ +static int create_t10_vendor_id_desc(unsigned char *desc, + const char *id, size_t n) +{ + int vnd_len = sizeof(vendor_id) - 1; + + /* code set: ascii */ + desc[0] = 2; + /* type: 10 vendor ID */ + desc[1] = 1; + desc[2] = 0; + desc[3] = n; + + memcpy(desc + 4, (const unsigned char *)vendor_id, vnd_len); + memset(desc + 4 + vnd_len, ' ', 8 - vnd_len); + memcpy(desc + 4 + 8, (const unsigned char *)id, n - 8); + + return n + 4; +} + +/** + * create_eui64_desc() - create EUI64 descriptor. + * @desc, @id: see above. + * @n: number of bytes (8, 12, or 16). + * + * Create an EUI64 designation descriptor. + * + * Return: descriptor length. + */ +static int create_eui64_desc(unsigned char *desc, + const char *id, size_t n) +{ + assert_true(n == 8 || n == 12 || n == 16); + + /* code set: binary */ + desc[0] = 1; + /* type: EUI64 */ + desc[1] = 2; + desc[2] = 0; + desc[3] = n; + + hex2bin(desc + 4, id, n, 2 * n); + return n + 4; +} + +/** + * create_naa_desc() - create an NAA designation descriptor + * @desc, @id: see above. + * @naa: Name Address Authority field (2, 3, 5, or 6). + * + * Return: descriptor length. + */ +static int create_naa_desc(unsigned char *desc, + const char *id, int naa) +{ + assert_true(naa == 2 || naa == 3 || naa == 5 || naa == 6); + + /* code set: binary */ + desc[0] = 1; + /* type: NAA */ + desc[1] = 3; + desc[2] = 0; + desc[4] = _hex2bin(id[0]) | (naa << 4); + switch (naa) { + case 2: + case 3: + case 5: + hex2bin(desc + 5, id + 1, 7, 14); + desc[3] = 8; + return 12; + case 6: + hex2bin(desc + 5, id + 1, 15, 30); + desc[3] = 16; + return 20; + default: + return 0; + } +} + +/* type and flags for SCSI name string designation descriptor */ +enum { + STR_EUI = 0, + STR_NAA, + STR_IQN, + STR_MASK = 0xf, + ZERO_LAST = 0x10, /* flag to zero out some bytes at string end */ +}; + +static const char * const str_prefix[] = { + [STR_EUI] = "eui.", + [STR_NAA] = "naa.", + [STR_IQN] = "iqn.", +}; + +static const char byte0[] = { + [STR_EUI] = '2', + [STR_NAA] = '3', + [STR_IQN] = '8', +}; + +/** + * create_scsi_string_desc() - create a SCSI name string descriptor. + * @desc, @id: see above. + * @typ: one of STR_EUI, STR_NAA, STR_IQN, possibly ORd with ZERO_LAST + * @maxlen: number of characters to use from input ID. + * + * If ZERO_LAST is set, zero out the last byte. + * + * Return: descriptor length. + */ +static int create_scsi_string_desc(unsigned char *desc, + const char *id, int typ, int maxlen) +{ + int len, plen; + int type = typ & STR_MASK; + + /* code set: UTF-8 */ + desc[0] = 3; + /* type: SCSI string */ + desc[1] = 8; + desc[2] = 0; + + assert_in_range(type, STR_EUI, STR_IQN); + assert_true(maxlen % 4 == 0); + len = snprintf((char *)(desc + 4), maxlen, "%s%s", + str_prefix[type], id); + if (len > maxlen) + len = maxlen; + /* zero-pad */ + if (typ & ZERO_LAST) + len -= 2; + plen = 4 * ((len - 1) / 4) + 4; + memset(desc + 4 + len, '\0', plen - len); + desc[3] = plen; + return plen + 4; +} + +/** + * create_vpd83() - create "device identification" VPD page + * @buf, @bufsiz, @id: see above. + * @type: descriptor type to use (1, 2, 3, 8) + * @parm: opaque parameter (e.g. means "naa" for NAA type) + * @len: designator length (exact meaning depends on designator type) + * + * Create a "device identification" VPD page with a single + * designation descriptor. + * + * Return: VPD page length. + */ +static int create_vpd83(unsigned char *buf, size_t bufsiz, const char *id, + uint8_t type, int parm, int len) +{ + unsigned char *desc; + int n = 0; + + memset(buf, 0, bufsiz); + buf[1] = 0x83; + + desc = buf + 4; + switch (type) { + case 1: + n = create_t10_vendor_id_desc(desc, id, len); + break; + case 2: + n = create_eui64_desc(desc, id, len); + break; + case 3: + n = create_naa_desc(desc, id, parm); + break; + case 8: + n = create_scsi_string_desc(desc, id, parm, len); + break; + default: + break; + } + put_unaligned_be16(n, buf + 2); + return n + 4; +} + +/** + * assert_correct_wwid() - test that a retrieved WWID matches expectations + * @test: test name + * @expected: expected WWID length + * @returned: WWID length as returned by code under test + * @byte0, @byte1: leading chars that our code prepends to the ID + * (e.g. "36" for "NAA registered extended" type) + * @lowercase: set if lower case WWID is expected + * @orig: original ID string, may be longer than wwid + * @wwid: WWID as returned by code under test + */ +static void assert_correct_wwid(const char *test, + int expected, int returned, + int byte0, int byte1, bool lowercase, + const char *orig, + const char *wwid) +{ + int ofs = 0, i; + + condlog(2, "%s: exp/ret: %d/%d, wwid: %s", test, + expected, returned, wwid); + /* + * byte0 and byte1 are the leading chars that our code prepends + * to the ID to indicate the designation descriptor type, . + */ + if (byte0 != 0) { + assert_int_equal(byte0, wwid[0]); + ++ofs; + } + if (byte1 != 0) { + assert_int_equal(byte1, wwid[1]); + ++ofs; + } + /* check matching length, and length of WWID string */ + assert_int_equal(expected, returned); + assert_int_equal(returned, strlen(wwid)); + /* check expected string value up to expected length */ + for (i = 0; i < returned - ofs; i++) + assert_int_equal(wwid[ofs + i], + lowercase ? tolower(orig[i]) : orig[i]); +} + +/* + * For T10 vendor ID - replace sequences of spaces with a single underscore. + * Use a different implementation then libmultipath, deliberately. + */ +static char *subst_spaces(const char *src) +{ + char *dst = calloc(1, strlen(src) + 1); + char *p; + static regex_t *re; + regmatch_t match; + int rc; + + assert_non_null(dst); + if (re == NULL) { + re = calloc(1, sizeof(*re)); + assert_non_null(re); + rc = regcomp(re, " +", REG_EXTENDED); + assert_int_equal(rc, 0); + } + + for (rc = regexec(re, src, 1, &match, 0), p = dst; + rc == 0; + src += match.rm_eo, rc = regexec(re, src, 1, &match, 0)) { + memcpy(p, src, match.rm_so); + p += match.rm_so; + *p = '_'; + ++p; + } + assert_int_equal(rc, REG_NOMATCH); + strcpy(p, src); + return dst; +} + +/** + * test_vpd_vnd_LEN_WLEN() - test code for VPD 83, T10 vendor ID + * @LEN: ID length in the VPD page (includes 8 byte vendor ID) + * @WLEN: WWID buffer size + * + * The input ID is modified by inserting some spaces, to be able to + * test the handling of spaces by the code. This is relevant only for + * a minimum input length of 24. + * The expected result must be adjusted accordingly. + */ +#define make_test_vpd_vnd(len, wlen) \ +static void test_vpd_vnd_ ## len ## _ ## wlen(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret, rc; \ + int exp_len; \ + char *exp_wwid, *exp_subst, *input; \ + \ + input = strdup(test_id); \ + /* 8 vendor bytes collapsed to actual vendor ID length + 1 */ \ + /* and one '1' prepended */ \ + exp_len = len - 8 + sizeof(vendor_id) + 1; \ + \ + /* insert some spaces to test space collapsing */ \ + input[15] = input[17] = input[18] = ' '; \ + /* adjust expectation for space treatment */ \ + /* drop char for 2nd space on offset 17/18 */ \ + if (len >= 18 + 9) \ + --exp_len; \ + /* drop trailing single '_' if input ends with space */ \ + if (len == 15 + 9 || len == 17 + 9 || len == 18 + 9) \ + --exp_len; \ + if (exp_len >= wlen) \ + exp_len = wlen - 1; \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), input, \ + 1, 0, len); \ + rc = asprintf(&exp_wwid, "%s_%s", vendor_id, input); \ + assert_int_not_equal(rc, -1); \ + free(input); \ + /* Replace spaces, like code under test */ \ + exp_subst = subst_spaces(exp_wwid); \ + free(exp_wwid); \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, vt->wwid, wlen); \ + assert_correct_wwid("test_vpd_vnd_" #len "_" #wlen, \ + exp_len, ret, '1', 0, false, \ + exp_subst, vt->wwid); \ + free(exp_subst); \ +} + +/** + * test_vpd_str_TYP_LEN_WLEN() - test code for VPD 83, SCSI name string + * @TYP: numeric value of STR_EUI, STR_NAA, STR_IQN above + * @LEN: ID length the VPD page + * @WLEN: WWID buffer size + */ +#define make_test_vpd_str(typ, len, wlen) \ +static void test_vpd_str_ ## typ ## _ ## len ## _ ## wlen(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + int exp_len; \ + int type = typ & STR_MASK; \ + \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, \ + 8, typ, len); \ + exp_len = len - strlen(str_prefix[type]); \ + if (typ & ZERO_LAST) \ + exp_len--; \ + if (exp_len >= wlen) \ + exp_len = wlen - 1; \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, vt->wwid, wlen); \ + assert_correct_wwid("test_vpd_str_" #typ "_" #len "_" #wlen, \ + exp_len, ret, byte0[type], 0, \ + type != STR_IQN, \ + test_id, vt->wwid); \ +} + +/** + * test_vpd_naa_NAA_WLEN() - test code for VPD 83 NAA designation + * @NAA: Network Name Authority (2, 3, 5, or 6) + * @WLEN: WWID buffer size + */ +#define make_test_vpd_naa(naa, wlen) \ +static void test_vpd_naa_ ## naa ## _ ## wlen(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + int len, exp_len; \ + \ + switch (naa) { \ + case 2: \ + case 3: \ + case 5: \ + len = 17; \ + break; \ + case 6: \ + len = 33; \ + break; \ + } \ + /* returned size is always uneven */ \ + exp_len = wlen > len ? len : \ + wlen % 2 == 0 ? wlen - 1 : wlen - 2; \ + \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, \ + 3, naa, 0); \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, vt->wwid, wlen); \ + assert_correct_wwid("test_vpd_naa_" #naa "_" #wlen, \ + exp_len, ret, '3', '0' + naa, true, \ + test_id, vt->wwid); \ +} + +/** + * test_vpd_eui_LEN_WLEN() - test code for VPD 83, EUI64 + * @LEN: EUI64 length (8, 12, or 16) + * @WLEN: WWID buffer size + */ +#define make_test_vpd_eui(len, wlen) \ +static void test_vpd_eui_ ## len ## _ ## wlen(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + /* returned size is always uneven */ \ + int exp_len = wlen > 2 * len + 1 ? 2 * len + 1 : \ + wlen % 2 == 0 ? wlen - 1 : wlen - 2; \ + \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, \ + 2, 0, len); \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, vt->wwid, wlen); \ + assert_correct_wwid("test_vpd_eui_" #len "_" #wlen, \ + exp_len, ret, '2', 0, true, \ + test_id, vt->wwid); \ +} + +/** + * test_vpd80_SIZE_LEN_WLEN() - test code for VPD 80 + * @SIZE, @LEN: see create_vpd80() + * @WLEN: WWID buffer size + */ +#define make_test_vpd80(size, len, wlen) \ +static void test_vpd80_ ## size ## _ ## len ## _ ## wlen(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + int exp_len = len > 20 ? 20 : len; \ + char *input = strdup(test_id); \ + \ + /* insert trailing whitespace after pos 20 */ \ + memset(input + 20, ' ', sizeof(test_id) - 20); \ + if (exp_len >= wlen) \ + exp_len = wlen - 1; \ + n = create_vpd80(vt->vpdbuf, sizeof(vt->vpdbuf), input, \ + size, len); \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x80, vt->wwid, wlen); \ + assert_correct_wwid("test_vpd80_" #size "_" #len "_" #wlen, \ + exp_len, ret, 0, 0, false, \ + input, vt->wwid); \ + free(input); \ +} + +/* VPD 80 */ +/* Tests without trailing whitespace: 21 WWID bytes required */ +make_test_vpd80(20, 20, 30); +make_test_vpd80(20, 20, 21); +make_test_vpd80(20, 20, 20); +make_test_vpd80(20, 20, 10); + +/* Tests with 4 byte trailing whitespace: 21 WWID bytes required */ +make_test_vpd80(24, 24, 30); +make_test_vpd80(24, 24, 25); +make_test_vpd80(24, 24, 24); +make_test_vpd80(24, 24, 21); +make_test_vpd80(24, 24, 20); + +/* Tests with 4 byte leading whitespace: 17 WWID bytes required */ +make_test_vpd80(20, 16, 30); +make_test_vpd80(20, 16, 17); +make_test_vpd80(20, 16, 16); + +/* Tests with 4 byte leading whitespace: 21 WWID bytes required */ +make_test_vpd80(24, 20, 21); +make_test_vpd80(24, 20, 20); + +/* Tests with leading and trailing whitespace: 21 WWID bytes required */ +make_test_vpd80(30, 24, 30); +make_test_vpd80(30, 24, 21); +make_test_vpd80(30, 24, 20); + +/* VPD 83, T10 vendor ID */ +make_test_vpd_vnd(40, 40); +make_test_vpd_vnd(40, 30); +make_test_vpd_vnd(30, 20); +make_test_vpd_vnd(29, 30); +make_test_vpd_vnd(28, 30); +make_test_vpd_vnd(27, 30); /* space at end */ +make_test_vpd_vnd(26, 30); /* space at end */ +make_test_vpd_vnd(25, 30); +make_test_vpd_vnd(24, 30); /* space at end */ +make_test_vpd_vnd(23, 30); +make_test_vpd_vnd(24, 20); +make_test_vpd_vnd(23, 20); +make_test_vpd_vnd(22, 20); +make_test_vpd_vnd(21, 20); +make_test_vpd_vnd(20, 20); +make_test_vpd_vnd(19, 20); +make_test_vpd_vnd(20, 10); +make_test_vpd_vnd(10, 10); + +/* EUI64 tests */ +/* 64bit, WWID size: 18 */ +make_test_vpd_eui(8, 32); +make_test_vpd_eui(8, 18); +make_test_vpd_eui(8, 17); +make_test_vpd_eui(8, 16); +make_test_vpd_eui(8, 10); + +/* 96 bit, WWID size: 26 */ +make_test_vpd_eui(12, 32); +make_test_vpd_eui(12, 26); +make_test_vpd_eui(12, 25); +make_test_vpd_eui(12, 20); +make_test_vpd_eui(12, 10); + +/* 128 bit, WWID size: 34 */ +make_test_vpd_eui(16, 40); +make_test_vpd_eui(16, 34); +make_test_vpd_eui(16, 33); +make_test_vpd_eui(16, 20); + +/* NAA IEEE registered extended (36), WWID size: 34 */ +make_test_vpd_naa(6, 40); +make_test_vpd_naa(6, 34); +make_test_vpd_naa(6, 33); +make_test_vpd_naa(6, 32); +make_test_vpd_naa(6, 20); + +/* NAA IEEE registered (35), WWID size: 18 */ +make_test_vpd_naa(5, 20); +make_test_vpd_naa(5, 18); +make_test_vpd_naa(5, 17); +make_test_vpd_naa(5, 16); + +/* NAA local (33), WWID size: 18 */ +make_test_vpd_naa(3, 20); +make_test_vpd_naa(3, 18); +make_test_vpd_naa(3, 17); +make_test_vpd_naa(3, 16); + +/* NAA IEEE extended (32), WWID size: 18 */ +make_test_vpd_naa(2, 20); +make_test_vpd_naa(2, 18); +make_test_vpd_naa(2, 17); +make_test_vpd_naa(2, 16); + +/* SCSI Name string: EUI64, WWID size: 17 */ +make_test_vpd_str(0, 20, 18) +make_test_vpd_str(0, 20, 17) +make_test_vpd_str(0, 20, 16) +make_test_vpd_str(0, 20, 15) + +/* SCSI Name string: EUI64, zero padded, WWID size: 16 */ +make_test_vpd_str(16, 20, 18) +make_test_vpd_str(16, 20, 17) +make_test_vpd_str(16, 20, 16) +make_test_vpd_str(16, 20, 15) + +/* SCSI Name string: NAA, WWID size: 17 */ +make_test_vpd_str(1, 20, 18) +make_test_vpd_str(1, 20, 17) +make_test_vpd_str(1, 20, 16) +make_test_vpd_str(1, 20, 15) + +/* SCSI Name string: NAA, zero padded, WWID size: 16 */ +make_test_vpd_str(17, 20, 18) +make_test_vpd_str(17, 20, 17) +make_test_vpd_str(17, 20, 16) +make_test_vpd_str(17, 20, 15) + +/* SCSI Name string: IQN, WWID size: 17 */ +make_test_vpd_str(2, 20, 18) +make_test_vpd_str(2, 20, 17) +make_test_vpd_str(2, 20, 16) +make_test_vpd_str(2, 20, 15) + +/* SCSI Name string: IQN, zero padded, WWID size: 16 */ +make_test_vpd_str(18, 20, 18) +make_test_vpd_str(18, 20, 17) +make_test_vpd_str(18, 20, 16) +make_test_vpd_str(18, 20, 15) + +static int test_vpd(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_vpd80_20_20_30), + cmocka_unit_test(test_vpd80_20_20_21), + cmocka_unit_test(test_vpd80_20_20_20), + cmocka_unit_test(test_vpd80_20_20_10), + cmocka_unit_test(test_vpd80_24_24_30), + cmocka_unit_test(test_vpd80_24_24_25), + cmocka_unit_test(test_vpd80_24_24_24), + cmocka_unit_test(test_vpd80_24_24_21), + cmocka_unit_test(test_vpd80_24_24_20), + cmocka_unit_test(test_vpd80_20_16_30), + cmocka_unit_test(test_vpd80_20_16_17), + cmocka_unit_test(test_vpd80_20_16_16), + cmocka_unit_test(test_vpd80_24_20_21), + cmocka_unit_test(test_vpd80_24_20_20), + cmocka_unit_test(test_vpd80_30_24_30), + cmocka_unit_test(test_vpd80_30_24_21), + cmocka_unit_test(test_vpd80_30_24_20), + cmocka_unit_test(test_vpd_vnd_40_40), + cmocka_unit_test(test_vpd_vnd_40_30), + cmocka_unit_test(test_vpd_vnd_30_20), + cmocka_unit_test(test_vpd_vnd_29_30), + cmocka_unit_test(test_vpd_vnd_28_30), + cmocka_unit_test(test_vpd_vnd_27_30), + cmocka_unit_test(test_vpd_vnd_26_30), + cmocka_unit_test(test_vpd_vnd_25_30), + cmocka_unit_test(test_vpd_vnd_24_30), + cmocka_unit_test(test_vpd_vnd_23_30), + cmocka_unit_test(test_vpd_vnd_24_20), + cmocka_unit_test(test_vpd_vnd_23_20), + cmocka_unit_test(test_vpd_vnd_22_20), + cmocka_unit_test(test_vpd_vnd_21_20), + cmocka_unit_test(test_vpd_vnd_20_20), + cmocka_unit_test(test_vpd_vnd_19_20), + cmocka_unit_test(test_vpd_vnd_20_10), + cmocka_unit_test(test_vpd_vnd_10_10), + cmocka_unit_test(test_vpd_eui_8_32), + cmocka_unit_test(test_vpd_eui_8_18), + cmocka_unit_test(test_vpd_eui_8_17), + cmocka_unit_test(test_vpd_eui_8_16), + cmocka_unit_test(test_vpd_eui_8_10), + cmocka_unit_test(test_vpd_eui_12_32), + cmocka_unit_test(test_vpd_eui_12_26), + cmocka_unit_test(test_vpd_eui_12_25), + cmocka_unit_test(test_vpd_eui_12_20), + cmocka_unit_test(test_vpd_eui_12_10), + cmocka_unit_test(test_vpd_eui_16_40), + cmocka_unit_test(test_vpd_eui_16_34), + cmocka_unit_test(test_vpd_eui_16_33), + cmocka_unit_test(test_vpd_eui_16_20), + cmocka_unit_test(test_vpd_naa_6_40), + cmocka_unit_test(test_vpd_naa_6_34), + cmocka_unit_test(test_vpd_naa_6_33), + cmocka_unit_test(test_vpd_naa_6_32), + cmocka_unit_test(test_vpd_naa_6_20), + cmocka_unit_test(test_vpd_naa_5_20), + cmocka_unit_test(test_vpd_naa_5_18), + cmocka_unit_test(test_vpd_naa_5_17), + cmocka_unit_test(test_vpd_naa_5_16), + cmocka_unit_test(test_vpd_naa_3_20), + cmocka_unit_test(test_vpd_naa_3_18), + cmocka_unit_test(test_vpd_naa_3_17), + cmocka_unit_test(test_vpd_naa_3_16), + cmocka_unit_test(test_vpd_naa_2_20), + cmocka_unit_test(test_vpd_naa_2_18), + cmocka_unit_test(test_vpd_naa_2_17), + cmocka_unit_test(test_vpd_naa_2_16), + cmocka_unit_test(test_vpd_str_0_20_18), + cmocka_unit_test(test_vpd_str_0_20_17), + cmocka_unit_test(test_vpd_str_0_20_16), + cmocka_unit_test(test_vpd_str_0_20_15), + cmocka_unit_test(test_vpd_str_16_20_18), + cmocka_unit_test(test_vpd_str_16_20_17), + cmocka_unit_test(test_vpd_str_16_20_16), + cmocka_unit_test(test_vpd_str_16_20_15), + cmocka_unit_test(test_vpd_str_1_20_18), + cmocka_unit_test(test_vpd_str_1_20_17), + cmocka_unit_test(test_vpd_str_1_20_16), + cmocka_unit_test(test_vpd_str_1_20_15), + cmocka_unit_test(test_vpd_str_17_20_18), + cmocka_unit_test(test_vpd_str_17_20_17), + cmocka_unit_test(test_vpd_str_17_20_16), + cmocka_unit_test(test_vpd_str_17_20_15), + cmocka_unit_test(test_vpd_str_2_20_18), + cmocka_unit_test(test_vpd_str_2_20_17), + cmocka_unit_test(test_vpd_str_2_20_16), + cmocka_unit_test(test_vpd_str_2_20_15), + cmocka_unit_test(test_vpd_str_18_20_18), + cmocka_unit_test(test_vpd_str_18_20_17), + cmocka_unit_test(test_vpd_str_18_20_16), + cmocka_unit_test(test_vpd_str_18_20_15), + }; + return cmocka_run_group_tests(tests, setup, teardown); +} + +int main(void) +{ + int ret = 0; + + ret += test_vpd(); + return ret; +} From patchwork Mon Jun 24 09:27:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012753 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 E0053186E for ; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D21EB2873B for ; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6C0F28867; Mon, 24 Jun 2019 09:30:40 +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 770FA285C8 for ; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 357CE46202; Mon, 24 Jun 2019 09:30:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0759F60619; Mon, 24 Jun 2019 09:30:39 +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 CD993206D7; Mon, 24 Jun 2019 09:30:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TLb5005097 for ; Mon, 24 Jun 2019 05:29:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id E469F60BFB; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD01660BF7; Mon, 24 Jun 2019 09:29:19 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 556D830BBE75; Mon, 24 Jun 2019 09:29:11 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:06 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:40 +0200 Message-Id: <20190624092756.7769-16-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 24 Jun 2019 09:29:11 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 14/30] libmultipath: fix parsing of VPD 83 type 1 (T10 vendor ID) 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:30:39 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In the buffer overflow case, the code would set p_len = out_len - len - 2, then len = len + plen = out_len - 2, and check if len >= out_len - 1, which is never the case. Rather, set p_len = out_len - len -1, and check the length again before appending the underscore. Fixes: 18176202e75c "Read wwid from sysfs vpg_pg83 attribute" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 407e64a0..f360e306 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1065,8 +1065,11 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, p = vpd; while ((p = memchr(vpd, ' ', vpd_len))) { p_len = p - vpd; - if (len + p_len > out_len - 1) - p_len = out_len - len - 2; + if (len + p_len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required", + __func__, len + p_len, out_len); + p_len = out_len - len - 1; + } memcpy(out + len, vpd, p_len); len += p_len; if (len >= out_len - 1) { @@ -1075,6 +1078,10 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, } out[len] = '_'; len ++; + if (len >= out_len - 1) { + out[len] = '\0'; + break; + } vpd = p; vpd_len -= p_len; while (vpd && *vpd == ' ') { From patchwork Mon Jun 24 09:27:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012763 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 A58F876 for ; Mon, 24 Jun 2019 09:30:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95AB2285C8 for ; Mon, 24 Jun 2019 09:30:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89F3428841; Mon, 24 Jun 2019 09:30:56 +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 3EA83285C8 for ; Mon, 24 Jun 2019 09:30:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74CEF307D928; Mon, 24 Jun 2019 09:30:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D69D5B68A; Mon, 24 Jun 2019 09:30:55 +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 261FB206D9; Mon, 24 Jun 2019 09:30:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TMQe005126 for ; Mon, 24 Jun 2019 05:29:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 77E111001B19; Mon, 24 Jun 2019 09:29:22 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B8521001B07; Mon, 24 Jun 2019 09:29:20 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B784B300146C; Mon, 24 Jun 2019 09:29:11 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:08 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:41 +0200 Message-Id: <20190624092756.7769-17-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:12 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 15/30] libmultipath: Fix buffer overflow in parse_vpd_pg80() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 24 Jun 2019 09:30:55 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP We set out[len] = '\0' later, thus we should set len to no more then out_len - 1. Fixes: 756ef73b7197 "Separate out vpd parsing functions" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index f360e306..89c4d2ad 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -913,7 +913,7 @@ parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) if (len >= out_len) { condlog(2, "vpd pg80 overflow, %d/%d bytes required", len, (int)out_len); - len = out_len; + len = out_len - 1; } if (len > 0) { memcpy(out, in + 4, len); From patchwork Mon Jun 24 09:27:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012749 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 E59E576 for ; Mon, 24 Jun 2019 09:30:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5E0B2873B for ; Mon, 24 Jun 2019 09:30:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA4D428867; Mon, 24 Jun 2019 09:30:36 +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 76EE12873B for ; Mon, 24 Jun 2019 09:30:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D14A30842D1; Mon, 24 Jun 2019 09:30:35 +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 5AABF60BF7; Mon, 24 Jun 2019 09:30:35 +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 00FFF1806B1D; Mon, 24 Jun 2019 09:30:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TSDO005301 for ; Mon, 24 Jun 2019 05:29:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 587645C22F; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5160B5C1B5; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1E908AE49; Mon, 24 Jun 2019 09:29:20 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:10 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:42 +0200 Message-Id: <20190624092756.7769-18-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 16/30] libmultipath: fix possible WWID overflow in parse_vpd_pg83() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:30:36 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP We have to check the remaining length before printing to the output buffer, not afterwards. Fixes: 18176202e75c "Read wwid from sysfs vpg_pg83 attribute" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 89c4d2ad..eed35284 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1012,11 +1012,9 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, int i; len = sprintf(out, "%d", vpd_type); - for (i = 0; i < vpd_len; i++) { + for (i = 0; i < vpd_len && len < out_len - 2; i++) { len += sprintf(out + len, "%02x", vpd[i]); - if (len >= out_len) - break; } } else if (vpd_type == 0x8) { if (!memcmp("eui.", vpd, 4)) { @@ -1024,27 +1022,19 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, len = 1; vpd += 4; vpd_len -= 4; - for (i = 0; i < vpd_len; i++) { + for (i = 0; i < vpd_len && len < out_len - 1; i++) { len += sprintf(out + len, "%c", tolower(vpd[i])); - if (len >= out_len) - break; } - len = vpd_len + 1; - out[len] = '\0'; } else if (!memcmp("naa.", vpd, 4)) { out[0] = '3'; len = 1; vpd += 4; vpd_len -= 4; - for (i = 0; i < vpd_len; i++) { + for (i = 0; i < vpd_len && len < out_len - 1; i++) { len += sprintf(out + len, "%c", tolower(vpd[i])); - if (len >= out_len) - break; } - len = vpd_len + 1; - out[len] = '\0'; } else { out[0] = '8'; len = 1; From patchwork Mon Jun 24 09:27:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012727 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 534F9112C for ; Mon, 24 Jun 2019 09:30:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42ED128AF5 for ; Mon, 24 Jun 2019 09:30:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35A9528B5D; Mon, 24 Jun 2019 09:30:10 +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 DC29428AF5 for ; Mon, 24 Jun 2019 09:30:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FEC213A4D; Mon, 24 Jun 2019 09:30:08 +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 24A8660928; Mon, 24 Jun 2019 09:30:08 +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 C0BCB1806B1D; Mon, 24 Jun 2019 09:30:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TSmf005307 for ; Mon, 24 Jun 2019 05:29:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 767331001B05; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A5321001B04; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F23323087944; Mon, 24 Jun 2019 09:29:20 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:12 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:43 +0200 Message-Id: <20190624092756.7769-19-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 17/30] libmultipath: fix another WWID overflow in parse_vpd_pg83() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 24 Jun 2019 09:30:09 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This one is an obvious typo. Fixes: 18176202e75c "Read wwid from sysfs vpg_pg83 attribute" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index eed35284..10306b22 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1040,7 +1040,7 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, len = 1; vpd += 4; vpd_len -= 4; - if (vpd_len > out_len + 2) + if (vpd_len > out_len - 2) vpd_len = out_len - 2; memcpy(out, vpd, vpd_len); len = vpd_len + 1; From patchwork Mon Jun 24 09:27:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012765 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 B47A976 for ; Mon, 24 Jun 2019 09:31:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A414C28AF5 for ; Mon, 24 Jun 2019 09:31:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9601D28B4C; Mon, 24 Jun 2019 09:31:00 +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 4ACBE28AF5 for ; Mon, 24 Jun 2019 09:31:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73C7881DFC; Mon, 24 Jun 2019 09:30:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AD7F5D9C5; Mon, 24 Jun 2019 09:30:59 +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 30621206D8; Mon, 24 Jun 2019 09:30:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TSr7005319 for ; Mon, 24 Jun 2019 05:29:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id A553B5C221; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9EA995C1B5; Mon, 24 Jun 2019 09:29:28 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E73722388D; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:13 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:44 +0200 Message-Id: <20190624092756.7769-20-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 18/30] libmultipath: fix parsing of SCSI name string, iqn format 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 24 Jun 2019 09:30:59 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Do not overwrite the leading '8'. Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 10306b22..45c2931e 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1037,12 +1037,11 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, } } else { out[0] = '8'; - len = 1; vpd += 4; vpd_len -= 4; if (vpd_len > out_len - 2) vpd_len = out_len - 2; - memcpy(out, vpd, vpd_len); + memcpy(out + 1, vpd, vpd_len); len = vpd_len + 1; out[len] = '\0'; } From patchwork Mon Jun 24 09:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012743 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 D66D276 for ; Mon, 24 Jun 2019 09:30:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9F25285C8 for ; Mon, 24 Jun 2019 09:30:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB5C628841; Mon, 24 Jun 2019 09:30:29 +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 4D49C285C8 for ; Mon, 24 Jun 2019 09:30:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87ACDC058CC0; Mon, 24 Jun 2019 09:30:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 691D960BFB; Mon, 24 Jun 2019 09:30:28 +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 2E626206D6; Mon, 24 Jun 2019 09:30:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TPqK005219 for ; Mon, 24 Jun 2019 05:29:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 92D1019C7F; Mon, 24 Jun 2019 09:29:25 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8847219C69; Mon, 24 Jun 2019 09:29:25 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6214D30C252E; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:15 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:45 +0200 Message-Id: <20190624092756.7769-21-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 19/30] libmultipath: add consistent WWID overflow logging in parse_vpd_pg83 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 24 Jun 2019 09:30:28 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 49 ++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 45c2931e..e484ec8d 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1011,38 +1011,53 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, if (vpd_type == 0x2 || vpd_type == 0x3) { int i; + assert(out_len >= 2); len = sprintf(out, "%d", vpd_type); - for (i = 0; i < vpd_len && len < out_len - 2; i++) { + if (2 * vpd_len >= out_len - len) { + condlog(1, "%s: WWID overflow, type %d, %d/%lu bytes required", + __func__, vpd_type, + 2 * vpd_len + len + 1, out_len); + vpd_len = (out_len - len - 1) / 2; + } + for (i = 0; i < vpd_len; i++) len += sprintf(out + len, "%02x", vpd[i]); - } } else if (vpd_type == 0x8) { if (!memcmp("eui.", vpd, 4)) { out[0] = '2'; - len = 1; vpd += 4; - vpd_len -= 4; - for (i = 0; i < vpd_len && len < out_len - 1; i++) { - len += sprintf(out + len, "%c", - tolower(vpd[i])); + len = vpd_len - 4; + if (len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", + __func__, out[0], len + 1, out_len); + len = out_len - 1; } + for (i = 0; i < len; ++i) + out[1 + i] = tolower(vpd[i]); + /* designator should be 0-terminated, but let's make sure */ + out[len] = '\0'; } else if (!memcmp("naa.", vpd, 4)) { out[0] = '3'; - len = 1; vpd += 4; - vpd_len -= 4; - for (i = 0; i < vpd_len && len < out_len - 1; i++) { - len += sprintf(out + len, "%c", - tolower(vpd[i])); + len = vpd_len - 4; + if (len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", + __func__, out[0], len + 1, out_len); + len = out_len - 1; } + for (i = 0; i < len; ++i) + out[1 + i] = tolower(vpd[i]); + out[len] = '\0'; } else { out[0] = '8'; vpd += 4; - vpd_len -= 4; - if (vpd_len > out_len - 2) - vpd_len = out_len - 2; - memcpy(out + 1, vpd, vpd_len); - len = vpd_len + 1; + len = vpd_len - 4; + if (len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", + __func__, out[0], len + 1, out_len); + len = out_len - 1; + } + memcpy(out + 1, vpd, len); out[len] = '\0'; } } else if (vpd_type == 0x1) { From patchwork Mon Jun 24 09:27:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012735 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 4E3E0112C for ; Mon, 24 Jun 2019 09:30:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E83D28AF5 for ; Mon, 24 Jun 2019 09:30:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32E4728B5B; Mon, 24 Jun 2019 09:30:19 +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 CC0BC28AF5 for ; Mon, 24 Jun 2019 09:30:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCF70C04BE32; Mon, 24 Jun 2019 09:30:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BA8EB5D9C5; Mon, 24 Jun 2019 09:30:17 +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 7BE59206D5; Mon, 24 Jun 2019 09:30:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TUnT005359 for ; Mon, 24 Jun 2019 05:29:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id F369E1001B07; Mon, 24 Jun 2019 09:29:29 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAC091001B04; Mon, 24 Jun 2019 09:29:29 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90F617F7C0; Mon, 24 Jun 2019 09:29:21 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:17 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:46 +0200 Message-Id: <20190624092756.7769-22-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 24 Jun 2019 09:29:21 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 20/30] libmultipath: parse_vpd_pg83: common code for SCSI string parsing 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:30:18 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The three cases for eui, naa, and iqn parsing share almost all code. Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 54 ++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index e484ec8d..32e3f9d3 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1023,43 +1023,31 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, len += sprintf(out + len, "%02x", vpd[i]); } else if (vpd_type == 0x8) { - if (!memcmp("eui.", vpd, 4)) { + if (!memcmp("eui.", vpd, 4)) out[0] = '2'; - vpd += 4; - len = vpd_len - 4; - if (len > out_len - 1) { - condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", - __func__, out[0], len + 1, out_len); - len = out_len - 1; - } - for (i = 0; i < len; ++i) - out[1 + i] = tolower(vpd[i]); - /* designator should be 0-terminated, but let's make sure */ - out[len] = '\0'; - } else if (!memcmp("naa.", vpd, 4)) { + else if (!memcmp("naa.", vpd, 4)) out[0] = '3'; - vpd += 4; - len = vpd_len - 4; - if (len > out_len - 1) { - condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", - __func__, out[0], len + 1, out_len); - len = out_len - 1; - } - for (i = 0; i < len; ++i) - out[1 + i] = tolower(vpd[i]); - out[len] = '\0'; - } else { + else out[0] = '8'; - vpd += 4; - len = vpd_len - 4; - if (len > out_len - 1) { - condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", - __func__, out[0], len + 1, out_len); - len = out_len - 1; - } - memcpy(out + 1, vpd, len); - out[len] = '\0'; + + vpd += 4; + len = vpd_len - 4; + if (len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", + __func__, out[0], len + 1, out_len); + len = out_len - 1; } + + if (out[0] == '8') + for (i = 0; i < len; ++i) + out[1 + i] = vpd[i]; + else + for (i = 0; i < len; ++i) + out[1 + i] = tolower(vpd[i]); + + /* designator should be 0-terminated, but let's make sure */ + out[len] = '\0'; + } else if (vpd_type == 0x1) { const unsigned char *p; int p_len; From patchwork Mon Jun 24 09:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012755 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 D238976 for ; Mon, 24 Jun 2019 09:30:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C048B285C8 for ; Mon, 24 Jun 2019 09:30:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC90428841; Mon, 24 Jun 2019 09:30:42 +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 5AE2A285C8 for ; Mon, 24 Jun 2019 09:30:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23770C0586C4; Mon, 24 Jun 2019 09:30:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E804160A9B; Mon, 24 Jun 2019 09:30:40 +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 9970F206D7; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TXar005450 for ; Mon, 24 Jun 2019 05:29:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id F24056014E; Mon, 24 Jun 2019 09:29:32 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6ACB60143; Mon, 24 Jun 2019 09:29:32 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D832081F0D; Mon, 24 Jun 2019 09:29:30 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:19 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:47 +0200 Message-Id: <20190624092756.7769-23-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 21/30] libmultipath: allow zero-padded SCSI names in parse_vpd_pg83() 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 09:30:42 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The spec says that SCSI name strings designator length must be a multiple of 4, and that strings must be zero-terminated and zero-padded. Fix the returned string length if the VPD input ends with multiple 0-bytes. Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 32e3f9d3..3558e559 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1032,6 +1032,8 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, vpd += 4; len = vpd_len - 4; + while (len > 2 && vpd[len - 2] == '\0') + --len; if (len > out_len - 1) { condlog(1, "%s: WWID overflow, type 8/%c, %d/%lu bytes required", __func__, out[0], len + 1, out_len); From patchwork Mon Jun 24 09:27:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012769 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 1AF8376 for ; Mon, 24 Jun 2019 09:31:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0982C28AF5 for ; Mon, 24 Jun 2019 09:31:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F21E528B4C; Mon, 24 Jun 2019 09:31:21 +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 9B45028AF5 for ; Mon, 24 Jun 2019 09:31:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF5B7307D874; Mon, 24 Jun 2019 09:31:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E3CE60C64; Mon, 24 Jun 2019 09:31:17 +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 687EF206D3; Mon, 24 Jun 2019 09:31:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TfRk005655 for ; Mon, 24 Jun 2019 05:29:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB63060C4C; Mon, 24 Jun 2019 09:29:41 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E92560BF7; Mon, 24 Jun 2019 09:29:39 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13CE0C058CC0; Mon, 24 Jun 2019 09:29:31 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:21 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:48 +0200 Message-Id: <20190624092756.7769-24-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 22/30] libmultipath: fix parsing of non-space-terminated T10 ID 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 24 Jun 2019 09:31:21 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If the T10 vendor specific ID doesn't end with spaces, the last part won't be parsed. Fix it. Fixes: 18176202e75c "Read wwid from sysfs vpg_pg83 attribute" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 3558e559..efcea468 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1083,6 +1083,17 @@ parse_vpd_pg83(const unsigned char *in, size_t in_len, vpd_len --; } } + p_len = vpd_len; + if (p_len > 0 && len < out_len - 1) { + if (len + p_len > out_len - 1) { + condlog(1, "%s: WWID overflow, type 1, %d/%lu bytes required", + __func__, len + p_len + 1, out_len); + p_len = out_len - len - 1; + } + memcpy(out + len, vpd, p_len); + len += p_len; + out[len] = '\0'; + } if (len > 1 && out[len - 1] == '_') { out[len - 1] = '\0'; len--; From patchwork Mon Jun 24 09:27:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012767 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 CD290112C for ; Mon, 24 Jun 2019 09:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7B628AF5 for ; Mon, 24 Jun 2019 09:31:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0A9828B4C; Mon, 24 Jun 2019 09:31:07 +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 59F2D28AF5 for ; Mon, 24 Jun 2019 09:31:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97C14307D923; Mon, 24 Jun 2019 09:31:06 +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 6E09C6012D; Mon, 24 Jun 2019 09:31:06 +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 5E1611806B1C; Mon, 24 Jun 2019 09:31:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TeFj005629 for ; Mon, 24 Jun 2019 05:29:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8A015C22E; Mon, 24 Jun 2019 09:29:40 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A80F65C1B5; Mon, 24 Jun 2019 09:29:38 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 430A8308FBA9; Mon, 24 Jun 2019 09:29:31 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:22 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:49 +0200 Message-Id: <20190624092756.7769-25-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 23/30] libmultipath: parse_vpd_pg80: fix overflow output 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 24 Jun 2019 09:31:07 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP "vpd pg80 overflow, 20/20 bytes required" looks weird. Make it clear that actually 21 bytes are required in this case. Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index efcea468..931a676f 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -912,7 +912,7 @@ parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) if (len >= out_len) { condlog(2, "vpd pg80 overflow, %d/%d bytes required", - len, (int)out_len); + len + 1, (int)out_len); len = out_len - 1; } if (len > 0) { From patchwork Mon Jun 24 09:27:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012739 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 D3976112C for ; Mon, 24 Jun 2019 09:30:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C397F28B4C for ; Mon, 24 Jun 2019 09:30:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B82BC28B70; Mon, 24 Jun 2019 09:30:25 +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 53B6B28B4C for ; Mon, 24 Jun 2019 09:30:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12E1181DE0; Mon, 24 Jun 2019 09:30:24 +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 D1A6F60605; Mon, 24 Jun 2019 09:30:23 +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 85FB91806B1D; Mon, 24 Jun 2019 09:30:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9Tgk6005679 for ; Mon, 24 Jun 2019 05:29:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 63C465C225; Mon, 24 Jun 2019 09:29:42 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C59B5C1B5; Mon, 24 Jun 2019 09:29:42 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 728AA87632; Mon, 24 Jun 2019 09:29:31 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:24 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:50 +0200 Message-Id: <20190624092756.7769-26-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 24 Jun 2019 09:29:31 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 24/30] libmultipath: parse_vpd_pg80: fix whitespace handling 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 24 Jun 2019 09:30:24 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP According to the SPC spec, the unit serial number is right-aligned ASCII. Thus leading whitespace must be skipped. Moreover, trailing whitespace should be discarded before doing the length check. Fixes: 756ef73b7197 "Separate out vpd parsing functions" Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 931a676f..b10afdef 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -907,9 +907,18 @@ get_geometry(struct path *pp) static int parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) { - char *p = NULL; int len = get_unaligned_be16(&in[2]); + /* + * Strip leading and trailing whitespace + */ + while (len > 0 && in[len + 3] == ' ') + --len; + while (len > 0 && in[4] == ' ') { + ++in; + --len; + } + if (len >= out_len) { condlog(2, "vpd pg80 overflow, %d/%d bytes required", len + 1, (int)out_len); @@ -919,15 +928,6 @@ parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len) memcpy(out, in + 4, len); out[len] = '\0'; } - /* - * Strip trailing whitspaces - */ - p = out + len - 1; - while (p > out && *p == ' ') { - *p = '\0'; - p--; - len --; - } return len; } From patchwork Mon Jun 24 09:27:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012773 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 DAEEE112C for ; Mon, 24 Jun 2019 09:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA22828B5B for ; Mon, 24 Jun 2019 09:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B958928B4C; Mon, 24 Jun 2019 09:31:30 +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 5743128B4C for ; Mon, 24 Jun 2019 09:31:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E532B307D931; Mon, 24 Jun 2019 09:31:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2C545D97C; Mon, 24 Jun 2019 09:31:28 +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 90651206D5; Mon, 24 Jun 2019 09:31:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TgZ1005689 for ; Mon, 24 Jun 2019 05:29:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 89ACD1001B29; Mon, 24 Jun 2019 09:29:42 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B93E1001B07; Mon, 24 Jun 2019 09:29:40 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2D60368E6; Mon, 24 Jun 2019 09:29:31 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:26 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:51 +0200 Message-Id: <20190624092756.7769-27-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 24 Jun 2019 09:29:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 24 Jun 2019 09:29:32 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 25/30] libmultipath: get_uid: straighten the fallback logic 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 24 Jun 2019 09:31:29 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The code had two distinct fallback paths, with non-obvious logic. Try to straighten it out. The "allow_fallback" logic from ffaf9477d115 "multipathd: Don't use fallback code after getting wwid" should only apply in the case where get_udev_uid() failed, not if it wasn't even tried. Moreover, uid_attribute is hardly ever NULL since ffaf9477; allow the user to set it to the empty string to skip udev-based WWID determination. This is rather not meant for production, but it's useful for testing. Finally, only set "origin" to "udev" if a WWID was actually retrieved from udev. Signed-off-by: Martin Wilck --- libmultipath/discovery.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index b10afdef..d7eaee68 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1876,20 +1876,20 @@ get_uid (struct path * pp, int path_state, struct udev_device *udev, len = strlen(pp->wwid); origin = "callout"; } else { + bool udev_available = udev && pp->uid_attribute + && *pp->uid_attribute; - if (udev && pp->uid_attribute) { + if (udev_available) { len = get_udev_uid(pp, pp->uid_attribute, udev); - origin = "udev"; if (len <= 0) condlog(1, "%s: failed to get udev uid: %s", pp->dev, strerror(-len)); - - } else if (pp->bus == SYSFS_BUS_SCSI) { - len = get_vpd_uid(pp); - origin = "sysfs"; + else + origin = "udev"; } - if (len <= 0 && allow_fallback && has_uid_fallback(pp)) { + if ((!udev_available || (len <= 0 && allow_fallback)) + && has_uid_fallback(pp)) { used_fallback = 1; len = uid_fallback(pp, path_state, &origin); } From patchwork Mon Jun 24 09:27:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012771 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 94879112C for ; Mon, 24 Jun 2019 09:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 829DB28AF5 for ; Mon, 24 Jun 2019 09:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75C3C28B4C; Mon, 24 Jun 2019 09:31:27 +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 0B43228AF5 for ; Mon, 24 Jun 2019 09:31:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87FBC3078AB3; Mon, 24 Jun 2019 09:31:25 +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 CF49E60F81; Mon, 24 Jun 2019 09:31:24 +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 9DE6E1806B1A; Mon, 24 Jun 2019 09:31:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9Tfkh005657 for ; Mon, 24 Jun 2019 05:29:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id C85A519728; Mon, 24 Jun 2019 09:29:41 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6202B19C69; Mon, 24 Jun 2019 09:29:39 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D409C308404B; Mon, 24 Jun 2019 09:29:31 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:28 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:52 +0200 Message-Id: <20190624092756.7769-28-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:29:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:29:32 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 26/30] libmultipath: fix has_uid_fallback() logic 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 24 Jun 2019 09:31:26 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The idea of 061daf40 "Do not automatically fall back to vpd uid generation" applies not only to SCSI. Use the same logic for NVMe. Allow fallback in two cases: - uid_attribute has the default value for the bus in question - uid_attribute has been set to "" to disable udev-based WWID checking As uid_fallback() has only one caller, no need to check the conditions there again. Signed-off-by: Martin Wilck --- libmultipath/defaults.h | 1 + libmultipath/discovery.c | 20 +++++++++++++++----- libmultipath/hwtable.c | 2 +- tests/hwtable.c | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/libmultipath/defaults.h b/libmultipath/defaults.h index 83f89f37..decc9335 100644 --- a/libmultipath/defaults.h +++ b/libmultipath/defaults.h @@ -5,6 +5,7 @@ * and the TEMPLATE in libmultipath/hwtable.c */ #define DEFAULT_UID_ATTRIBUTE "ID_SERIAL" +#define DEFAULT_NVME_UID_ATTRIBUTE "ID_WWN" #define DEFAULT_UDEVDIR "/dev" #define DEFAULT_MULTIPATHDIR "/" LIB_STRING "/multipath" #define DEFAULT_SELECTOR "service-time 0" diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index d7eaee68..15f5cd4b 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1802,8 +1802,7 @@ static ssize_t uid_fallback(struct path *pp, int path_state, { ssize_t len = -1; - if (pp->bus == SYSFS_BUS_SCSI && - !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) { + if (pp->bus == SYSFS_BUS_SCSI) { len = get_vpd_uid(pp); *origin = "sysfs"; if (len < 0 && path_state == PATH_UP) { @@ -1833,11 +1832,22 @@ static ssize_t uid_fallback(struct path *pp, int path_state, return len; } -static int has_uid_fallback(struct path *pp) +static bool has_uid_fallback(struct path *pp) { + /* + * Falling back to direct WWID determination is dangerous + * if uid_attribute is set to something non-standard. + * Allow it only if it's either the default, or if udev + * has been disabled by setting 'uid_attribute ""'. + */ + if (!pp->uid_attribute) + return false; return ((pp->bus == SYSFS_BUS_SCSI && - !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) || - pp->bus == SYSFS_BUS_NVME); + (!strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE) || + !strcmp(pp->uid_attribute, ""))) || + (pp->bus == SYSFS_BUS_NVME && + (!strcmp(pp->uid_attribute, DEFAULT_NVME_UID_ATTRIBUTE) || + !strcmp(pp->uid_attribute, "")))); } int diff --git a/libmultipath/hwtable.c b/libmultipath/hwtable.c index 1d964333..46caaf91 100644 --- a/libmultipath/hwtable.c +++ b/libmultipath/hwtable.c @@ -88,7 +88,7 @@ static struct hwentry default_hw[] = { /* Generic NVMe */ .vendor = "NVME", .product = ".*", - .uid_attribute = "ID_WWN", + .uid_attribute = DEFAULT_NVME_UID_ATTRIBUTE, .checker_name = NONE, .retain_hwhandler = RETAIN_HWHANDLER_OFF, }, diff --git a/tests/hwtable.c b/tests/hwtable.c index f436f52d..977a5663 100644 --- a/tests/hwtable.c +++ b/tests/hwtable.c @@ -571,7 +571,7 @@ static void test_internal_nvme(const struct hwt_state *hwt) mp = mock_multipath(pp); assert_ptr_not_equal(mp, NULL); TEST_PROP(checker_name(&pp->checker), NONE); - TEST_PROP(pp->uid_attribute, "ID_WWN"); + TEST_PROP(pp->uid_attribute, DEFAULT_NVME_UID_ATTRIBUTE); assert_int_equal(mp->pgpolicy, DEFAULT_PGPOLICY); assert_int_equal(mp->no_path_retry, DEFAULT_NO_PATH_RETRY); assert_int_equal(mp->retain_hwhandler, RETAIN_HWHANDLER_OFF); From patchwork Mon Jun 24 09:27:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012747 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 F12B1112C for ; Mon, 24 Jun 2019 09:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD70D285C8 for ; Mon, 24 Jun 2019 09:30:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D040928841; Mon, 24 Jun 2019 09:30:34 +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 193B2285C8 for ; Mon, 24 Jun 2019 09:30:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FBDE821C1; Mon, 24 Jun 2019 09:30:33 +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 DBDAB60BFC; Mon, 24 Jun 2019 09:30:32 +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 923DC1806B1F; Mon, 24 Jun 2019 09:30:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TnuA005878 for ; Mon, 24 Jun 2019 05:29:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC5751001B29; Mon, 24 Jun 2019 09:29:49 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2C751001B05; Mon, 24 Jun 2019 09:29:49 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2A2A3082E63; Mon, 24 Jun 2019 09:29:40 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:30 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:53 +0200 Message-Id: <20190624092756.7769-29-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Tang Junhui , Martin Wilck Subject: [dm-devel] [PATCH v2 27/30] libmultipath: fix memory leak with "uid_attrs" config option 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 24 Jun 2019 09:30:33 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP pp->uid_attribute is normally just a pointer to memory that belongs to the configuration. But if "uid_attrs" is used, it's a pointer to strdup()d memory returned by parse_uid_attribute_by_attrs(). Consequently, this strdup()'d memory is never freed. Fix this by splitting the uid_attrs string when the configuration is read, and using just a refererence to this memory in pp->uid_attribute. A side effect is that this makes the code more efficient in both memory and CPU terms. This requires a change for the uevents test, as uid_attrs must now be set up differently. Cc: Tang Junhui Signed-off-by: Martin Wilck --- libmultipath/config.c | 51 +++++++++++++++++++++++++++++++++++++++--- libmultipath/config.h | 6 ++++- libmultipath/dict.c | 36 ++++++++++++++++++++++++++--- libmultipath/propsel.c | 4 ++-- libmultipath/uevent.c | 5 ++--- libmultipath/util.c | 42 ---------------------------------- libmultipath/util.h | 1 - tests/globals.c | 1 - tests/uevent.c | 9 ++++++++ 9 files changed, 99 insertions(+), 56 deletions(-) diff --git a/libmultipath/config.c b/libmultipath/config.c index 141f092b..20e3b8bf 100644 --- a/libmultipath/config.c +++ b/libmultipath/config.c @@ -585,8 +585,7 @@ free_config (struct config * conf) if (conf->uid_attribute) FREE(conf->uid_attribute); - if (conf->uid_attrs) - FREE(conf->uid_attrs); + vector_reset(&conf->uid_attrs); if (conf->getuid) FREE(conf->getuid); @@ -718,7 +717,6 @@ load_config (char * file) conf->remove_retries = 0; conf->ghost_delay = DEFAULT_GHOST_DELAY; conf->all_tg_pt = DEFAULT_ALL_TG_PT; - /* * preload default hwtable */ @@ -853,3 +851,50 @@ out: free_config(conf); return NULL; } + +char *get_uid_attribute_by_attrs(struct config *conf, + const char *path_dev) +{ + vector uid_attrs = &conf->uid_attrs; + int j; + char *att, *col; + + vector_foreach_slot(uid_attrs, att, j) { + col = strrchr(att, ':'); + if (!col) + continue; + if (!strncmp(path_dev, att, col - att)) + return col + 1; + } + return NULL; +} + +int parse_uid_attrs(char *uid_attrs, struct config *conf) +{ + vector attrs = &conf->uid_attrs; + char *uid_attr_record, *tmp; + int ret = 0, count; + + if (!uid_attrs) + return 1; + + count = get_word(uid_attrs, &uid_attr_record); + while (uid_attr_record) { + tmp = strchr(uid_attr_record, ':'); + if (!tmp) { + condlog(2, "invalid record in uid_attrs: %s", + uid_attr_record); + free(uid_attr_record); + ret = 1; + } else if (!vector_alloc_slot(attrs)) { + free(uid_attr_record); + ret = 1; + } else + vector_set_slot(attrs, uid_attr_record); + if (!count) + break; + uid_attrs += count; + count = get_word(uid_attrs, &uid_attr_record); + } + return ret; +} diff --git a/libmultipath/config.h b/libmultipath/config.h index f5bf5b1b..ff2b4e86 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -190,7 +190,7 @@ struct config { char * multipath_dir; char * selector; - char * uid_attrs; + struct _vector uid_attrs; char * uid_attribute; char * getuid; char * features; @@ -250,4 +250,8 @@ void free_config (struct config * conf); extern struct config *get_multipath_config(void); extern void put_multipath_config(void *); +int parse_uid_attrs(char *uid_attrs, struct config *conf); +char *get_uid_attribute_by_attrs(struct config *conf, + const char *path_dev); + #endif diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 96815f8a..c6eba0f6 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -374,8 +374,38 @@ declare_ovr_snprint(selector, print_str) declare_mp_handler(selector, set_str) declare_mp_snprint(selector, print_str) -declare_def_handler(uid_attrs, set_str) -declare_def_snprint(uid_attrs, print_str) +static int snprint_uid_attrs(struct config *conf, char *buff, int len, + const void *dummy) +{ + char *p = buff; + int n, j; + const char *att; + + vector_foreach_slot(&conf->uid_attrs, att, j) { + n = snprintf(p, len, "%s%s", j == 0 ? "" : " ", att); + if (n >= len) + return (p - buff) + n; + p += n; + len -= n; + } + return p - buff; +} + +static int uid_attrs_handler(struct config *conf, vector strvec) +{ + char *val; + + vector_reset(&conf->uid_attrs); + val = set_value(strvec); + if (!val) + return 1; + if (parse_uid_attrs(val, conf)) + condlog(1, "error parsing uid_attrs: \"%s\"", val); + condlog(3, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs)); + FREE(val); + return 0; +} + declare_def_handler(uid_attribute, set_str) declare_def_snprint_defstr(uid_attribute, print_str, DEFAULT_UID_ATTRIBUTE) declare_ovr_handler(uid_attribute, set_str) @@ -1618,7 +1648,7 @@ init_keywords(vector keywords) install_keyword("multipath_dir", &def_multipath_dir_handler, &snprint_def_multipath_dir); install_keyword("path_selector", &def_selector_handler, &snprint_def_selector); install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_pgpolicy); - install_keyword("uid_attrs", &def_uid_attrs_handler, &snprint_def_uid_attrs); + install_keyword("uid_attrs", &uid_attrs_handler, &snprint_uid_attrs); install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute); install_keyword("getuid_callout", &def_getuid_handler, &snprint_def_getuid); install_keyword("prio", &def_prio_name_handler, &snprint_def_prio_name); diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index e6263e9b..6af2513d 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -536,9 +536,9 @@ int select_getuid(struct config *conf, struct path *pp) { const char *origin; - pp->uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs, pp->dev); + pp->uid_attribute = get_uid_attribute_by_attrs(conf, pp->dev); if (pp->uid_attribute) { - origin = "(setting: multipath.conf defaults section)"; + origin = "(setting: multipath.conf defaults section / uid_attrs)"; goto out; } diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index f73de8cc..8f7b2ef5 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -163,13 +163,12 @@ uevent_get_wwid(struct uevent *uev) conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); - uid_attribute = parse_uid_attribute_by_attrs(conf->uid_attrs, uev->kernel); + uid_attribute = get_uid_attribute_by_attrs(conf, uev->kernel); pthread_cleanup_pop(1); val = uevent_get_env_var(uev, uid_attribute); if (val) uev->wwid = val; - FREE(uid_attribute); } bool @@ -179,7 +178,7 @@ uevent_need_merge(void) bool need_merge = false; conf = get_multipath_config(); - if (conf->uid_attrs) + if (VECTOR_SIZE(&conf->uid_attrs) > 0) need_merge = true; put_multipath_config(conf); diff --git a/libmultipath/util.c b/libmultipath/util.c index 8a4be787..28cbf4b9 100644 --- a/libmultipath/util.c +++ b/libmultipath/util.c @@ -273,48 +273,6 @@ dev_t parse_devt(const char *dev_t) return makedev(maj, min); } -char *parse_uid_attribute_by_attrs(char *uid_attrs, char *path_dev) -{ - char *uid_attribute; - char *uid_attr_record; - char *dev; - char *attr; - char *tmp; - int count; - - if(!uid_attrs || !path_dev) - return NULL; - - count = get_word(uid_attrs, &uid_attr_record); - while (uid_attr_record) { - tmp = strrchr(uid_attr_record, ':'); - if (!tmp) { - free(uid_attr_record); - if (!count) - break; - uid_attrs += count; - count = get_word(uid_attrs, &uid_attr_record); - continue; - } - dev = uid_attr_record; - attr = tmp + 1; - *tmp = '\0'; - - if(!strncmp(path_dev, dev, strlen(dev))) { - uid_attribute = STRDUP(attr); - free(uid_attr_record); - return uid_attribute; - } - - free(uid_attr_record); - if (!count) - break; - uid_attrs += count; - count = get_word(uid_attrs, &uid_attr_record); - } - return NULL; -} - void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached) { diff --git a/libmultipath/util.h b/libmultipath/util.h index 1e0d832c..693991c1 100644 --- a/libmultipath/util.h +++ b/libmultipath/util.h @@ -15,7 +15,6 @@ size_t strlcat(char *dst, const char *src, size_t size); int devt2devname (char *, int, char *); dev_t parse_devt(const char *dev_t); char *convert_dev(char *dev, int is_path_device); -char *parse_uid_attribute_by_attrs(char *uid_attrs, char *path_dev); void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached); int systemd_service_enabled(const char *dev); int get_linux_version_code(void); diff --git a/tests/globals.c b/tests/globals.c index aeb7723f..8add5eb7 100644 --- a/tests/globals.c +++ b/tests/globals.c @@ -5,7 +5,6 @@ struct udev *udev; int logsink = -1; struct config conf = { - .uid_attrs = "sd:ID_BOGUS", .verbosity = 4, }; diff --git a/tests/uevent.c b/tests/uevent.c index b0d0bfda..215d97ad 100644 --- a/tests/uevent.c +++ b/tests/uevent.c @@ -43,7 +43,11 @@ void uevent_get_wwid(struct uevent *uev); static int setup_uev(void **state) { + static char test_uid_attrs[] = + "dasd:ID_SPAM sd:ID_BOGUS nvme:ID_EGGS "; + struct uevent *uev = alloc_uevent(); + struct config *conf; if (uev == NULL) return -1; @@ -51,11 +55,16 @@ static int setup_uev(void **state) *state = uev; uev->kernel = "sdo"; uev->envp[0] = "MAJOR=" str(MAJOR); + uev->envp[1] = "ID_SPAM=nonsense"; uev->envp[1] = "ID_BOGUS=" WWID; uev->envp[2] = "MINOR=" str(MINOR); uev->envp[3] = "DM_NAME=" DM_NAME; uev->envp[4] = "DISK_RO=" str(DISK_RO); uev->envp[5] = NULL; + + conf = get_multipath_config(); + parse_uid_attrs(test_uid_attrs, conf); + put_multipath_config(conf); return 0; } From patchwork Mon Jun 24 09:27:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012775 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 295EA76 for ; Mon, 24 Jun 2019 09:31:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A0E528AF5 for ; Mon, 24 Jun 2019 09:31:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E9B428B4C; Mon, 24 Jun 2019 09:31:38 +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 AF98628AF5 for ; Mon, 24 Jun 2019 09:31:37 +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 1BCD830F1BD9; Mon, 24 Jun 2019 09:31:33 +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 EE7F65C26C; Mon, 24 Jun 2019 09:31:32 +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 ACF121806B1A; Mon, 24 Jun 2019 09:31:32 +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 x5O9ToE1005904 for ; Mon, 24 Jun 2019 05:29:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA1175D9C8; Mon, 24 Jun 2019 09:29:50 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5CBE5D9C5; Mon, 24 Jun 2019 09:29:47 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CFEC307CDD5; Mon, 24 Jun 2019 09:29:41 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:32 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:54 +0200 Message-Id: <20190624092756.7769-30-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 28/30] multipath-tools tests: add test for uid_attrs parsing 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: , 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.43]); Mon, 24 Jun 2019 09:31:37 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Martin Wilck --- tests/uevent.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/uevent.c b/tests/uevent.c index 215d97ad..f4afd9b4 100644 --- a/tests/uevent.c +++ b/tests/uevent.c @@ -95,6 +95,23 @@ static void test_ro_good(void **state) assert_int_equal(uevent_get_disk_ro(uev), DISK_RO); } +static void test_uid_attrs(void **state) +{ + /* see test_uid_attrs above */ + struct config *conf = get_multipath_config(); + vector attrs = &conf->uid_attrs; + + assert_int_equal(VECTOR_SIZE(attrs), 3); + assert_null(get_uid_attribute_by_attrs(conf, "hda")); + assert_string_equal("ID_BOGUS", + get_uid_attribute_by_attrs(conf, "sdaw")); + assert_string_equal("ID_SPAM", + get_uid_attribute_by_attrs(conf, "dasdu")); + assert_string_equal("ID_EGGS", + get_uid_attribute_by_attrs(conf, "nvme2n4")); + put_multipath_config(conf); +} + static void test_wwid(void **state) { struct uevent *uev = *state; @@ -280,6 +297,7 @@ int test_uevent_get_XXX(void) cmocka_unit_test(test_minor_good), cmocka_unit_test(test_ro_good), cmocka_unit_test(test_dm_name_good), + cmocka_unit_test(test_uid_attrs), cmocka_unit_test(test_wwid), cmocka_unit_test(test_major_bad_0), cmocka_unit_test(test_major_bad_1), From patchwork Mon Jun 24 09:27:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012751 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 5396476 for ; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44475285C8 for ; Mon, 24 Jun 2019 09:30:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38E7B28867; Mon, 24 Jun 2019 09:30:40 +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 6D52E2873B for ; Mon, 24 Jun 2019 09:30:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3AA23092651; Mon, 24 Jun 2019 09:30:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 831E660BFB; Mon, 24 Jun 2019 09:30:38 +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 566C4206D7; Mon, 24 Jun 2019 09:30:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TpdS005920 for ; Mon, 24 Jun 2019 05:29:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FA2A5B68B; Mon, 24 Jun 2019 09:29:51 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF1645B687; Mon, 24 Jun 2019 09:29:48 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E9DD3082B68; Mon, 24 Jun 2019 09:29:41 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:34 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:55 +0200 Message-Id: <20190624092756.7769-31-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 24 Jun 2019 09:29:41 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v2 29/30] libmultipath: more cautious blacklisting by missing property 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 24 Jun 2019 09:30:39 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP If a tool likk sg_inq or scsi_id fails to access a device during uevent processing, the required properties for whitelisting a device may be missing. This causes the device to be blacklisted and permanently orphaned, which is not desired. Rather, blacklisting by missing properties is meant to ensure that the WWID determined from udev properties is _reliable_. Therefore, blacklist only devices that exhibit ID_SERIAL (or more generally, the configured uid_attribute), but do not have the required whitelist properties set. This will avoid the above-mentioned problem, because if failed device I/O was causing properties to be missing, ID_SERIAL will most likely also not be set. Signed-off-by: Martin Wilck --- libmultipath/blacklist.c | 26 +++++++++++++++++++++++-- libmultipath/blacklist.h | 2 +- libmultipath/configure.c | 6 +++--- libmultipath/discovery.c | 2 +- multipath/multipath.conf.5 | 8 ++++++++ tests/blacklist.c | 39 +++++++++++++++++++++++++++++++++----- 6 files changed, 71 insertions(+), 12 deletions(-) diff --git a/libmultipath/blacklist.c b/libmultipath/blacklist.c index e0d02794..00e8dbdb 100644 --- a/libmultipath/blacklist.c +++ b/libmultipath/blacklist.c @@ -366,7 +366,7 @@ filter_path (struct config * conf, struct path * pp) { int r; - r = filter_property(conf, pp->udev, 3); + r = filter_property(conf, pp->udev, 3, pp->uid_attribute); if (r > 0) return r; r = filter_devnode(conf->blist_devnode, conf->elist_devnode, pp->dev); @@ -384,7 +384,8 @@ filter_path (struct config * conf, struct path * pp) } int -filter_property(struct config *conf, struct udev_device *udev, int lvl) +filter_property(struct config *conf, struct udev_device *udev, int lvl, + const char *uid_attribute) { const char *devname = udev_device_get_sysname(udev); struct udev_list_entry *list_entry; @@ -395,7 +396,21 @@ filter_property(struct config *conf, struct udev_device *udev, int lvl) /* * This is the inverse of the 'normal' matching; * the environment variable _has_ to match. + * But only if the uid_attribute used for determining the WWID + * of the path is is present in the environment + * (uid_attr_seen). If this is not the case, udev probably + * just failed to access the device, which should not cause the + * device to be blacklisted (it won't be used by multipath + * anyway without WWID). + * Likewise, if no uid attribute is defined, udev-based WWID + * determination is effectively off, and devices shouldn't be + * blacklisted by missing properties (check_missing_prop). */ + + bool check_missing_prop = uid_attribute != NULL && + *uid_attribute != '\0'; + bool uid_attr_seen = false; + r = MATCH_PROPERTY_BLIST_MISSING; udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev)) { @@ -403,6 +418,10 @@ filter_property(struct config *conf, struct udev_device *udev, int lvl) env = udev_list_entry_get_name(list_entry); if (!env) continue; + + if (check_missing_prop && !strcmp(env, uid_attribute)) + uid_attr_seen = true; + if (_blacklist_exceptions(conf->elist_property, env)) { r = MATCH_PROPERTY_BLIST_EXCEPT; break; @@ -413,6 +432,9 @@ filter_property(struct config *conf, struct udev_device *udev, int lvl) } env = NULL; } + if (r == MATCH_PROPERTY_BLIST_MISSING && + (!check_missing_prop || !uid_attr_seen)) + r = MATCH_NOTHING; } log_filter(devname, NULL, NULL, NULL, env, NULL, r, lvl); diff --git a/libmultipath/blacklist.h b/libmultipath/blacklist.h index 4c8ec99e..2d721f60 100644 --- a/libmultipath/blacklist.h +++ b/libmultipath/blacklist.h @@ -37,7 +37,7 @@ int filter_devnode (vector, vector, char *); int filter_wwid (vector, vector, char *, char *); int filter_device (vector, vector, char *, char *, char *); int filter_path (struct config *, struct path *); -int filter_property(struct config *, struct udev_device *, int); +int filter_property(struct config *, struct udev_device *, int, const char*); int filter_protocol(vector, vector, struct path *); int store_ble (vector, char *, int); int set_ble_device (vector, char *, char *, int); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index c8dd69b0..b09ef529 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -1369,7 +1369,7 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); if (pp->udev && pp->uid_attribute && - filter_property(conf, pp->udev, 3) > 0) + filter_property(conf, pp->udev, 3, pp->uid_attribute) > 0) invalid = 1; pthread_cleanup_pop(1); if (invalid) @@ -1409,7 +1409,7 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); if (pp->udev && pp->uid_attribute && - filter_property(conf, pp->udev, 3) > 0) + filter_property(conf, pp->udev, 3, pp->uid_attribute) > 0) invalid = 1; pthread_cleanup_pop(1); if (invalid) @@ -1438,7 +1438,7 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); if (pp->udev && pp->uid_attribute && - filter_property(conf, pp->udev, 3) > 0) + filter_property(conf, pp->udev, 3, pp->uid_attribute) > 0) invalid = 1; pthread_cleanup_pop(1); if (invalid) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 15f5cd4b..acca466c 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -1945,7 +1945,7 @@ int pathinfo(struct path *pp, struct config *conf, int mask) return PATHINFO_SKIPPED; } if (is_claimed_by_foreign(pp->udev) || - filter_property(conf, pp->udev, 4) > 0) + filter_property(conf, pp->udev, 4, pp->uid_attribute) > 0) return PATHINFO_SKIPPED; } diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index 6f08980a..d5fe38ac 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -1241,6 +1241,14 @@ otherwise they're treated as blacklisted, and the message . .RS .PP +.B Note: +The behavior of this option has changed in \fBmultipath-tools\fR 0.8.2 +compared to previous versions. +Blacklisting by missing properties is only applied to devices which do have the +property specified by \fIuid_attribute\fR (e.g. \fIID_SERIAL\fR) +set. Previously, it was applied to every device, possibly causing devices to be +blacklisted because of temporary I/O error conditions. +.PP The default \fIblacklist exception\fR is: \fB(SCSI_IDENT_|ID_WWN)\fR, causing well-behaved SCSI devices and devices that provide a WWN (World Wide Number) to be included, and all others to be excluded. diff --git a/tests/blacklist.c b/tests/blacklist.c index 54d568f5..362c44d9 100644 --- a/tests/blacklist.c +++ b/tests/blacklist.c @@ -267,7 +267,7 @@ static void test_property_blacklist(void **state) static struct udev_device udev = { "sdb", { "ID_FOO", "ID_WWN", "ID_BAR", NULL } }; conf.blist_property = blist_property_wwn; expect_condlog(3, "sdb: udev property ID_WWN blacklisted\n"); - assert_int_equal(filter_property(&conf, &udev, 3), + assert_int_equal(filter_property(&conf, &udev, 3, "ID_SERIAL"), MATCH_PROPERTY_BLIST); } @@ -281,17 +281,23 @@ static void test_property_whitelist(void **state) static struct udev_device udev = { "sdb", { "ID_FOO", "ID_WWN", "ID_BAR", NULL } }; conf.elist_property = blist_property_wwn; expect_condlog(3, "sdb: udev property ID_WWN whitelisted\n"); - assert_int_equal(filter_property(&conf, &udev, 3), + assert_int_equal(filter_property(&conf, &udev, 3, "ID_SERIAL"), MATCH_PROPERTY_BLIST_EXCEPT); } static void test_property_missing(void **state) { - static struct udev_device udev = { "sdb", { "ID_FOO", "ID_BAZ", "ID_BAR", NULL } }; + static struct udev_device udev = { "sdb", { "ID_FOO", "ID_BAZ", "ID_BAR", "ID_SERIAL", NULL } }; conf.blist_property = blist_property_wwn; expect_condlog(3, "sdb: blacklisted, udev property missing\n"); - assert_int_equal(filter_property(&conf, &udev, 3), + assert_int_equal(filter_property(&conf, &udev, 3, "ID_SERIAL"), MATCH_PROPERTY_BLIST_MISSING); + assert_int_equal(filter_property(&conf, &udev, 3, "ID_BLAH"), + MATCH_NOTHING); + assert_int_equal(filter_property(&conf, &udev, 3, ""), + MATCH_NOTHING); + assert_int_equal(filter_property(&conf, &udev, 3, NULL), + MATCH_NOTHING); } struct udev_device test_udev = { "sdb", { "ID_FOO", "ID_WWN", "ID_BAR", NULL } }; @@ -347,16 +353,25 @@ static void test_filter_path_wwid(void **state) assert_int_equal(filter_path(&conf, &test_pp), MATCH_WWID_BLIST); } -struct udev_device miss_udev = { "sdb", { "ID_FOO", "ID_BAZ", "ID_BAR", NULL } }; +struct udev_device miss_udev = { "sdb", { "ID_FOO", "ID_BAZ", "ID_BAR", "ID_SERIAL", NULL } }; struct path miss1_pp = { .dev = "sdc", .bus = SYSFS_BUS_SCSI, .udev = &miss_udev, + .uid_attribute = "ID_SERIAL", .sg_id.proto_id = SCSI_PROTOCOL_ISCSI, .vendor_id = "foo", .product_id = "baz", .wwid = "plugh" }; struct path miss2_pp = { .dev = "sdc", .bus = SYSFS_BUS_SCSI, .udev = &test_udev, + .uid_attribute = "ID_SERIAL", + .sg_id.proto_id = SCSI_PROTOCOL_ISCSI, + .vendor_id = "foo", .product_id = "baz", + .wwid = "plugh" }; + +struct path miss3_pp = { .dev = "sdc", .bus = SYSFS_BUS_SCSI, + .udev = &miss_udev, + .uid_attribute = "ID_EGGS", .sg_id.proto_id = SCSI_PROTOCOL_ISCSI, .vendor_id = "foo", .product_id = "baz", .wwid = "plugh" }; @@ -387,6 +402,19 @@ static void test_filter_path_missing2(void **state) MATCH_NOTHING); } +/* Here we use a different uid_attribute which is also missing, thus + the path is not blacklisted */ +static void test_filter_path_missing3(void **state) +{ + conf.blist_property = blist_property_wwn; + conf.blist_devnode = blist_devnode_sdb; + conf.blist_device = blist_device_foo_bar; + conf.blist_protocol = blist_protocol_fcp; + conf.blist_wwid = blist_wwid_xyzzy; + assert_int_equal(filter_path(&conf, &miss3_pp), + MATCH_NOTHING); +} + static void test_filter_path_whitelist(void **state) { conf.elist_property = blist_property_wwn; @@ -495,6 +523,7 @@ int test_blacklist(void) test_and_reset(test_filter_path_wwid), test_and_reset(test_filter_path_missing1), test_and_reset(test_filter_path_missing2), + test_and_reset(test_filter_path_missing3), test_and_reset(test_filter_path_whitelist), test_and_reset(test_filter_path_whitelist_property), test_and_reset(test_filter_path_whitelist_devnode), From patchwork Mon Jun 24 09:27:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 11012759 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 6364A112C for ; Mon, 24 Jun 2019 09:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 520FD285C8 for ; Mon, 24 Jun 2019 09:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4693628841; Mon, 24 Jun 2019 09:30:50 +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 410D3285C8 for ; Mon, 24 Jun 2019 09:30:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DB2A3084034; Mon, 24 Jun 2019 09:30:48 +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 57F581001B04; Mon, 24 Jun 2019 09:30:48 +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 24F211806B1D; Mon, 24 Jun 2019 09:30:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5O9TnHH005857 for ; Mon, 24 Jun 2019 05:29:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3097F1972A; Mon, 24 Jun 2019 09:29:49 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2757F19C69; Mon, 24 Jun 2019 09:29:49 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE5B883F4C; Mon, 24 Jun 2019 09:29:41 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Mon, 24 Jun 2019 03:29:36 -0600 From: Martin Wilck To: Benjamin Marzinski , Christophe Varoqui Date: Mon, 24 Jun 2019 11:27:56 +0200 Message-Id: <20190624092756.7769-32-mwilck@suse.com> In-Reply-To: <20190624092756.7769-1-mwilck@suse.com> References: <20190624092756.7769-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jun 2019 09:29:42 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: 0.174 (RCVD_IN_DNSWL_MED, SORTED_RECIPS, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Xose Vazquez Perez , Tang Junhui , Martin Wilck Subject: [dm-devel] [PATCH v2 30/30] multipath.conf.5: Improve documentation of WWID determination 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 24 Jun 2019 09:30:48 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Clarify the effect of setting uid_attrs, and document the effect of setting uid_attribute to an empty string. Replace the arcane "vpd_pg83" with something easier to understand. Tell the user that the defaults are usually good enough. Cc: Tang Junhui Cc: Xose Vazquez Perez Signed-off-by: Martin Wilck --- multipath/multipath.conf.5 | 48 ++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index d5fe38ac..f7d21b4c 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -241,23 +241,32 @@ The default is: \fBfailover\fR . .TP .B uid_attrs -The udev attribute providing a unique path identifier for corresponding -type of path devices. If this field is configured and matched with type -of device, it would override any other methods providing for device -unique identifier in config file, and it would activate merging uevents -according to the identifier to promote effiecncy in processing uevents. -It has no default value, if you want to identify path by udev attribute -and to activate merging uevents for SCSI and DASD devices, you can set -its value as: \fIuid_attrs "sd:ID_SERIAL dasd:ID_UID"\fR. +. +Setting this option activates \fBmerging uevents\fR by WWID, which may improve +uevent processing effiency. Moreover, it's an alternative method to configure +the udev properties to use for determining unique path identifiers (WWIDs). .RS -.TP -The default is: \fB\fR +.PP +The value of this option is a space separated list of records like +\(dq\fItype:ATTR\fR\(dq, where \fItype\fR is matched against the beginning +of the device node name (e.g. \fIsd:ATTR\fR matches \fIsda\fR), and +\fIATTR\fR is the name of the udev property to use for matching devices. +.PP +If this option is configured and matches the device +node name of a device, it overrides any other configured methods for +determining the WWID for this device. +.PP +The default is: \fB\fR. To enable uevent merging, set it e.g. to +\(dqsd:ID_SERIAL dasd:ID_UID nvme:ID_WWN\(dq. .RE . . .TP .B uid_attribute -The udev attribute providing a unique path identifier. +The udev attribute providing a unique path identifier (WWID). If +\fIuid_attribute\fR is set to the empty string, WWID determination is done +using the \fIsysfs\fR method rather then using udev (not recommended in +production; see \fBWWID generation\fR below). .RS .TP The default is: \fBID_SERIAL\fR, for SCSI devices @@ -1635,8 +1644,8 @@ WWID is assumed to point to the same device. The WWID is generated by four methods (in the order of preference): .TP 17 .B uid_attrs -The WWID is derived from udev attributes by matching the device node name. See -description of \fIuid_attrs\fR in the defaults section above. +The WWID is derived from udev attributes by matching the device node name; cf +\fIuid_attrs\fR above. .TP .B getuid_callout Use the specified external program; cf \fIgetuid_callout\fR above. @@ -1651,10 +1660,15 @@ does not need to call any external programs here. However, under certain circumstances udev might not be able to generate the requested variable. .TP -.B vpd_pg83 -If none of the \fIgetuid_callout\fR or \fIuid_attribute\fR parameters -are present multipath will try to use the sysfs attribute -\fIvpd_pg83\fR to generate the WWID. +.B sysfs +Try to determine the WWID from sysfs attributes. +For SCSI devices, this means reading the Vital Product Data (VPD) page +\(dqDevice Identification\(dq (0x83). +.PP +The default settings (using udev and \fBuid_attribute\fR configured from +the built-in hardware table) should work fine +in most scenarios. Users who want to enable uevent merging must set +\fBuid_attrs\fR. . . .\" ----------------------------------------------------------------------------