From patchwork Fri Jun 7 13:05:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981691 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 1EFE614B6 for ; Fri, 7 Jun 2019 13:09:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DF34286BC for ; Fri, 7 Jun 2019 13:09:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 023D0288F8; Fri, 7 Jun 2019 13:09:51 +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 A590B286BC for ; Fri, 7 Jun 2019 13:09:51 +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 ECA7530C543C; Fri, 7 Jun 2019 13:09:50 +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 D08A382F53; Fri, 7 Jun 2019 13:09:50 +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 9B68218433A3; Fri, 7 Jun 2019 13:09:50 +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 x57D6rJn000404 for ; Fri, 7 Jun 2019 09:06:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id E27E58189F; Fri, 7 Jun 2019 13:06:53 +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 CBAB282703; Fri, 7 Jun 2019 13:06: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 226EF3082145; Fri, 7 Jun 2019 13:06:14 +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); Fri, 07 Jun 2019 07:06:06 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:23 +0200 Message-Id: <20190607130552.13203-2-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:06:40 +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.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 07 Jun 2019 13:09:51 +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 Fri Jun 7 13:05:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981651 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 4988C14E5 for ; Fri, 7 Jun 2019 13:07:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37DFC289D1 for ; Fri, 7 Jun 2019 13:07:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2921728BAB; Fri, 7 Jun 2019 13:07:55 +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 BFB5228947 for ; Fri, 7 Jun 2019 13:07: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 A98153091DD1; Fri, 7 Jun 2019 13:07:27 +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 3593E8231E; Fri, 7 Jun 2019 13:07: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 D9066206D3; Fri, 7 Jun 2019 13:06:51 +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 x57D6lZZ000343 for ; Fri, 7 Jun 2019 09:06:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02BE47FE8D; Fri, 7 Jun 2019 13:06:47 +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 B0F0E7FE8C; Fri, 7 Jun 2019 13:06:44 +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 81BEC30001D8; Fri, 7 Jun 2019 13:06:14 +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); Fri, 07 Jun 2019 07:06:07 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:24 +0200 Message-Id: <20190607130552.13203-3-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:06:28 +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.298 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_NONE) 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.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:07:53 +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 Fri Jun 7 13:05:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981649 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 818C614B6 for ; Fri, 7 Jun 2019 13:07:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68CC8286BC for ; Fri, 7 Jun 2019 13:07:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CCBB288A9; Fri, 7 Jun 2019 13:07:51 +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 E6FB6286BC for ; Fri, 7 Jun 2019 13:07:50 +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 762E630C1206; Fri, 7 Jun 2019 13:07:23 +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 707608CBAC; Fri, 7 Jun 2019 13:07:13 +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 D9BA018433A1; Fri, 7 Jun 2019 13:06: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 x57D6qYN000378 for ; Fri, 7 Jun 2019 09:06:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id D513182F56; Fri, 7 Jun 2019 13:06:52 +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 CE10982F53; Fri, 7 Jun 2019 13:06: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 D27BC85376; Fri, 7 Jun 2019 13:06:14 +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); Fri, 07 Jun 2019 07:06:09 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:25 +0200 Message-Id: <20190607130552.13203-4-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jun 2019 13:06:39 +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 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 07 Jun 2019 13:07:50 +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 Fri Jun 7 13:05: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: 10981663 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 DA4FF14B6 for ; Fri, 7 Jun 2019 13:09:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9889286BC for ; Fri, 7 Jun 2019 13:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBC2C288F8; Fri, 7 Jun 2019 13:09: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 07BBB286BC for ; Fri, 7 Jun 2019 13:09: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 A09363005216; Fri, 7 Jun 2019 13:09:02 +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 6B38883859; Fri, 7 Jun 2019 13:09:00 +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 33519206D4; Fri, 7 Jun 2019 13:08:57 +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 x57D6sYe000405 for ; Fri, 7 Jun 2019 09:06:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55A208CB89; Fri, 7 Jun 2019 13:06:54 +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 33F4B17D09; Fri, 7 Jun 2019 13:06: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 6577A3007406; Fri, 7 Jun 2019 13:06:15 +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); Fri, 07 Jun 2019 07:06:10 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:26 +0200 Message-Id: <20190607130552.13203-5-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:06: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.42 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 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.47]); Fri, 07 Jun 2019 13:09:08 +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 Fri Jun 7 13:05:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981659 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 BF09B14E5 for ; Fri, 7 Jun 2019 13:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD1A5286BC for ; Fri, 7 Jun 2019 13:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A148E288F8; Fri, 7 Jun 2019 13:08:46 +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 0DB5A286BC for ; Fri, 7 Jun 2019 13:08:45 +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 7052230C31B9; Fri, 7 Jun 2019 13:08:44 +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 4F2817D562; Fri, 7 Jun 2019 13:08: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 1B7E518433A5; Fri, 7 Jun 2019 13:08:39 +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 x57D6kNq000337 for ; Fri, 7 Jun 2019 09:06:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE50682F56; Fri, 7 Jun 2019 13:06:46 +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 BCA9C82268; Fri, 7 Jun 2019 13:06:41 +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 9441F81F0E; Fri, 7 Jun 2019 13:06:23 +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); Fri, 07 Jun 2019 07:06:11 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:27 +0200 Message-Id: <20190607130552.13203-6-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jun 2019 13:06:28 +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.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:08:45 +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 +- libmultipath/uxsock.c | 2 +- 6 files changed, 25 insertions(+), 26 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..dfee7d24 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, WWID_SIZE)) == 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; } } diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c index 7e5a1449..1ec4549b 100644 --- a/libmultipath/uxsock.c +++ b/libmultipath/uxsock.c @@ -67,7 +67,7 @@ int ux_socket_listen(const char *name) 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); + strncpy(&addr.sun_path[1], name, sizeof(addr.sun_path) - 1); if (bind(fd, (struct sockaddr *)&addr, len) == -1) { condlog(3, "Couldn't bind to ux_socket, error %d", errno); From patchwork Fri Jun 7 13:05: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: 10981687 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 3746C14B6 for ; Fri, 7 Jun 2019 13:09:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 251E1286BC for ; Fri, 7 Jun 2019 13:09:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1951028947; Fri, 7 Jun 2019 13:09: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 9ED27286BC for ; Fri, 7 Jun 2019 13:09:44 +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 CFD627FDF8; Fri, 7 Jun 2019 13:09:43 +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 AF1D310AFF18; Fri, 7 Jun 2019 13:09: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 7AA15206D7; Fri, 7 Jun 2019 13:09:43 +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 x57D6tOD000450 for ; Fri, 7 Jun 2019 09:06:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC0637FE91; Fri, 7 Jun 2019 13:06:55 +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 D83D47FE8C; Fri, 7 Jun 2019 13:06:51 +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 B5B90B2DD1; Fri, 7 Jun 2019 13:06:23 +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); Fri, 07 Jun 2019 07:06:13 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:28 +0200 Message-Id: <20190607130552.13203-7-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jun 2019 13:06:39 +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.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.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.27]); Fri, 07 Jun 2019 13:09:44 +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 dfee7d24..c8dd69b0 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 Fri Jun 7 13:05:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981665 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 2161A14E5 for ; Fri, 7 Jun 2019 13:09:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F2B4286BC for ; Fri, 7 Jun 2019 13:09:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03185288F8; Fri, 7 Jun 2019 13:09:20 +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 956D5286BC for ; Fri, 7 Jun 2019 13:09:20 +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 997E630860C9; Fri, 7 Jun 2019 13:09:12 +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 377AA7DE40; Fri, 7 Jun 2019 13:09:10 +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 C97BE18433A9; Fri, 7 Jun 2019 13:09:08 +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 x57D6pdG000367 for ; Fri, 7 Jun 2019 09:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C2D07FE8C; Fri, 7 Jun 2019 13:06:51 +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 7978C7FE93; Fri, 7 Jun 2019 13:06: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 D768D30832E4; Fri, 7 Jun 2019 13:06:23 +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); Fri, 07 Jun 2019 07:06:14 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:29 +0200 Message-Id: <20190607130552.13203-8-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 07 Jun 2019 13:06: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.44 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 07/30] libmpathcmd: use target length in strncpy() call 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]); Fri, 07 Jun 2019 13:09:20 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Martin Wilck --- libmpathcmd/mpath_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c index b681311b..05b69316 100644 --- a/libmpathcmd/mpath_cmd.c +++ b/libmpathcmd/mpath_cmd.c @@ -104,7 +104,7 @@ int __mpath_connect(int nonblocking) addr.sun_family = AF_LOCAL; addr.sun_path[0] = '\0'; len = strlen(DEFAULT_SOCKET) + 1 + sizeof(sa_family_t); - strncpy(&addr.sun_path[1], DEFAULT_SOCKET, len); + strncpy(&addr.sun_path[1], DEFAULT_SOCKET, sizeof(addr.sun_path) - 1); fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (fd == -1) From patchwork Fri Jun 7 13:05: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: 10981655 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 7476A14B6 for ; Fri, 7 Jun 2019 13:08:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62E58286BC for ; Fri, 7 Jun 2019 13:08:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 573D4288A9; Fri, 7 Jun 2019 13:08: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 00FFD286BC for ; Fri, 7 Jun 2019 13:08:42 +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 CD8F52E95B0; Fri, 7 Jun 2019 13:08:29 +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 A812E7DE3D; Fri, 7 Jun 2019 13:08:26 +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 760C718433A0; Fri, 7 Jun 2019 13:08:24 +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 x57D6mAB000352 for ; Fri, 7 Jun 2019 09:06:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73F987FE8D; Fri, 7 Jun 2019 13:06:48 +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 6BC657FE8C; Fri, 7 Jun 2019 13:06:46 +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 323AE81DEE; Fri, 7 Jun 2019 13:06:24 +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); Fri, 07 Jun 2019 07:06:16 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:30 +0200 Message-Id: <20190607130552.13203-9-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jun 2019 13:06:36 +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.298 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_NONE) 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.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jun 2019 13:08:40 +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 Fri Jun 7 13:05: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: 10981657 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 DFFFF14E5 for ; Fri, 7 Jun 2019 13:08:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE0FD286BC for ; Fri, 7 Jun 2019 13:08:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2725288F8; Fri, 7 Jun 2019 13:08:43 +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 45C14286BC for ; Fri, 7 Jun 2019 13:08:43 +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 F189F2E95B5; Fri, 7 Jun 2019 13:08:29 +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 CA6417DE40; Fri, 7 Jun 2019 13:08:26 +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 9B729206D5; Fri, 7 Jun 2019 13:08:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x57D6oJZ000366 for ; Fri, 7 Jun 2019 09:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id E979582EEF; Fri, 7 Jun 2019 13:06:50 +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 BE6E48385C; Fri, 7 Jun 2019 13:06:46 +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 B49BE88E55; Fri, 7 Jun 2019 13:06:24 +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); Fri, 07 Jun 2019 07:06:17 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:31 +0200 Message-Id: <20190607130552.13203-10-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jun 2019 13:06:35 +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.13 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jun 2019 13:08:35 +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/devmapper.c | 28 +++++++++++++++++----------- libmultipath/devmapper.h | 2 +- libmultipath/wwids.c | 3 ++- multipathd/main.c | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) 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 Fri Jun 7 13:05:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981671 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 0F96415E6 for ; Fri, 7 Jun 2019 13:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0421289D6 for ; Fri, 7 Jun 2019 13:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4D29288F8; Fri, 7 Jun 2019 13:09: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 9B5B328857 for ; Fri, 7 Jun 2019 13:09: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 96AC530C31B1; Fri, 7 Jun 2019 13:09: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 6DDB282EEF; Fri, 7 Jun 2019 13:09: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 41A5518433A5; Fri, 7 Jun 2019 13:09:22 +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 x57D6pSW000369 for ; Fri, 7 Jun 2019 09:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1B4068C6B; Fri, 7 Jun 2019 13:06:51 +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 744525F5BB; Fri, 7 Jun 2019 13:06: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 4678E4627A; Fri, 7 Jun 2019 13:06:25 +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); Fri, 07 Jun 2019 07:06:18 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:32 +0200 Message-Id: <20190607130552.13203-11-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jun 2019 13:06: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.301 (RCVD_IN_DNSWL_MED, 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.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:09:25 +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 Fri Jun 7 13:05: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: 10981677 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 635AB14E5 for ; Fri, 7 Jun 2019 13:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D6A5288F8 for ; Fri, 7 Jun 2019 13:09:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 413FD28947; Fri, 7 Jun 2019 13:09:35 +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 EBF39286BC for ; Fri, 7 Jun 2019 13:09:34 +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 4EDCE30862BE; Fri, 7 Jun 2019 13:09:30 +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 2580482EEF; Fri, 7 Jun 2019 13:09:29 +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 5EB3F206D6; Fri, 7 Jun 2019 13:09: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 x57D6xfH000505 for ; Fri, 7 Jun 2019 09:06:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B5E468C68; Fri, 7 Jun 2019 13:06:59 +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 1054D68C61; Fri, 7 Jun 2019 13:06:58 +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 0653F44FB1; Fri, 7 Jun 2019 13:06:27 +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); Fri, 07 Jun 2019 07:06:20 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:33 +0200 Message-Id: <20190607130552.13203-12-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jun 2019 13:06:48 +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.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 07 Jun 2019 13:09:34 +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 Fri Jun 7 13:05: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: 10981685 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 8AF9D14E5 for ; Fri, 7 Jun 2019 13:09:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78DC4286BC for ; Fri, 7 Jun 2019 13:09:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D3E5288F8; Fri, 7 Jun 2019 13:09:43 +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 F04B7286BC for ; Fri, 7 Jun 2019 13:09:42 +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 EB5CA7E428; Fri, 7 Jun 2019 13:09:41 +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 C1CF219811; Fri, 7 Jun 2019 13:09:41 +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 90A7618433A4; Fri, 7 Jun 2019 13:09:41 +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 x57D6rxL000402 for ; Fri, 7 Jun 2019 09:06:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id D889F68C67; Fri, 7 Jun 2019 13:06:53 +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 D039E5F5BB; Fri, 7 Jun 2019 13:06:51 +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 3A8D430C5843; Fri, 7 Jun 2019 13:06:27 +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); Fri, 07 Jun 2019 07:06:21 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:34 +0200 Message-Id: <20190607130552.13203-13-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 07 Jun 2019 13:06:38 +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.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jun 2019 13:09:42 +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 Fri Jun 7 13:05: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: 10981697 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 6B91914B6 for ; Fri, 7 Jun 2019 13:10:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57D0828857 for ; Fri, 7 Jun 2019 13:10:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BE0C28BAD; Fri, 7 Jun 2019 13:10:05 +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 DE66D28857 for ; Fri, 7 Jun 2019 13:10:03 +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 6B7E530872F4; Fri, 7 Jun 2019 13:10:02 +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 39D5210AFF1A; Fri, 7 Jun 2019 13:10:02 +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 E25EE18433A3; Fri, 7 Jun 2019 13:10:01 +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 x57D71vG000556 for ; Fri, 7 Jun 2019 09:07:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3DC345F5BB; Fri, 7 Jun 2019 13:07:01 +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 348F917B23; Fri, 7 Jun 2019 13:07:00 +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 AC178308213C; Fri, 7 Jun 2019 13:06:33 +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); Fri, 07 Jun 2019 07:06:22 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:35 +0200 Message-Id: <20190607130552.13203-14-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:06:49 +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.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.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.47]); Fri, 07 Jun 2019 13:10:03 +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 Fri Jun 7 13:05: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: 10981667 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 47E7E14E5 for ; Fri, 7 Jun 2019 13:09:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 363C928857 for ; Fri, 7 Jun 2019 13:09:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ABE628947; Fri, 7 Jun 2019 13:09:22 +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 C934128857 for ; Fri, 7 Jun 2019 13:09:21 +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 D43B430F1BC8; Fri, 7 Jun 2019 13:09:20 +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 ACD828386C; Fri, 7 Jun 2019 13:09:20 +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 E2481206D5; Fri, 7 Jun 2019 13:09:18 +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 x57D6rVM000387 for ; Fri, 7 Jun 2019 09:06:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E48D7FE94; Fri, 7 Jun 2019 13:06:53 +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 957C97FE8D; Fri, 7 Jun 2019 13:06:51 +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 E4C4630001E1; Fri, 7 Jun 2019 13:06:33 +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); Fri, 07 Jun 2019 07:06:24 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:36 +0200 Message-Id: <20190607130552.13203-15-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 07 Jun 2019 13:06: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.301 (RCVD_IN_DNSWL_MED, 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 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.43]); Fri, 07 Jun 2019 13:09:21 +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 Fri Jun 7 13:05: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: 10981661 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 76D3714E5 for ; Fri, 7 Jun 2019 13:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DA528857 for ; Fri, 7 Jun 2019 13:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58F0A289D1; Fri, 7 Jun 2019 13:09:09 +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 105C028857 for ; Fri, 7 Jun 2019 13:09:09 +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 257A8A3B68; Fri, 7 Jun 2019 13:08:58 +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 C95127DE35; Fri, 7 Jun 2019 13:08: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 9DC5918433A5; Fri, 7 Jun 2019 13:08:54 +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 x57D6rxA000401 for ; Fri, 7 Jun 2019 09:06:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id CAB5882F53; Fri, 7 Jun 2019 13:06:53 +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 B6E5C82268; Fri, 7 Jun 2019 13:06: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 1306B308FC4E; Fri, 7 Jun 2019 13:06:34 +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); Fri, 07 Jun 2019 07:06:25 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:37 +0200 Message-Id: <20190607130552.13203-16-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 07 Jun 2019 13:06:40 +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.298 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_NONE) 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 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jun 2019 13:09:08 +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 Fri Jun 7 13:05: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: 10981693 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 BB2B414B6 for ; Fri, 7 Jun 2019 13:09:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9387286BC for ; Fri, 7 Jun 2019 13:09:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D213288F8; Fri, 7 Jun 2019 13:09: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 3290D286BC for ; Fri, 7 Jun 2019 13:09:56 +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 7F62A30C31BC; Fri, 7 Jun 2019 13:09:55 +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 60FD417D09; Fri, 7 Jun 2019 13:09: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 2FACE18433A2; Fri, 7 Jun 2019 13:09:55 +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 x57D6x5g000511 for ; Fri, 7 Jun 2019 09:06:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C7EF8CB89; Fri, 7 Jun 2019 13:06: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 3508317D09; Fri, 7 Jun 2019 13:06:59 +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 34DC522389D; Fri, 7 Jun 2019 13:06:34 +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); Fri, 07 Jun 2019 07:06:27 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:38 +0200 Message-Id: <20190607130552.13203-17-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jun 2019 13:06:38 +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.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:09:55 +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 Fri Jun 7 13:05: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: 10981695 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 9F77015E6 for ; Fri, 7 Jun 2019 13:09:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CABE28857 for ; Fri, 7 Jun 2019 13:09:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80FF0288F8; Fri, 7 Jun 2019 13:09:58 +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 363B528947 for ; Fri, 7 Jun 2019 13:09:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7352F2F8BFC; Fri, 7 Jun 2019 13:09: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 53B4F68C64; Fri, 7 Jun 2019 13:09: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 27BDF206D2; Fri, 7 Jun 2019 13:09:56 +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 x57D6rTd000396 for ; Fri, 7 Jun 2019 09:06:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id B4BEE82707; Fri, 7 Jun 2019 13:06:53 +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 90BC88231E; Fri, 7 Jun 2019 13:06: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 84743B2DEC; Fri, 7 Jun 2019 13:06:34 +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); Fri, 07 Jun 2019 07:06:28 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:39 +0200 Message-Id: <20190607130552.13203-18-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jun 2019 13:06: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.78 on 10.5.110.26 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 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 07 Jun 2019 13:09:56 +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 Fri Jun 7 13:05: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: 10981699 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 5758214B6 for ; Fri, 7 Jun 2019 13:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 450F2289D1 for ; Fri, 7 Jun 2019 13:10:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39BB128A94; Fri, 7 Jun 2019 13:10: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 D5AC428857 for ; Fri, 7 Jun 2019 13:10: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 50203307D9D0; Fri, 7 Jun 2019 13:10: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 24B5A82268; Fri, 7 Jun 2019 13:10: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 C31CE206D4; Fri, 7 Jun 2019 13:10:03 +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 x57D6roC000403 for ; Fri, 7 Jun 2019 09:06:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB12582704; Fri, 7 Jun 2019 13:06:53 +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 D376D8231E; Fri, 7 Jun 2019 13:06:51 +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 13FA9356E4; Fri, 7 Jun 2019 13:06:35 +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); Fri, 07 Jun 2019 07:06:29 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:40 +0200 Message-Id: <20190607130552.13203-19-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jun 2019 13:06: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.78 on 10.5.110.30 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 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Jun 2019 13:10:05 +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 Fri Jun 7 13:05: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: 10981669 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 0429F14B6 for ; Fri, 7 Jun 2019 13:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FCD286BC for ; Fri, 7 Jun 2019 13:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA933289D1; Fri, 7 Jun 2019 13:09: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 78FD3286BC for ; Fri, 7 Jun 2019 13:09:25 +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 8F6F518DF7A; Fri, 7 Jun 2019 13:09: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 5E3DA8231E; Fri, 7 Jun 2019 13:09:16 +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 252D7206D3; Fri, 7 Jun 2019 13:09:13 +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 x57D6wQX000492 for ; Fri, 7 Jun 2019 09:06:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25C6E82703; Fri, 7 Jun 2019 13:06: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 1E9AA82701; Fri, 7 Jun 2019 13:06: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 B6522C051684; Fri, 7 Jun 2019 13:06:35 +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); Fri, 07 Jun 2019 07:06:31 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:41 +0200 Message-Id: <20190607130552.13203-20-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jun 2019 13:06:47 +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.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.29]); Fri, 07 Jun 2019 13:09:25 +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 Fri Jun 7 13:05: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: 10981703 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 C424E14B6 for ; Fri, 7 Jun 2019 13:10:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A951B28C05 for ; Fri, 7 Jun 2019 13:10:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E01D28C08; Fri, 7 Jun 2019 13:10:15 +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 3FBC828A94 for ; Fri, 7 Jun 2019 13:10:15 +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 6FF2C3179156; Fri, 7 Jun 2019 13:10:14 +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 5052D82708; Fri, 7 Jun 2019 13:10:13 +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 E4F27206D6; Fri, 7 Jun 2019 13:10:11 +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 x57D71Tr000553 for ; Fri, 7 Jun 2019 09:07:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 387E782701; Fri, 7 Jun 2019 13:07:01 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F45D8189F; Fri, 7 Jun 2019 13:07:00 +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 03AF9308A963; Fri, 7 Jun 2019 13:06:44 +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); Fri, 07 Jun 2019 07:06:32 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:42 +0200 Message-Id: <20190607130552.13203-21-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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.41]); Fri, 07 Jun 2019 13:06:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 07 Jun 2019 13:06:49 +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.41 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 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 07 Jun 2019 13:10:14 +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 Fri Jun 7 13:05: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: 10981679 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 7687715E6 for ; Fri, 7 Jun 2019 13:09:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61E56286BC for ; Fri, 7 Jun 2019 13:09:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56730289D6; Fri, 7 Jun 2019 13:09:35 +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 0AD5228857 for ; Fri, 7 Jun 2019 13:09:35 +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 C4796307D840; Fri, 7 Jun 2019 13:09:31 +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 A6CBA7DE48; Fri, 7 Jun 2019 13:09: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 745F118433A7; Fri, 7 Jun 2019 13:09:30 +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 x57D74oD000597 for ; Fri, 7 Jun 2019 09:07:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F8A37FE94; Fri, 7 Jun 2019 13:07:04 +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 623167FE8C; Fri, 7 Jun 2019 13:06:59 +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 215603082E42; Fri, 7 Jun 2019 13:06:44 +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); Fri, 07 Jun 2019 07:06:34 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:43 +0200 Message-Id: <20190607130552.13203-22-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 07 Jun 2019 13:06: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.84 on 10.5.110.46 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 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Jun 2019 13:09:34 +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 Fri Jun 7 13:05: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: 10981675 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 9ECA514B6 for ; Fri, 7 Jun 2019 13:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF0A286BC for ; Fri, 7 Jun 2019 13:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F391288F8; Fri, 7 Jun 2019 13:09:33 +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 2A8AD286BC for ; Fri, 7 Jun 2019 13:09:33 +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 458A9307D85A; Fri, 7 Jun 2019 13:09:32 +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 1C1B18386F; Fri, 7 Jun 2019 13:09:31 +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 DF0EC206D8; Fri, 7 Jun 2019 13:09:29 +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 x57D6psj000368 for ; Fri, 7 Jun 2019 09:06:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93CA468C6A; Fri, 7 Jun 2019 13:06:51 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 173AD68C61; Fri, 7 Jun 2019 13:06: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 406483082163; Fri, 7 Jun 2019 13:06:44 +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); Fri, 07 Jun 2019 07:06:35 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:44 +0200 Message-Id: <20190607130552.13203-23-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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.47]); Fri, 07 Jun 2019 13:06:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 07 Jun 2019 13:06:44 +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.47 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 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Jun 2019 13:09:32 +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 Fri Jun 7 13:05: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: 10981709 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 757F214E5 for ; Fri, 7 Jun 2019 13:10:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62CF628901 for ; Fri, 7 Jun 2019 13:10:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 572FA28917; Fri, 7 Jun 2019 13:10:35 +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 114D528925 for ; Fri, 7 Jun 2019 13:10:35 +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 510C6B2DDB; Fri, 7 Jun 2019 13:10:30 +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 335288CB89; Fri, 7 Jun 2019 13:10: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 E7DC118433A6; Fri, 7 Jun 2019 13:10:28 +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 x57D74va000607 for ; Fri, 7 Jun 2019 09:07:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8CABD7FE93; Fri, 7 Jun 2019 13:07:04 +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 8527D7FE8D; Fri, 7 Jun 2019 13:07:03 +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 627175F793; Fri, 7 Jun 2019 13:06:44 +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); Fri, 07 Jun 2019 07:06:36 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:45 +0200 Message-Id: <20190607130552.13203-24-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jun 2019 13:06:48 +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.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jun 2019 13:10:34 +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 Fri Jun 7 13:05: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: 10981673 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 6B2F03E8C for ; Fri, 7 Jun 2019 13:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 582CA286BC for ; Fri, 7 Jun 2019 13:09:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C8BB28857; Fri, 7 Jun 2019 13:09: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 E798928947 for ; Fri, 7 Jun 2019 13:09:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 370E4223890; Fri, 7 Jun 2019 13:09: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 116E168C61; Fri, 7 Jun 2019 13:09:25 +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 D1A4618433A2; Fri, 7 Jun 2019 13:09:24 +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 x57D70F3000530 for ; Fri, 7 Jun 2019 09:07:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F8855F5BB; Fri, 7 Jun 2019 13:07:00 +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 06D9217B23; Fri, 7 Jun 2019 13:06:59 +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 B3818308620F; Fri, 7 Jun 2019 13:06:44 +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); Fri, 07 Jun 2019 07:06:38 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:46 +0200 Message-Id: <20190607130552.13203-25-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:06:47 +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.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jun 2019 13:09:25 +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 Fri Jun 7 13:05: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: 10981681 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 771CE14B6 for ; Fri, 7 Jun 2019 13:09:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66068286BC for ; Fri, 7 Jun 2019 13:09:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57A5E289D1; Fri, 7 Jun 2019 13:09:37 +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 F203F286BC for ; Fri, 7 Jun 2019 13:09: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 39A563078AC6; Fri, 7 Jun 2019 13:09:36 +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 1901382703; Fri, 7 Jun 2019 13:09:36 +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 DED52206D7; Fri, 7 Jun 2019 13:09:35 +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 x57D6xYD000518 for ; Fri, 7 Jun 2019 09:06:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8AF2F10AFF1D; Fri, 7 Jun 2019 13:06:59 +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 1343710AFF15; Fri, 7 Jun 2019 13:06: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 3419E3082E4D; Fri, 7 Jun 2019 13:06:45 +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); Fri, 07 Jun 2019 07:06:39 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:47 +0200 Message-Id: <20190607130552.13203-26-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 07 Jun 2019 13:06:47 +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, Martin Wilck Subject: [dm-devel] [PATCH 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Jun 2019 13:09:36 +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 Fri Jun 7 13:05: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: 10981705 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 01CA014B6 for ; Fri, 7 Jun 2019 13:10:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4A4D205A4 for ; Fri, 7 Jun 2019 13:10:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D94DD288F8; Fri, 7 Jun 2019 13:10: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 6C794205A4 for ; Fri, 7 Jun 2019 13:10:21 +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 5F35F811A9; Fri, 7 Jun 2019 13:10:20 +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 2D9AB7D562; Fri, 7 Jun 2019 13:10:20 +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 D9C7D206D6; Fri, 7 Jun 2019 13:10:18 +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 x57D700h000536 for ; Fri, 7 Jun 2019 09:07:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8351382F54; Fri, 7 Jun 2019 13:07:00 +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 7B22A82268; Fri, 7 Jun 2019 13:07:00 +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 83E48307CDD5; Fri, 7 Jun 2019 13:06:45 +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); Fri, 07 Jun 2019 07:06:40 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:48 +0200 Message-Id: <20190607130552.13203-27-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 07 Jun 2019 13:06:56 +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.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jun 2019 13:10:20 +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 Fri Jun 7 13:05: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: 10981707 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 30BA714B6 for ; Fri, 7 Jun 2019 13:10:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DFE7288B9 for ; Fri, 7 Jun 2019 13:10:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 126DC28917; Fri, 7 Jun 2019 13:10: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 4ADFA288B9 for ; Fri, 7 Jun 2019 13:10:31 +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 7D007316D76E; Fri, 7 Jun 2019 13:10: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 5B5B610AFF18; Fri, 7 Jun 2019 13:10: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 1E53B18433A5; Fri, 7 Jun 2019 13:10:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x57D72md000567 for ; Fri, 7 Jun 2019 09:07:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9D38183868; Fri, 7 Jun 2019 13:07:02 +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 949FA8386E; Fri, 7 Jun 2019 13:07:02 +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 111733084213; Fri, 7 Jun 2019 13:06:54 +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); Fri, 07 Jun 2019 07:06:42 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:49 +0200 Message-Id: <20190607130552.13203-28-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:06: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.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck , Tang Junhui Subject: [dm-devel] [PATCH 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.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.41]); Fri, 07 Jun 2019 13:10:30 +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 Fri Jun 7 13:05: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: 10981683 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 D063714E5 for ; Fri, 7 Jun 2019 13:09:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDF61286BC for ; Fri, 7 Jun 2019 13:09:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B257D288F8; Fri, 7 Jun 2019 13:09:41 +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 52909286BC for ; Fri, 7 Jun 2019 13:09:41 +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 8ACF92F8BC1; Fri, 7 Jun 2019 13:09:40 +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 6A25710AFF17; Fri, 7 Jun 2019 13:09: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 34A8E18433A2; Fri, 7 Jun 2019 13:09:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x57D7CIB000936 for ; Fri, 7 Jun 2019 09:07:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA91083868; Fri, 7 Jun 2019 13:07:12 +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 6301E82EEF; Fri, 7 Jun 2019 13:07:10 +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 41D85C03D478; Fri, 7 Jun 2019 13:06:54 +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); Fri, 07 Jun 2019 07:06:43 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:50 +0200 Message-Id: <20190607130552.13203-29-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:06:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jun 2019 13:06: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.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 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.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.38]); Fri, 07 Jun 2019 13:09:40 +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 Fri Jun 7 13:05: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: 10981701 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 755FD14B6 for ; Fri, 7 Jun 2019 13:10:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 638C4288F8 for ; Fri, 7 Jun 2019 13:10:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57CD628BEC; Fri, 7 Jun 2019 13:10:09 +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 8EEDD288F8 for ; Fri, 7 Jun 2019 13:10:08 +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 51BA33001D53; Fri, 7 Jun 2019 13:10:07 +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 2BCCF82703; Fri, 7 Jun 2019 13:10: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 E0E7C18433A5; Fri, 7 Jun 2019 13:10:06 +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 x57D7ER8000941 for ; Fri, 7 Jun 2019 09:07:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id BEC7882F56; Fri, 7 Jun 2019 13:07:14 +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 3E97E82268; Fri, 7 Jun 2019 13:07:10 +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 638673007400; Fri, 7 Jun 2019 13:06:54 +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); Fri, 07 Jun 2019 07:06:45 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:51 +0200 Message-Id: <20190607130552.13203-30-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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]); Fri, 07 Jun 2019 13:07:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:07:03 +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 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.42]); Fri, 07 Jun 2019 13:10:08 +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 Fri Jun 7 13:05: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: 10981689 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 AC8B315E6 for ; Fri, 7 Jun 2019 13:09:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 999C6286BC for ; Fri, 7 Jun 2019 13:09:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D3F6288F8; Fri, 7 Jun 2019 13:09: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 147FD28857 for ; Fri, 7 Jun 2019 13:09:45 +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 3ED9C30872F5; Fri, 7 Jun 2019 13:09:44 +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 1EF6282709; Fri, 7 Jun 2019 13:09:44 +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 D9BFD206D7; Fri, 7 Jun 2019 13:09:43 +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 x57D7Hig000958 for ; Fri, 7 Jun 2019 09:07:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id F17337FE96; Fri, 7 Jun 2019 13:07:17 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7A2D7FE94; Fri, 7 Jun 2019 13:07:17 +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 9426C307D913; Fri, 7 Jun 2019 13:06:54 +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); Fri, 07 Jun 2019 07:06:46 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:52 +0200 Message-Id: <20190607130552.13203-31-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-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.48]); Fri, 07 Jun 2019 13:07:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Jun 2019 13:07:03 +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.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Xose Vazquez Perez , Martin Wilck , Tang Junhui Subject: [dm-devel] [PATCH 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.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.47]); Fri, 07 Jun 2019 13:09:44 +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. . . .\" ----------------------------------------------------------------------------