Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1302012ybg; Wed, 29 Jul 2020 10:32:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwximf1Ukz94bZK6QWUyU8t5cy0rc2v6Yynuq1KHKRHqYQgI57c49in1wGlvUaL89EPPXxM X-Received: by 2002:aa7:d7cf:: with SMTP id e15mr32733563eds.236.1596043960037; Wed, 29 Jul 2020 10:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596043960; cv=none; d=google.com; s=arc-20160816; b=iwjgJw5OPEO4pYrJonKgoztt8vR/zH4sud8UBjjAzf5Ly/nwuWTkUH0YWLL1aajxO7 9YWInAH+hc9O/fa7EX36Jvqp9+cd1dYRNvfKBpbIS92iukeoMLl3zQJIiH5E1JV3IQnk FE6lWmaktezZubzljTCu7QFk1MoeA5sJpuVS62WjuYqvPg6ptuIwx903qMAFNdt80KPO ZzkuDdxy0gnQ9lV3alxRPHAuf19IAmiTO0dLcfXlxBoPlGWANW6VKQldrQWIhFuPt32H /7Z6OMOwGsbY877dFnEUpmKAc6/YaBrtBYbmhbliBlAWLqM6vZBOMVLL8yg9lwci+7UI aZPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=/t95+lXM2KRb53gXYp4E0vQ4mDqnp8kDeW/jcF4iAqc=; b=BhQgsv+CpxOGP3U80+jVHMQJ0mteLC8MWVYnkymzlx0yExY7sRkCw2eqsll0m2gLCQ B7MA/54cMjqtMjKmZYoVlKEiugeszt/jGUEO0noGpGrZodRi0k56uLh++agFPmcWQKEa 4/YYq+0vK+nQF1PhoZ3qifpflbfXfnBzihft5ZE4hkiH/ahL91UcRNassKl4EDfZv3+K zBCuQx14OsJjKD1ABmy5yGv8U9UlKubJI0hnDp6T2Luhcwq7/ACI1aPBbStUSANP8PEj oI05MJ3M2r8LwyxJNPNopo2nObw/dL6ZySTbW76U4kto1EvNSQKesjbN7ygo9/ebjXtq bOBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si1549598eje.437.2020.07.29.10.32.16; Wed, 29 Jul 2020 10:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726581AbgG2RcL (ORCPT + 99 others); Wed, 29 Jul 2020 13:32:11 -0400 Received: from mga03.intel.com ([134.134.136.65]:2012 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbgG2RcK (ORCPT ); Wed, 29 Jul 2020 13:32:10 -0400 IronPort-SDR: ZeOyQJoPO9fx5Vi8or/0qc9w+Q/jXVbq8Wt/85VgznmKKs7z/YwLhQaCenwwou6OMgbB9B4OPe 3ACfPaGqNB6w== X-IronPort-AV: E=McAfee;i="6000,8403,9697"; a="151445502" X-IronPort-AV: E=Sophos;i="5.75,411,1589266800"; d="scan'208";a="151445502" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2020 10:32:10 -0700 IronPort-SDR: hx1rMLW2533idCRWSHOH7b6sOv2j1/aK6b3RBNbjzcsH8nh1t8+vZK84f80g2gU2QHiVcOXZ6U 0GEcN8mINOJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,411,1589266800"; d="scan'208";a="490363474" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by fmsmga006.fm.intel.com with ESMTP; 29 Jul 2020 10:32:08 -0700 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Tomas Winkler , Ramalingam C , "Gustavo A . R . Silva" Subject: [char-misc-next] mei: hdcp: fix mei_hdcp_verify_mprime() input paramter Date: Wed, 29 Jul 2020 20:32:04 +0300 Message-Id: <20200729173204.3251582-1-tomas.winkler@intel.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org wired_cmd_repeater_auth_stream_req_in has a variable length array at the end. we use struct_size() overflow macro to determine the size for the allocation and sending size. Fixes: c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) Cc: Ramalingam C Cc: Gustavo A. R. Silva Signed-off-by: Tomas Winkler --- drivers/misc/mei/hdcp/mei_hdcp.c | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/misc/mei/hdcp/mei_hdcp.c b/drivers/misc/mei/hdcp/mei_hdcp.c index d1d3e025ca0e..0e8f12e38494 100644 --- a/drivers/misc/mei/hdcp/mei_hdcp.c +++ b/drivers/misc/mei/hdcp/mei_hdcp.c @@ -546,38 +546,44 @@ static int mei_hdcp_verify_mprime(struct device *dev, struct hdcp_port_data *data, struct hdcp2_rep_stream_ready *stream_ready) { - struct wired_cmd_repeater_auth_stream_req_in - verify_mprime_in = { { 0 } }; + struct wired_cmd_repeater_auth_stream_req_in *verify_mprime_in; struct wired_cmd_repeater_auth_stream_req_out verify_mprime_out = { { 0 } }; struct mei_cl_device *cldev; ssize_t byte; + size_t cmd_size; if (!dev || !stream_ready || !data) return -EINVAL; cldev = to_mei_cl_device(dev); - verify_mprime_in.header.api_version = HDCP_API_VERSION; - verify_mprime_in.header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ; - verify_mprime_in.header.status = ME_HDCP_STATUS_SUCCESS; - verify_mprime_in.header.buffer_len = + cmd_size = struct_size(verify_mprime_in, streams, data->k); + if (cmd_size == SIZE_MAX) + return -EINVAL; + + verify_mprime_in = kzalloc(cmd_size, GFP_KERNEL); + + verify_mprime_in->header.api_version = HDCP_API_VERSION; + verify_mprime_in->header.command_id = WIRED_REPEATER_AUTH_STREAM_REQ; + verify_mprime_in->header.status = ME_HDCP_STATUS_SUCCESS; + verify_mprime_in->header.buffer_len = WIRED_CMD_BUF_LEN_REPEATER_AUTH_STREAM_REQ_MIN_IN; - verify_mprime_in.port.integrated_port_type = data->port_type; - verify_mprime_in.port.physical_port = (u8)data->fw_ddi; - verify_mprime_in.port.attached_transcoder = (u8)data->fw_tc; + verify_mprime_in->port.integrated_port_type = data->port_type; + verify_mprime_in->port.physical_port = (u8)data->fw_ddi; + verify_mprime_in->port.attached_transcoder = (u8)data->fw_tc; + + memcpy(verify_mprime_in->m_prime, stream_ready->m_prime, HDCP_2_2_MPRIME_LEN); + drm_hdcp_cpu_to_be24(verify_mprime_in->seq_num_m, data->seq_num_m); - memcpy(verify_mprime_in.m_prime, stream_ready->m_prime, - HDCP_2_2_MPRIME_LEN); - drm_hdcp_cpu_to_be24(verify_mprime_in.seq_num_m, data->seq_num_m); - memcpy(verify_mprime_in.streams, data->streams, + memcpy(verify_mprime_in->streams, data->streams, array_size(data->k, sizeof(*data->streams))); - verify_mprime_in.k = cpu_to_be16(data->k); + verify_mprime_in->k = cpu_to_be16(data->k); - byte = mei_cldev_send(cldev, (u8 *)&verify_mprime_in, - sizeof(verify_mprime_in)); + byte = mei_cldev_send(cldev, (u8 *)&verify_mprime_in, cmd_size); + kfree(verify_mprime_in); if (byte < 0) { dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte); return byte; -- 2.25.4