Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2261417ybg; Thu, 30 Jul 2020 15:05:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGwyWpdL+NAeSQi4/Lz+4rFkR366QW2KfQ3Di8pfhQOP5L/ojn/hNKfoyfwmMz0mrK9ikE X-Received: by 2002:a50:a404:: with SMTP id u4mr1074724edb.222.1596146720658; Thu, 30 Jul 2020 15:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596146720; cv=none; d=google.com; s=arc-20160816; b=eS9mawLy3PqkRYfVkiju7mnFOnCaLTMjdn1zppGLn+lUlqdPCrd4cdFS4dTq4Ik6wO oD/KDMjmm8qIYjhp9Z5NaWWPatajMcJ8hkp5DFrZOeDLQMuvhXYwiOjAIdLnbAoRtbEL M0Kj+reNfc78YX6Cxip61imQU1JIQQocK3CYQppq5d1jyNCcIyy4tsE/H+t9Rjlm46Va JvwGCPowtKKmPSeAilpyHJQaCDnRrQkScZT2J2lA84PiYgop/vAilLNgICtPy19NOKiP Cz+CMUQGNxpKZe3Ir8BTmiX8d1pNbWblyX20xyc0iquwf5A0/6vDboCA8etPgrtJEdq4 2p9A== 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=Ft5ZxWXRkZTxJP/j/YQt76ktpWe+jE5lI8jwwZ7hiNI=; b=i0Kb+ffAuGJ4vOiqzU5Dur9EIu+5byTnk8b0OtlEC7oQn7YtE36xcIeqyJic26cloj lo7bnmNfe9d7GVDf/KEdsr7LuzReV7nTBtNl/fPmh69ykEzRC5GEVDsIqIyEiZoo801R LZpkcQfrUj+NwuTMzxEgObJSGU3TB131WP+ppr5cYDHnxo9rj+UKn/lMUMH25cuGZnPS +h6iQ6tt5l0LucF7iiLwBIGSd/UfAFNZtiKBxlXPlmPb/Mih24i1xan2otKdK/Fh8ZIS YzeipBFrV9C/faB6ImRK3RVZjfD63itCF4vNvcmRhPLwnQlrdqof0azKskwZIFimrsDr zrcQ== 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 i23si3984537ejj.300.2020.07.30.15.04.58; Thu, 30 Jul 2020 15:05:20 -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 S1728396AbgG3WBp (ORCPT + 99 others); Thu, 30 Jul 2020 18:01:45 -0400 Received: from mga17.intel.com ([192.55.52.151]:20825 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726544AbgG3WBp (ORCPT ); Thu, 30 Jul 2020 18:01:45 -0400 IronPort-SDR: Hd97d/qInC5mZ4tR8ELyazbVyDYT4FrYtUK15QmQKweRuw2ziMrLstkDHrzsHrZDG2DbyZ6KHZ Buzb68Iu7uuQ== X-IronPort-AV: E=McAfee;i="6000,8403,9698"; a="131770557" X-IronPort-AV: E=Sophos;i="5.75,415,1589266800"; d="scan'208";a="131770557" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2020 15:01:44 -0700 IronPort-SDR: KG5bBtfQ5NYIWnkLXakYe6lEqlSfkszqGP5+7vR7xaJytouSRsMjPtn/ldEsmk8DZk308UE7/U eZBSZV2tMA4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,415,1589266800"; d="scan'208";a="435205691" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by orsmga004.jf.intel.com with ESMTP; 30 Jul 2020 15:01:41 -0700 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Tomas Winkler , "Gustavo A. R. Silva" , Ramalingam C , stable@vger.kernel.org Subject: [char-misc-next V4] mei: hdcp: fix mei_hdcp_verify_mprime() input parameter Date: Fri, 31 Jul 2020 01:01:39 +0300 Message-Id: <20200730220139.3642424-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: commit 0a1af1b5c18d ("misc/mei/hdcp: Verify M_prime") Cc: "Gustavo A. R. Silva" Cc: Ramalingam C Cc: v5.1+ Signed-off-by: Tomas Winkler --- 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: 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