Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp968306imm; Wed, 10 Oct 2018 07:10:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV619NjdKtxu6O8HQ7DG7vSkOVEgH18tFKEmYstE9uZG/Ui+Ob8BEN+PcD+gJYmz67NFNepmI X-Received: by 2002:a17:902:15c5:: with SMTP id a5-v6mr16820860plh.137.1539180646312; Wed, 10 Oct 2018 07:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539180646; cv=none; d=google.com; s=arc-20160816; b=nBV85JxoR5qINwv5I+/kNdwPr8uOyhsywrSsb+emHIt78y5YcsKTblbGTrlTuRBOLR +K/YXE9BUWtwRdJSp0nlVYmmOKPIgtCPYPZHMvyVWtRgfAVu4FaNNMWD/W/dP/QgqbZQ x6kwU/BjMoNyvwhDAb+HBP4qCrXcEwQH1ZNnA8d6yi9noV8TKTzI2B322yFGHr9+d11K lIGI9TnUlSssi9xAl9DJSRI/9kgbZ4+WhtNINtIyryS6IhP1EmWaIg6m8Zuyx9ArEetr EV4sOm3esVrWap0VdW5v8OqGEH4XTX+28H9OUpIy4p6qWcP1HKAxkBLC4vpVfLmoFJGD Giyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=CNpYATb123GKPYfFIkQTrxUr0FWVpINhm9z4Mn60OMY=; b=P86NHEnilbTN1NCCJiZJmbPKpAjrXxJ0VW1DD9QMFQxpEOXzN/+u5le8R9R8U8EebU W3je4F0ychPU29TVt8YDzj60BL7cu2FtZMubwpG3j6u6QqhP2yoExU4OgDrN9lfqzwe2 YJo5fjpcqbS//DjpXuRcDsE/GrNoAHlnie1TDmjcRz2Ubw9Jbf4nJvm76hgD9m46g+Jl C98Gin6ol4TFCdxkev49I3kHECoqAfYUT1myXn/5FbpSYXd0/u22twWNb+rt2Iy6ZqSX mE741t6mUYwOFAKp/xjBQH4H1khcd0zHxG3ZeTfG6nMkF28UIro4TAxwGNifHADv/9HL fg1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si23782640pgj.76.2018.10.10.07.10.31; Wed, 10 Oct 2018 07:10:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbeJJVby (ORCPT + 99 others); Wed, 10 Oct 2018 17:31:54 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:49403 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726896AbeJJVbx (ORCPT ); Wed, 10 Oct 2018 17:31:53 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Oct 2018 15:14:43 +0200 Received: from dev-l-vrt-136.mtl.labs.mlnx (dev-l-vrt-136.mtl.labs.mlnx [10.134.136.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w9AD9rvq003286; Wed, 10 Oct 2018 16:09:53 +0300 Received: from dev-l-vrt-136.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7) with ESMTP id w9AD9q1n022235; Wed, 10 Oct 2018 16:09:52 +0300 Received: (from moshe@localhost) by dev-l-vrt-136.mtl.labs.mlnx (8.14.7/8.14.7/Submit) id w9AD9qot022234; Wed, 10 Oct 2018 16:09:52 +0300 From: Moshe Shemesh To: "David S. Miller" Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Moshe Shemesh Subject: [PATCH net 1/3] devlink: Fix param set handling for string type Date: Wed, 10 Oct 2018 16:09:25 +0300 Message-Id: <1539176967-22172-2-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1539176967-22172-1-git-send-email-moshe@mellanox.com> References: <1539176967-22172-1-git-send-email-moshe@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case devlink param type is string, it needs to copy the string value it got from the input to devlink_param_value. Fixes: e3b7ca18ad7b ("devlink: Add param set command") Signed-off-by: Moshe Shemesh --- include/net/devlink.h | 2 +- net/core/devlink.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index b9b89d6..b0e17c0 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -311,7 +311,7 @@ enum devlink_param_type { u8 vu8; u16 vu16; u32 vu32; - const char *vstr; + char vstr[DEVLINK_PARAM_MAX_STRING_VALUE]; bool vbool; }; diff --git a/net/core/devlink.c b/net/core/devlink.c index 8c0ed22..d808af7 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -2995,6 +2995,8 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg, struct genl_info *info, union devlink_param_value *value) { + int len; + if (param->type != DEVLINK_PARAM_TYPE_BOOL && !info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) return -EINVAL; @@ -3010,10 +3012,13 @@ static int devlink_nl_cmd_param_get_dumpit(struct sk_buff *msg, value->vu32 = nla_get_u32(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]); break; case DEVLINK_PARAM_TYPE_STRING: - if (nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) > - DEVLINK_PARAM_MAX_STRING_VALUE) + len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]), + nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); + if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) || + len >= DEVLINK_PARAM_MAX_STRING_VALUE) return -EINVAL; - value->vstr = nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]); + strcpy(value->vstr, + nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); break; case DEVLINK_PARAM_TYPE_BOOL: value->vbool = info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA] ? -- 1.8.3.1