From patchwork Mon Sep 3 13:47:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10585969 X-Patchwork-Delegate: hal@mellanox.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F73016B1 for ; Mon, 3 Sep 2018 13:48:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1017628DA5 for ; Mon, 3 Sep 2018 13:48:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 042C528DBB; Mon, 3 Sep 2018 13:48:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BB4728DA5 for ; Mon, 3 Sep 2018 13:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbeICSIN (ORCPT ); Mon, 3 Sep 2018 14:08:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51488 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725982AbeICSIN (ORCPT ); Mon, 3 Sep 2018 14:08:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C5A9402243B; Mon, 3 Sep 2018 13:47:57 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209682166BA1; Mon, 3 Sep 2018 13:47:54 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: yuval.shaia@oracle.com, linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH] parse_group_flag log suspicious group flag value Date: Mon, 3 Sep 2018 21:47:49 +0800 Message-Id: <20180903134749.29912-1-honli@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 03 Sep 2018 13:47:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 03 Sep 2018 13:47:57 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'honli@redhat.com' RCPT:'' Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Honggang Li parse_mgroup_flags assumes that the flags of mgroup_flags are separated by comma. If the flags are separated with whitespace, only the first flag will be parsed correctly. Rest of flags will be dropped quietly. This patch makes parse_group_flag log suspicious group flag value. So, users will be warned because of wrong configuration file. Signed-off-by: Honggang Li --- opensm/osm_prtn_config.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/opensm/osm_prtn_config.c b/opensm/osm_prtn_config.c index f76ad4d4..0c01385c 100644 --- a/opensm/osm_prtn_config.c +++ b/opensm/osm_prtn_config.c @@ -266,6 +266,19 @@ static int partition_create(unsigned lineno, struct part_conf *conf, return 0; } +static unsigned long int verify_val(unsigned lineno, osm_log_t *p_log, + char *flag, char *val) +{ + char *end = NULL; + unsigned long int ret = strtoul(val, &end, 0); + if (val && end) + OSM_LOG(p_log, OSM_LOG_VERBOSE, + "PARSE WARN: line %d: " + "suspicious val=(%s) detected. " + "flag=(%s)\n", lineno, val, flag); + return ret; +} + /* returns 1 if processed 0 if _not_ */ static int parse_group_flag(unsigned lineno, osm_log_t * p_log, struct group_flags *flags, @@ -275,14 +288,14 @@ static int parse_group_flag(unsigned lineno, osm_log_t * p_log, int len = strlen(flag); if (!strncmp(flag, "mtu", len)) { rc = 1; - if (!val || (flags->mtu = strtoul(val, NULL, 0)) == 0) + if (!val || (flags->mtu = verify_val(lineno, p_log, flag, val)) == 0) OSM_LOG(p_log, OSM_LOG_VERBOSE, "PARSE WARN: line %d: " "flag \'mtu\' requires valid value" " - skipped\n", lineno); } else if (!strncmp(flag, "rate", len)) { rc = 1; - if (!val || (flags->rate = strtoul(val, NULL, 0)) == 0) + if (!val || (flags->rate = verify_val(lineno, p_log, flag, val)) == 0) OSM_LOG(p_log, OSM_LOG_VERBOSE, "PARSE WARN: line %d: " "flag \'rate\' requires valid value" @@ -290,7 +303,7 @@ static int parse_group_flag(unsigned lineno, osm_log_t * p_log, } else if (!strncmp(flag, "scope", len)) { unsigned int scope; rc = 1; - if (!val || (scope = strtoul(val, NULL, 0)) == 0 || scope > 0xF) + if (!val || (scope = verify_val(lineno, p_log, flag, val)) == 0 || scope > 0xF) OSM_LOG(p_log, OSM_LOG_VERBOSE, "PARSE WARN: line %d: " "flag \'scope\' requires valid value" @@ -299,14 +312,14 @@ static int parse_group_flag(unsigned lineno, osm_log_t * p_log, flags->scope_mask |= (1<Q_Key = strtoul(val, NULL, 0)) == 0) + if (!val || (flags->Q_Key = verify_val(lineno, p_log, flag, val)) == 0) OSM_LOG(p_log, OSM_LOG_VERBOSE, "PARSE WARN: line %d: " "flag \'Q_Key\' requires valid value" " - using '0'\n", lineno); } else if (!strncmp(flag, "TClass", strlen(flag))) { rc =1; - if (!val || (flags->TClass = strtoul(val, NULL, 0)) == 0) + if (!val || (flags->TClass = verify_val(lineno, p_log, flag, val)) == 0) OSM_LOG(p_log, OSM_LOG_VERBOSE, "PARSE WARN: line %d: " "flag \'TClass\' requires valid value"