Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2376726iof; Wed, 8 Jun 2022 03:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyarRuURB2cmPPG3cXCGyAeJhFmYr5Y/uM0bUAq7UJWWAZMiY2ow9ZROnzsVpBxUNCCnE02 X-Received: by 2002:a17:90a:9741:b0:1e8:a001:5caa with SMTP id i1-20020a17090a974100b001e8a0015caamr9280163pjw.231.1654685178023; Wed, 08 Jun 2022 03:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654685178; cv=none; d=google.com; s=arc-20160816; b=tdg7IzH0KY8kpe6Jbz9M6OA7okYkobhdj+zSYKhA29ieWo71MvoKGRbC6Xd+6LQhzX GgKq99BqrrQ+4ae0JGxmdj1FnuXlnuLGqcyVlnIILH0LVAjUqCc93X/eqLfpwgHUXcix 2laxYcsqL0tnblgAO0ooL69Pnfdnem4WHiLOTea8aKQTW+eIaEBVfnLb78ggsffJ5lVV C+zRxbGIN4km/eIzL6JHxAX2sdGrieLYGIkCqNpkOlyuoVkepxq9sLEnw5yrN4fw/GNg QPOwDzbg1r5KCQykIK5/ge6eyI4dE+lwfsiNu+fblHH6cEpfBMjB94vZyo5EnMsTr67/ NoqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8roaq1cdvVMEWHs1hI7An+drBeTptYd2OjDG18m5M+8=; b=gWAvvt6b+n3jtl9FYN+FF4JxPB324Qykyq4mLVG74EVm7xsgtlRoKpASIxj/3B7VRS awrLxJdyNEL/uLvTOTAD5CZYvYVRL3XTwgS5NNMqJC3B1GmT3LJbAQgWr8LoHhb0oZx3 YG9jsLuRGyL7GzWZmlA2pBtp+d/1KZQy4Bx91mILm9c0Cx2tI3GXBnqPM2ZeEBI7C1U1 5Nl+fBNtNtpw8GsTrt2WQDLBSgY8SQuxUaosmLn/7AlgGSZAQxvOaPg6Ti9ZQnP1XrL7 CoH1EJTUEgAYnpJ/uyFBzI2rt/FIogV7YuBoeK3X5ZR16CgYsYQ3sp6kzGsW9uVpHo8m 33Fw== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t62-20020a638141000000b003db947d50fcsi27417013pgd.174.2022.06.08.03.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 03:46:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8D8391F7428; Wed, 8 Jun 2022 03:12:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235989AbiFHKLW (ORCPT + 99 others); Wed, 8 Jun 2022 06:11:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236448AbiFHKKe (ORCPT ); Wed, 8 Jun 2022 06:10:34 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A798D62FC for ; Wed, 8 Jun 2022 02:55:46 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 294221424; Wed, 8 Jun 2022 02:55:46 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 631B43F73B; Wed, 8 Jun 2022 02:55:45 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com Subject: [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Date: Wed, 8 Jun 2022 10:55:28 +0100 Message-Id: <20220608095530.497879-1-cristian.marussi@arm.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SCMI Base protocol agent_name/vendor_id/sub_vendor_id are defined by the specification as NULL-terminated ASCII strings up to 16-bytes in length. The underlying buffers and message descriptors are currently bigger than needed; resize them to fit only the strictly needed 16 bytes. While at that, convert Base protocol strings handling routines to use the preferred strscpy. Fixes: b260fccaebdc2 ("firmware: arm_scmi: Add SCMI v3.1 protocol extended names support") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/base.c | 8 ++++---- drivers/firmware/arm_scmi/protocols.h | 2 -- include/linux/scmi_protocol.h | 9 +++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c index d0ac96da1ddf..a52f084a6a87 100644 --- a/drivers/firmware/arm_scmi/base.c +++ b/drivers/firmware/arm_scmi/base.c @@ -36,7 +36,7 @@ struct scmi_msg_resp_base_attributes { struct scmi_msg_resp_base_discover_agent { __le32 agent_id; - u8 name[SCMI_MAX_STR_SIZE]; + u8 name[SCMI_SHORT_NAME_MAX_SIZE]; }; @@ -119,7 +119,7 @@ scmi_base_vendor_id_get(const struct scmi_protocol_handle *ph, bool sub_vendor) ret = ph->xops->do_xfer(ph, t); if (!ret) - memcpy(vendor_id, t->rx.buf, size); + strscpy(vendor_id, t->rx.buf, size); ph->xops->xfer_put(ph, t); @@ -276,7 +276,7 @@ static int scmi_base_discover_agent_get(const struct scmi_protocol_handle *ph, ret = ph->xops->do_xfer(ph, t); if (!ret) { agent_info = t->rx.buf; - strlcpy(name, agent_info->name, SCMI_MAX_STR_SIZE); + strscpy(name, agent_info->name, SCMI_SHORT_NAME_MAX_SIZE); } ph->xops->xfer_put(ph, t); @@ -375,7 +375,7 @@ static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph) int id, ret; u8 *prot_imp; u32 version; - char name[SCMI_MAX_STR_SIZE]; + char name[SCMI_SHORT_NAME_MAX_SIZE]; struct device *dev = ph->dev; struct scmi_revision_info *rev = scmi_revision_area_get(ph); diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index 73304af5ec4a..c679f3fb8718 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -24,8 +24,6 @@ #include -#define SCMI_SHORT_NAME_MAX_SIZE 16 - #define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0) #define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16) #define PROTOCOL_REV_MAJOR(x) ((u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))) diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 1c58646ba381..704111f63993 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -13,8 +13,9 @@ #include #include -#define SCMI_MAX_STR_SIZE 64 -#define SCMI_MAX_NUM_RATES 16 +#define SCMI_MAX_STR_SIZE 64 +#define SCMI_SHORT_NAME_MAX_SIZE 16 +#define SCMI_MAX_NUM_RATES 16 /** * struct scmi_revision_info - version information structure @@ -36,8 +37,8 @@ struct scmi_revision_info { u8 num_protocols; u8 num_agents; u32 impl_ver; - char vendor_id[SCMI_MAX_STR_SIZE]; - char sub_vendor_id[SCMI_MAX_STR_SIZE]; + char vendor_id[SCMI_SHORT_NAME_MAX_SIZE]; + char sub_vendor_id[SCMI_SHORT_NAME_MAX_SIZE]; }; struct scmi_clock_info { -- 2.32.0