Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2909915pxa; Tue, 18 Aug 2020 00:57:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtd4VA95+M09S8qWBRs+iPY5d7QuvutkNrlIixHKiqHeaWyawgMB7NpsZXz64dHxfvLWhF X-Received: by 2002:a17:907:20db:: with SMTP id qq27mr19547294ejb.550.1597737436757; Tue, 18 Aug 2020 00:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597737436; cv=none; d=google.com; s=arc-20160816; b=srb6JvmMeqt2qM7Msd7nHXB+2N7qkzb3aSpaLeg2qnAiS9CFmjaS6HoX4vvCngvWU9 Zupm8RQbhpPuR6AL2tL8CHKmjSXdld/lC/3hi/rUXKOSkXXIGFfKX21AXcoDW/GIYhe+ S9YWSSL0sVWzALhNUPY0aJsQaUMj6XjPlnFafGoSXmDjUuXNZwAyQLMk7HJWSO8RB0GJ rRRBoK7AArED5uArvwzmjCIBG84WIBJjTilKJq7igLcYO85HulPgfTqnWfIt/egCDb2g riAIF5BG0IZ/Lcr7q/wz7Lvtdp22O6+rba7D27IJa1WkoQhG64J6cgAoeZ53Fw16Ewol XwvA== 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=AVUxT1pgCNwkDmnrmwqecmL1FApr4x0zhHdzs6AdnCc=; b=NCUdg+e5eGG52tPJ4l+KNCZlV6CRC5lx5VWDsrdGebY2iIc7gjTmzdF6ml9i5iJT6I zvjfr0ZIU0iYx7RjMAyrV7VO/WCvojMED404aK8B5gHsfMzSZhuJAIGhzNr1iFfI/I8K z+sZLuK9fLZgOCOombgM1/LcaGMGhCfSkruQRF/iPRVoGOOB2uV2c3SDgq8NA7V30gE/ aI6VMxfwnUIHLlBDyorm8DDUb+Gym588hOO/IamjGv1NVkP8qIDeggRcy6q/4sPaZccP tO0E1oTTWdKRFTXUohRALxW/ZbxBJl8ZEMQ03vxRgbI/JrXFy3uoghMfLS/cHScpZRTf QI0Q== 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 33si14206117edq.578.2020.08.18.00.56.52; Tue, 18 Aug 2020 00:57:16 -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 S1726336AbgHRH4P (ORCPT + 99 others); Tue, 18 Aug 2020 03:56:15 -0400 Received: from mga07.intel.com ([134.134.136.100]:36584 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgHRH4O (ORCPT ); Tue, 18 Aug 2020 03:56:14 -0400 IronPort-SDR: /SGiGL+/x2EYD0rFgVRlrPygr4i9Td1NXQwxK4sNfIc7xyGb6GTuYP+YBL5lKfJ4NwMibUiRb8 KylGB1q+LcUA== X-IronPort-AV: E=McAfee;i="6000,8403,9716"; a="219174401" X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="219174401" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2020 00:56:13 -0700 IronPort-SDR: 4tYE53XSB6YAiPbWPaMciN12HkT7ZYYCf7k8Ae7IpAZCTWS09uaC5r847Uwmki8KWpY0nFBP5l FeNh0UgDFGeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="326657452" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by orsmga008.jf.intel.com with ESMTP; 18 Aug 2020 00:56:11 -0700 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Tomas Winkler , stable@vger.kernel.org, "Gustavo A . R . Silva" Subject: [char-misc V5] mei: hdcp: fix mei_hdcp_verify_mprime() input parameter Date: Tue, 18 Aug 2020 10:54:06 +0300 Message-Id: <20200818075406.2532605-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. This also fixes bug in case number of streams is > 0 in the original submission. This bug was not triggered as the number of streams is always one. Fixes: c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) Fixes: 0a1af1b5c18d (misc/mei/hdcp: Verify M_prime) Cc: # v5.1+: c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) Signed-off-by: Tomas Winkler Reviewed-by: Gustavo A. R. Silva --- V5: 1. Add reference to depending patch for stable V4: 1. Fix typo in the subject. (Gustavo) 2. Fix dereferencing pointer in send. (Gustavo) V3: 1. Fix commit message with more info and another patch it fixes (Gustavo) 2. Target stable. (Gustavo) V2: 1. 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..9ae9669e46ea 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