Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1711611ybg; Thu, 30 Jul 2020 00:06:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztG5SDmvGHF1ZTZjz6JEuCroG7JPI53+L2Z/LJycKexeDt4ABGHZYrECw1NkleWDuKTplV X-Received: by 2002:aa7:da8c:: with SMTP id q12mr1362108eds.126.1596092764603; Thu, 30 Jul 2020 00:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596092764; cv=none; d=google.com; s=arc-20160816; b=Z7tE/ZFYfTIdLzAytxI5iM1/LCrXiRrbJPJADm86A4Qa2VaVD8P+d6ONH9AhmmBVfW S4ygA6aA1FuI5PF0qE7AUhakJKQO5ye1Gv81eP7VNlWnkczEsr1M+YpE+7i/M8yjaxXe QwO4zl1NubBzQibK6j6A5Z8/ZK5wDU/kBLaN8fFAgucQWVwR6Bcan061X1soH5KoS7Dd Z/SHNH7TopciDznw+EbREyf39eT5zDvnGfXNdJpwUhGTKEFOH+BLzeSh6HAf2mycdDb/ 1b5KUada0i6exRU+ZcWeBIk19qH5pG9QI8zaLg6sZT9lX07U1HbFu2MhSmMYga3gjJWP 1MqA== 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=29eic4Wl1URKDGt6kd11gBwA+Rlog7VxCEVTQXuS8NY=; b=ijg1Twg8pOrFYvO1wJRh7jkojlZ9S4pD3CdkmU8WCpsPEin36Eu0dmR2XZSFvZw332 Sbr8Atfn4RAJEsuDUF2KNqsSoq7Kd8rcP40z4P3JRKfH51GyiBox9pR2sa30RwNn/B67 4lq+CPGwPd3+bit187l+vht1dcINb9u+VXANtRTlMOtcBkJ2uxk8OpQY6TFZShCP37+c uLBl3Vx8eqzuo9GAbyZIkw9+9J7oWLUdbtB5hDYoKD5sEWwiSRnQo+QGiM6jk4UN78Qx Y8/392f1lYGxFFb703We3prRnV8HLgMGKKZAuqUTZLL5GFZQRguuM+jLEM3fdZOhDvyh xIrQ== 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 89si2772238edr.415.2020.07.30.00.05.41; Thu, 30 Jul 2020 00:06:04 -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 S1728775AbgG3HDG (ORCPT + 99 others); Thu, 30 Jul 2020 03:03:06 -0400 Received: from mga11.intel.com ([192.55.52.93]:28434 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbgG3HDG (ORCPT ); Thu, 30 Jul 2020 03:03:06 -0400 IronPort-SDR: n3mLsN/tnYJ3UmFnfFYjoJs8q3+Z2Rr3Bym5StZHbj3Z0Etim8SEgJxaH+pzO7i2ExYeurK+nN pYiEocs0rYyQ== X-IronPort-AV: E=McAfee;i="6000,8403,9697"; a="149384481" X-IronPort-AV: E=Sophos;i="5.75,413,1589266800"; d="scan'208";a="149384481" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2020 00:03:05 -0700 IronPort-SDR: +45noUNCgkqDce/jRQFGXSClpd1TRTAvJEj73vKXwJ14/Kf09x1BT+l8pu7oqblrtErneLC6Gk 90YN/XAyij3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,413,1589266800"; d="scan'208";a="320984312" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by orsmga008.jf.intel.com with ESMTP; 30 Jul 2020 00:03:02 -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 V2] mei: hdcp: fix mei_hdcp_verify_mprime() input paramter Date: Thu, 30 Jul 2020 10:02:58 +0300 Message-Id: <20200730070258.3361503-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) 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 --- V2: Check for allocation failure. drivers/misc/mei/hdcp/mei_hdcp.c | 40 +++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/misc/mei/hdcp/mei_hdcp.c b/drivers/misc/mei/hdcp/mei_hdcp.c index d1d3e025ca0e..f1205e0060db 100644 --- a/drivers/misc/mei/hdcp/mei_hdcp.c +++ b/drivers/misc/mei/hdcp/mei_hdcp.c @@ -546,38 +546,46 @@ 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); + if (!verify_mprime_in) + return -ENOMEM; + + 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