Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2282812ybg; Thu, 30 Jul 2020 15:46:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH9iBdqDANt5HYmKgHJsyK+PzMESk4WXWLT/7iQTqLmCttfT1w6U+7T08l3mkyAXw6KOba X-Received: by 2002:a17:906:4e14:: with SMTP id z20mr1309069eju.541.1596149209027; Thu, 30 Jul 2020 15:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596149209; cv=none; d=google.com; s=arc-20160816; b=KwOzUw6l+m8ZVmTcFZQ/oiuvXuC/k4IMyoxquOUIejcGcyHv1OPWo/SCDer6/I+qYL +4iz54YsWlQo0ZlKHXa1PZzvDxlsG2G76KIP0R15Tu0TZDNAx7x1CIEm6tU+hvTSk/vD iw9vo/21OUPNtdV6gnGVouHnArXIWmSOlkztHZQtmdfK0d9KH8GonJ2/2kOTdfXFyZkp DaMWelqw12qJRR1sRJXTCRWBF5h+dItTlpnfadHMK2uw15hOzdtUOe+ebNc+LQ6Otiuz ZqCpebCAC5NFM8DCHQg3DWfIHMWGx3TzSBEKdMIb2OOzzN0heexU/pVeR2UL4kzZJSYm 1L8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=dJjfGit9H/clJmlXbMn2ofEPsS20kApSJ4daKFNVog0=; b=qR1m092oEWulLyaPsQAiyymTxv9QEx7Lt1H0WYyKOyx6bjNjBHDb02OvW8OoXdUu/v Zy1vwkPc/LYOFNRf8ntcIr1MMRSPoagATPWEUT9+YLK8We2QK9/ASy/Q4ASLYtKDEHBo A34/3agal4n8nltDYicjs80yqvS05kHS94S23Hju80JUGaqudf9k8YQZsbWptZ5W5idC hZKhikXU/jxboXD19lLbVy13kNjg0e+u0GjpEyF3bwDlilga3Cgvqyaepgg2IyFd7GK0 OGpyLDPGn+hFNkUw+DTZMzGRPRwcxbB6oMixexXVeKQ9hedoIPbgl1ufrlVewUlb92yU Y3Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lZetdtpC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u7si4031513ejn.161.2020.07.30.15.46.27; Thu, 30 Jul 2020 15:46:49 -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; dkim=pass header.i=@kernel.org header.s=default header.b=lZetdtpC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730509AbgG3WqL (ORCPT + 99 others); Thu, 30 Jul 2020 18:46:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:44722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730036AbgG3WqK (ORCPT ); Thu, 30 Jul 2020 18:46:10 -0400 Received: from embeddedor (187-162-31-110.static.axtel.net [187.162.31.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19A0520838; Thu, 30 Jul 2020 22:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596149169; bh=MdiKqZtkKcfBkgB2ny4nl/l0vVvGSKyEuahiF0CPnl8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lZetdtpCN4pomhfZdJIstWjRbatO5WXmy94YhE3NzZPm6NjKW6CxwHrhz4mV+K4AY JVUIsEmzhXqmaNr+dRS0SuzeiD+mb0WFPKVDSkQuBvm7IANbq391PKnanuYe40WuA+ voa3zL/KU7q/0C3rryCg6i5drnJT214pk1czmVtY= Date: Thu, 30 Jul 2020 17:52:10 -0500 From: "Gustavo A. R. Silva" To: Tomas Winkler Cc: Greg Kroah-Hartman , Alexander Usyskin , linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , Ramalingam C , stable@vger.kernel.org Subject: Re: [char-misc-next V4] mei: hdcp: fix mei_hdcp_verify_mprime() input parameter Message-ID: <20200730225210.GA1726@embeddedor> References: <20200730220139.3642424-1-tomas.winkler@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200730220139.3642424-1-tomas.winkler@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 01:01:39AM +0300, Tomas Winkler wrote: > 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") ^^^^ I think the _commit_ word above is unnecessary. > Cc: "Gustavo A. R. Silva" > Cc: Ramalingam C > Cc: v5.1+ Greg, Notice that this patch is fine as is for -next, only. This becomes suitable for -stable as long as commit c56967d674e3 (mei: hdcp: Replace one-element array with flexible-array member) is applied to -stable, too. Otherwise, a separate patch that leaves the one-element array in struct wired_cmd_repeater_auth_stream_req_in in place needs to be crafted. With this taken into account, here is my Reviewed-by: Gustavo A. R. Silva Thanks for the changes, Tomas. -- Gustavo > 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 >